source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
lib/sexy_scopes/active_record/dynamic_methods.rb
Ruby
mit
94
master
2,561
module SexyScopes module ActiveRecord module DynamicMethods private def respond_to_missing?(method_name, *) # super currently resolve to Object#respond_to_missing? which return false, # but future version of ActiveRecord::Base might implement respond_to_missing? if @sex...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
lib/arel/visitors_extensions.rb
Ruby
mit
94
master
1,474
require 'arel/visitors' module Arel module Visitors # TODO: Extract these methods into modules class ToSql private def visit_Regexp(regexp, collector) source = SexyScopes.quote(regexp.source) visit source, collector end end class MySQL private def visi...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/spec_helper.rb
Ruby
mit
94
master
541
if ENV['COVERAGE'] || ENV['TRAVIS'] require 'simplecov' if ENV['TRAVIS'] require 'coveralls' SimpleCov.formatter = Coveralls::SimpleCov::Formatter end SimpleCov.start do # exclude Gemfiles and gems bundled by Travis add_filter 'gemfiles/' add_filter 'spec/' end end require 'rspec' requi...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/support/config.rb
Ruby
mit
94
master
782
module SexyScopesSpec extend self CONFIG_FILENAME = 'config.yml' EXAMPLE_CONFIG_FILENAME = 'config.example.yml' TRAVIS_CONFIG_FILENAME = 'config.travis.yml' def config @config ||= read_config end protected def config_file File.expand_path("../#{config_filename}", File.dirname(__FILE__)) ...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/support/connection.rb
Ruby
mit
94
master
338
module SexyScopesSpec extend self DEFAULT_DATABASE_SYSTEM = 'sqlite3' def connection_config config[database_system] end def database_system ENV['DB'] || DEFAULT_DATABASE_SYSTEM end def connect puts "Connecting using #{database_system}" ActiveRecord::Base.establish_connection connection...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/support/shared_examples.rb
Ruby
mit
94
master
484
RSpec.shared_examples "a predicate method" do it "should return an Arel node" do expect(subject.class.name).to match /^(SexyScopes::)?Arel::Nodes::/ end it { is_expected.to be_extended_by SexyScopes::Arel::PredicateMethods } end RSpec.shared_examples "an expression method" do it "should return an Arel nod...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/arel/predicate_methods_spec.rb
Ruby
mit
94
master
1,213
require 'spec_helper' describe SexyScopes::Arel::PredicateMethods do before do @attribute = User.attribute(:score) @predicate = @attribute < 1000 @predicate2 = @attribute >= 200 end describe ".not" do subject { @predicate.not } it_behaves_like "a predicate method" it { is_expected.to c...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/arel/predications_spec.rb
Ruby
mit
94
master
2,875
require 'spec_helper' describe SexyScopes::Arel::Predications do before do @attribute = User.attribute(:score) end METHODS = { # Arel method => [ Ruby operator, SQL operator ] :eq => [ '==', '= %s' ], :in => [ nil, 'IN (%s)' ], :matches => [ '=~...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/arel/regexp_matches_spec.rb
Ruby
mit
94
master
972
require 'spec_helper' describe SexyScopes::Arel::Nodes::RegexpMatches do before do @attribute = User.attribute(:username) end context "case sensitive" do subject { @attribute =~ /bob|alice/ } db :postgresql do it { is_expected.to convert_to_sql %{"users"."username" ~ 'bob|alice'} } end ...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/arel/math_spec.rb
Ruby
mit
94
master
1,476
require 'spec_helper' describe SexyScopes::Arel::Math do before do @attribute = User.attribute(:score) end describe "the method `*`" do subject { @attribute * 42 } it_behaves_like "an expression method" it { is_expected.to convert_to_sql %{"users"."score" * 42} } end describe "the method ...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/active_record/query_methods_spec.rb
Ruby
mit
94
master
5,731
require 'spec_helper' describe SexyScopes::ActiveRecord::QueryMethods do describe ".where(&block)" do context "sent to an ActiveRecord::Base class" do subject { User } it "should execute the block in the context of the class" do expect_block_to_be_executed_in_context_or_with_argument User.al...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/active_record/class_methods_spec.rb
Ruby
mit
94
master
988
require 'spec_helper' describe SexyScopes::ActiveRecord::ClassMethods do it "should extend ActiveRecord::Base" do expect(ActiveRecord::Base).to be_extended_by described_class end describe ".attribute(name)" do subject { User.attribute(:username) } it "should return an Arel attribute for the given n...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/active_record/dynamic_methods_spec.rb
Ruby
mit
94
master
2,704
require 'spec_helper' describe SexyScopes::ActiveRecord::DynamicMethods do before do ActiveRecord::Migration.create_table :temp_users do |t| t.string :username t.string :name t.string :foo t.integer :score end class ::TempUser < ActiveRecord::Base # Deliberately defining a ...
github
samleb/sexy_scopes
https://github.com/samleb/sexy_scopes
spec/matchers/convert_to_sql.rb
Ruby
mit
94
master
766
RSpec::Matchers.define :convert_to_sql do |expected| case SexyScopesSpec.database_system when 'mysql' expected = expected.gsub('"', '`') when 'postgresql' expected = expected.gsub('LIKE', 'ILIKE') end match do |actual| convert_to_sql(actual) == expected end description do "convert to the...
github
dougfales/gpx
https://github.com/dougfales/gpx
Rakefile
Ruby
mit
94
master
860
# frozen_string_literal: true require 'bundler/gem_tasks' require 'rake/testtask' require 'rdoc/task' require 'rubocop/rake_task' RuboCop::RakeTask.new desc 'Default Task' task default: %i[test rubocop] namespace :ci do task :build do puts 'Creating tests/output directory...' FileUtils.mkdir_p 'tests/outp...
github
dougfales/gpx
https://github.com/dougfales/gpx
gpx.gemspec
Ruby
mit
94
master
1,005
# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'gpx/version' Gem::Specification.new do |s| s.name = 'gpx' s.version = GPX::VERSION s.authors = ['Guillaume Dott', 'Doug Fales', 'Andrew Hao'] s.email = ['guillaume+github@dott....
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx.rb
Ruby
mit
94
master
661
# frozen_string_literal: true require 'time' require 'nokogiri' require File.expand_path('gpx/version', __dir__) require File.expand_path('gpx/gpx', __dir__) require File.expand_path('gpx/gpx_file', __dir__) require File.expand_path('gpx/bounds', __dir__) require File.expand_path('gpx/track', __dir__) require File.ex...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/magellan_track_log.rb
Ruby
mit
94
master
3,533
# frozen_string_literal: true module GPX # This class will parse the lat/lon and time data from a Magellan track log, # which is a NMEA formatted CSV list of points. class MagellanTrackLog # PMGNTRK # This message is to be used to transmit Track information (basically a list of previous position fixes) ...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/route.rb
Ruby
mit
94
master
1,086
# frozen_string_literal: true module GPX # A Route in GPX is very similar to a Track, but it is created by a user # from a series of Waypoints, whereas a Track is created by the GPS device # automatically logging your progress at regular intervals. class Route < Base attr_accessor :points, :name, :gpx_file...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/bounds.rb
Ruby
mit
94
master
1,845
# frozen_string_literal: true module GPX class Bounds < Base attr_accessor :min_lat, :max_lat, :max_lon, :min_lon # Creates a new bounds object with the passed-in min and max longitudes # and latitudes. def initialize(opts = { min_lat: 90.0, max_lat: -90.0, min_lon: 180.0, max_lon: -180.0 }) s...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/gpx_file.rb
Ruby
mit
94
master
12,107
# frozen_string_literal: true module GPX class GPXFile < Base attr_accessor :tracks, :routes, :waypoints, :bounds, :lowest_point, :highest_point, :duration, :ns, :time, :name, :version, :creator, :description, :moving_duration DEFAULT_CREATOR = "GPX RubyGem #{GPX::VERSION} -- http://dougfa...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/track_point.rb
Ruby
mit
94
master
1,007
# frozen_string_literal: true module GPX # Basically the same as a point, the TrackPoint class is supposed to # represent the points that are children of Segment elements. So, the only # real difference is that TrackPoints hold a reference to their parent # Segments. class TrackPoint < Point RADIUS = 63...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/point.rb
Ruby
mit
94
master
2,482
# frozen_string_literal: true module GPX # The base class for all points. Trackpoint and Waypoint both descend from this base class. class Point < Base D_TO_R = Math::PI / 180.0 attr_accessor :time, :elevation, :gpx_file, :speed, :extensions attr_reader :lat, :lon # When you need to manipulate in...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/waypoint.rb
Ruby
mit
94
master
1,617
# frozen_string_literal: true module GPX # This class supports the concept of a waypoint. Beware that this class has # not seen much use yet, since WalkingBoss does not use waypoints right now. class Waypoint < Point SUB_ELEMENTS = %w[ele magvar geoidheight name cmt desc src link sym type fix sat hdop vdop ...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/segment.rb
Ruby
mit
94
master
8,372
# frozen_string_literal: true module GPX # A segment is the basic container in a GPX file. A Segment contains points # (in this lib, they're called TrackPoints). A Track contains Segments. An # instance of Segment knows its highest point, lowest point, earliest and # latest points, distance, and bounds. c...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/track.rb
Ruby
mit
94
master
4,503
# frozen_string_literal: true module GPX # In GPX, a single Track can hold multiple Segments, each of which hold # multiple points (in this library, those points are instances of # TrackPoint). Each instance of this class has its own meta-data, including # low point, high point, and distance. Of course, each...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/geo_json.rb
Ruby
mit
94
master
6,676
# frozen_string_literal: true require 'json' module GPX # Class to parse GeoJSON LineStrings, MultiLineStrings, Points, # and MultiPoint geometric objects to GPX format. For the full # specification of GeoJSON, see: # http://geojson.org/geojson-spec.html # Note that GeoJSON coordinates are specified in lo...
github
dougfales/gpx
https://github.com/dougfales/gpx
lib/gpx/gpx.rb
Ruby
mit
94
master
929
# frozen_string_literal: true module GPX # A common base class which provides a useful initializer method to many # class in the GPX library. class Base # This initializer can take an XML::Node and scrape out any text # elements with the names given in the "text_elements" array. Each # element found...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/segment_test.rb
Ruby
mit
94
master
5,460
# frozen_string_literal: true require 'minitest/autorun' require 'yaml' require 'gpx' class SegmentTest < Minitest::Test ONE_SEGMENT = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx') ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_no_time.gpx') ONE_SEGMENT_MIXED_TIM...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/route_test.rb
Ruby
mit
94
master
3,745
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class RouteTest < Minitest::Test def test_read_routes gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/routes.gpx')) assert_equal(2, gpx.routes.size) first_route = gpx.routes.first assert_equal(3, fir...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/track_test.rb
Ruby
mit
94
master
2,879
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class TrackTest < Minitest::Test ONE_TRACK = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx') def setup @gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK) @track = @gpx_file.tracks.first end def test_track_read ass...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/gpx10_test.rb
Ruby
mit
94
master
299
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class GPX10Test < Minitest::Test GPX_FILE = File.join(File.dirname(__FILE__), 'gpx_files/gpx10.gpx') def test_read # make sure we can read a GPX 1.0 file @gpx_file = GPX::GPXFile.new(gpx_file: GPX_FILE) end end
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/track_file_test.rb
Ruby
mit
94
master
2,305
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class TrackFileTest < Minitest::Test TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/tracks.gpx') OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/arches.gpx') def setup @track_file = GPX::GPXFile.new(gpx_file: ...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/magellan_test.rb
Ruby
mit
94
master
625
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class MagellanTest < Minitest::Test MAGELLAN_TRACK_LOG = File.join(File.dirname(__FILE__), 'gpx_files/magellan_track.log') GPX_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx') def test_convert GPX::MagellanTrackLog....
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/waypoint_test.rb
Ruby
mit
94
master
1,502
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class WaypointTest < Minitest::Test def test_read_waypoints gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/waypoints.gpx')) assert_equal(18, gpx.waypoints.size) # First Waypoint # <wpt lat="40...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/track_point_test.rb
Ruby
mit
94
master
1,032
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' class TrackPointTest < Minitest::Test def setup @point1 = GPX::TrackPoint.new( lat: 37.7985474, lon: -122.2554386 ) @point2 = GPX::TrackPoint.new( lat: 37.7985583, lon: -122.2554564 ) @point3 = GPX::Tr...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/output_test.rb
Ruby
mit
94
master
8,322
# frozen_string_literal: true require 'minitest/autorun' require 'fileutils' require 'gpx' class OutputTest < Minitest::Test include GPX def setup FileUtils.mkdir_p(File.join(File.dirname(__FILE__), 'output')) end def test_new_gpx_file_from_scratch gpx_file = GPXFile.new track = Track.new(name:...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/gpx_file_test.rb
Ruby
mit
94
master
3,195
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' require 'stringio' class GPXFileTest < Minitest::Test ONE_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx') WITH_OR_WITHOUT_ELEV_FILE = File.join(File.dirname(__FILE__), 'gpx_files/with_or_without_elev.gpx') WITH_EMPT...
github
dougfales/gpx
https://github.com/dougfales/gpx
tests/geojson_test.rb
Ruby
mit
94
master
5,899
# frozen_string_literal: true require 'minitest/autorun' require 'gpx' require 'json' class GeojsonTest < Minitest::Test # Test passing a file name def test_geojson_file_name_as_param file_name = "#{File.dirname(__FILE__)}/geojson_files/line_string_data.json" gpx_file = GPX::GeoJSON.convert_to_gpx(geojson...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
jsonapi-consumer.gemspec
Ruby
apache-2.0
94
master
1,296
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'jsonapi/consumer/version' Gem::Specification.new do |spec| spec.name = "jsonapi-consumer" spec.version = Jsonapi::Consumer::VERSION spec.authors = ["Justin Smestad"] ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
Rakefile
Ruby
apache-2.0
94
master
437
require "bundler/gem_tasks" require 'rdoc/task' RDoc::Task.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'JsonApiClient' rdoc.options << '--line-numbers' rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end require 'rake/testtask' Rake::TestTask.new(:test) do |t...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer.rb
Ruby
apache-2.0
94
master
2,427
require "jsonapi/consumer/version" require "active_support" require "active_support/inflector" require "active_support/core_ext" require "active_model" require "forwardable" require "faraday" require "faraday_middleware" require "addressable/uri" require "request_store" module JSONAPI module Consumer module As...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/connection.rb
Ruby
apache-2.0
94
master
1,153
module JSONAPI::Consumer class Connection attr_reader :faraday def initialize(options = {}) site = options.fetch(:site) connection_options = options.slice(:proxy, :ssl, :request, :headers, :params) adapter_options = Array(options.fetch(:adapter, Faraday.default_adapter)) @faraday = F...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/error_collector.rb
Ruby
apache-2.0
94
master
1,492
module JSONAPI::Consumer class ErrorCollector < Array class Error delegate :[], to: :attrs def initialize(attrs = {}) @attrs = (attrs || {}).with_indifferent_access end def id attrs[:id] end def about res = attrs.fetch(:links, {}) res ? res[:a...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/errors.rb
Ruby
apache-2.0
94
master
1,069
module JSONAPI::Consumer module Errors class ApiError < StandardError attr_reader :env def initialize(message, env=nil) super(message) @env = env end end class ClientError < ApiError; end class AccessDenied < ClientError; end class NotAuthorized < ClientError; en...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/implementation.rb
Ruby
apache-2.0
94
master
354
module JSONAPI::Consumer class Implementation attr_reader :version, :meta def initialize(data) # If the version member is not present, clients should assume the server implements at least version 1.0 of the specification. @version = data.fetch("version", "1.0") @meta = MetaData.new(data.fe...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/meta_data.rb
Ruby
apache-2.0
94
master
342
module JSONAPI::Consumer class MetaData include Helpers::DynamicAttributes attr_accessor :record_class def initialize(data, record_class = nil) self.record_class = record_class self.attributes = data end protected def key_formatter record_class && record_class.key_formatt...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/result_set.rb
Ruby
apache-2.0
94
master
637
require 'forwardable' module JSONAPI::Consumer class ResultSet < Array extend Forwardable attr_accessor :errors, :record_class, :meta, :pages, :uri, :links, :implementation, :relatio...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/resource.rb
Ruby
apache-2.0
94
master
17,533
module JSONAPI::Consumer class Resource extend ActiveModel::Naming extend ActiveModel::Translation include ActiveModel::Validations include ActiveModel::Conversion include ActiveModel::Serialization include Helpers::DynamicAttributes include Helpers::Dirty attr_accessor :last_result_...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/utils.rb
Ruby
apache-2.0
94
master
856
module JSONAPI::Consumer module Utils def self.compute_type(klass, type_name) # If the type is prefixed with a scope operator then we assume that # the type_name is an absolute reference. return type_name.constantize if type_name.match(/^::/) # Build a list of candidates to search for ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/formatter.rb
Ruby
apache-2.0
94
master
2,709
# Taken form jsonapi_resources formatter module JSONAPI::Consumer class Formatter class << self def format(arg) arg.to_s end def unformat(arg) # We call to_s() here so that unformat consistently returns a string # (instead of a symbol) regardless which Formatter subcl...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/schema.rb
Ruby
apache-2.0
94
master
3,552
module JSONAPI::Consumer class Schema module Types class Integer def self.cast(value, _) value.to_i end end class String def self.cast(value, _) value.to_s end end class Float def self.cast(value, _) value.to_f ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/included_data.rb
Ruby
apache-2.0
94
master
1,710
module JSONAPI::Consumer class IncludedData attr_reader :data def initialize(result_set, data) record_class = result_set.record_class grouped_data = data.group_by{|datum| datum["type"]} @data = grouped_data.inject({}) do |h, (type, records)| klass = Utils.compute_type(record_class, ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/parsers/parser.rb
Ruby
apache-2.0
94
master
3,722
module JSONAPI::Consumer module Parsers class Parser class << self def parse(klass, response) data = response.body.present? ? response.body : {} ResultSet.new.tap do |result_set| result_set.record_class = klass result_set.uri = response.env[:url] ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/paginating/paginator.rb
Ruby
apache-2.0
94
master
1,851
module JSONAPI::Consumer module Paginating class Paginator class_attribute :page_param, :per_page_param self.page_param = "page" self.per_page_param = "per_page" attr_reader :params, :result_set, :links def initialize(result_set, data) @params = param...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/relationships/relations.rb
Ruby
apache-2.0
94
master
1,328
module JSONAPI::Consumer module Relationships class Relations include Helpers::DynamicAttributes include Helpers::Dirty include ActiveModel::Serialization attr_reader :record_class delegate :key_formatter, to: :record_class def initialize(record_class, relations) @rec...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/relationships/top_level_relations.rb
Ruby
apache-2.0
94
master
719
module JSONAPI::Consumer module Relationships class TopLevelRelations attr_reader :relations, :record_class def initialize(record_class, relations) @relations = relations @record_class = record_class end def respond_to_missing?(method, include_private = false) re...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/associations/belongs_to.rb
Ruby
apache-2.0
94
master
846
module JSONAPI::Consumer module Associations module BelongsTo extend ActiveSupport::Concern module ClassMethods def belongs_to(attr_name, options = {}) # self.associations = self.associations + [HasOne::Association.new(attr_name, self, options)] self.associations += [Belon...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/associations/base_association.rb
Ruby
apache-2.0
94
master
624
module JSONAPI::Consumer module Associations class BaseAssociation attr_reader :attr_name, :klass, :options def initialize(attr_name, klass, options = {}) @attr_name = attr_name @klass = klass @options = options end def association_class @association_class ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/associations/has_many.rb
Ruby
apache-2.0
94
master
641
module JSONAPI::Consumer module Associations module HasMany extend ActiveSupport::Concern module ClassMethods def has_many(attr_name, options = {}) self.associations = self.associations + [HasMany::Association.new(attr_name, self, options)] end end class Associa...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/associations/has_one.rb
Ruby
apache-2.0
94
master
427
module JSONAPI::Consumer module Associations module HasOne extend ActiveSupport::Concern module ClassMethods def has_one(attr_name, options = {}) self.associations += [HasOne::Association.new(attr_name, self, options)] end end class Association < BaseAssociation...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/middleware/json_request.rb
Ruby
apache-2.0
94
master
759
module JSONAPI::Consumer module Middleware class JsonRequest < Faraday::Middleware def call(environment) accept_header = update_accept_header(environment[:request_headers]) environment[:request_headers]["Content-Type"] = 'application/vnd.api+json' environment[:request_headers]["Acce...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/middleware/status.rb
Ruby
apache-2.0
94
master
1,150
module JSONAPI::Consumer module Middleware class Status < Faraday::Middleware def call(environment) @app.call(environment).on_complete do |env| handle_status(env[:status], env) # look for meta[:status] if env[:body].is_a?(Hash) code = env[:body].fetch("meta...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/middleware/parse_json.rb
Ruby
apache-2.0
94
master
713
module JSONAPI::Consumer module Middleware class ParseJson < Faraday::Middleware def call(environment) @app.call(environment).on_complete do |env| if process_response_type?(response_type(env)) env[:raw_body] = env[:body] env[:body] = parse(env[:body]) end...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/linking/top_level_links.rb
Ruby
apache-2.0
94
master
899
module JSONAPI::Consumer module Linking class TopLevelLinks attr_reader :links, :record_class def initialize(record_class, links) @links = links @record_class = record_class end def respond_to_missing?(method, include_private = false) links.has_key?(method.to_s) ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/linking/links.rb
Ruby
apache-2.0
94
master
344
module JSONAPI::Consumer module Linking class Links include Helpers::DynamicAttributes def initialize(links) self.attributes = links end def present? attributes.present? end protected def set_attribute(name, value) attributes[name] = value ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/helpers/callbacks.rb
Ruby
apache-2.0
94
master
502
module JSONAPI::Consumer module Helpers module Callbacks extend ActiveSupport::Concern included do extend ActiveModel::Callbacks define_model_callbacks :save, :destroy, :create, :update end def save run_callbacks :save do run_callbacks (persisted? ? :upd...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/helpers/uri.rb
Ruby
apache-2.0
94
master
209
module JSONAPI::Consumer module Helpers module URI def encode_part(part) Addressable::URI.encode_component(part, Addressable::URI::CharacterClasses::UNRESERVED) end end end end
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/helpers/dynamic_attributes.rb
Ruby
apache-2.0
94
master
1,803
module JSONAPI::Consumer module Helpers module DynamicAttributes def attributes @attributes end def attributes=(attrs = {}) @attributes ||= ActiveSupport::HashWithIndifferentAccess.new return @attributes unless attrs.present? attrs.each do |key, value| ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/helpers/dirty.rb
Ruby
apache-2.0
94
master
1,745
module JSONAPI::Consumer module Helpers module Dirty def changed? changed_attributes.present? end def changed changed_attributes.keys end def changed_attributes @changed_attributes ||= ActiveSupport::HashWithIndifferentAccess.new end def clear_...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/query/builder.rb
Ruby
apache-2.0
94
master
4,999
module JSONAPI::Consumer module Query class Builder attr_reader :klass, :requestor delegate :key_formatter, to: :klass def initialize(klass, requestor = nil) @klass = klass @requestor = requestor || klass.requestor @primary_key = nil @pagination_params = {} ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
lib/jsonapi/consumer/query/requestor.rb
Ruby
apache-2.0
94
master
1,620
module JSONAPI::Consumer module Query class Requestor extend Forwardable include Helpers::URI def initialize(klass, path = nil) @klass = klass @path = path end # expects a record def create(record) request(:post, klass.path(record.attributes), { ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/test_helper.rb
Ruby
apache-2.0
94
master
1,191
require "bundler/setup" require "jsonapi/consumer" require 'minitest/autorun' require 'webmock/minitest' require 'mocha/minitest' require 'minitest/ci' if ENV['CI'] # shim for ActiveSupport 4.0.x requiring minitest 4.2 unless defined?(Minitest::Test) Minitest::Test = Minitest::Unit::TestCase end WebMock.disable_ne...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/error_collector_test.rb
Ruby
apache-2.0
94
master
8,843
require 'test_helper' class ErrorCollectorTest < MiniTest::Test def test_can_handle_no_errors stub_request(:post, "http://example.com/articles") .with(headers: {content_type: "application/vnd.api+json", accept: "application/vnd.api+json"}, body: { data: { type: "articles", ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/custom_header_test.rb
Ruby
apache-2.0
94
master
3,548
require 'test_helper' class CustomHeaderTest < MiniTest::Test class CustomHeaderResource < TestResource end def test_can_set_custom_headers stub_request(:get, "http://example.com/custom_header_resources/1") .with(headers: {"X-My-Header" => "asdf"}) .to_return(headers: {content_type: "applicatio...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/updating_test.rb
Ruby
apache-2.0
94
master
21,848
require 'test_helper' class UpdatingTest < MiniTest::Test class Author < TestResource def relationships_for_serialization super.except('reader') end end class CallbackTest < TestResource include JSONAPI::Consumer::Helpers::Callbacks before_update do self.foo = 10 end after_...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/custom_paginator_params_test.rb
Ruby
apache-2.0
94
master
643
require 'test_helper' class CustomPaginatorTest < MiniTest::Test class CustomPaginator < JSONAPI::Consumer::Paginating::Paginator self.page_param = 'pagina' self.per_page_param = 'limit' end class Book < JSONAPI::Consumer::Resource self.site = "http://example.com/" self.paginator = CustomPagina...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/compound_document_test.rb
Ruby
apache-2.0
94
master
4,501
require 'test_helper' class CompoundDocumentTest < MiniTest::Test TEST_DATA = %{ { "links": { "self": "http://example.com/posts", "next": "http://example.com/posts?page[offset]=2", "last": "http://example.com/posts?page[offset]=10" }, "data": [{ "type": "posts",...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/meta_test.rb
Ruby
apache-2.0
94
master
2,359
require 'test_helper' class MetaTest < MiniTest::Test def test_can_parse_global_meta_data stub_request(:get, "http://example.com/articles/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { type: "articles", id: "1", attributes: { ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/connection_test.rb
Ruby
apache-2.0
94
master
2,073
require 'test_helper' require 'logger' class NullConnection def initialize(*args) end def run(*args) end end class NullParser def self.parse(*args) # do nothing end end class CustomConnectionResource < TestResource self.connection_class = NullConnection self.parser = NullParser end class Inheri...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/errors_test.rb
Ruby
apache-2.0
94
master
2,185
require 'test_helper' class ErrorsTest < MiniTest::Test def test_connection_errors stub_request(:get, "http://example.com/users") .to_raise(Faraday::ConnectionFailed) assert_raises JSONAPI::Consumer::Errors::ConnectionError do User.all end end def test_timeout_errors stub_request(:...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/benchmark_dynamic_attributes_test.rb
Ruby
apache-2.0
94
master
1,041
require 'test_helper' require 'benchmark' class BenchmarkDynamicAttributesTest < MiniTest::Test def test_can_parse_global_meta_data stub_request(:get, "http://example.com/articles/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { type: "articles", ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/destroying_test.rb
Ruby
apache-2.0
94
master
2,443
require 'test_helper' class DestroyingTest < MiniTest::Test class CallbackTest < TestResource include JSONAPI::Consumer::Helpers::Callbacks attr_accessor :foo after_destroy do self.foo = 10 end end def test_destroy stub_request(:delete, "http://example.com/users/6") .to_return(h...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/status_test.rb
Ruby
apache-2.0
94
master
1,468
require 'test_helper' class StatusTest < MiniTest::Test def test_server_responding_with_status_meta stub_request(:get, "http://example.com/users/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { meta: { status: 500, message: "An internal server error h...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/editing_test.rb
Ruby
apache-2.0
94
master
2,025
require 'test_helper' class Author < TestResource end class EditingTest < MiniTest::Test def test_attribute_changed stub_request(:get, "http://example.com/authors/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/parser_test.rb
Ruby
apache-2.0
94
master
2,422
require 'test_helper' class ParserTest < MiniTest::Test def test_can_parse_single_record stub_request(:get, "http://example.com/articles/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { type: "articles", id: "1", attributes: { ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/query_builder_test.rb
Ruby
apache-2.0
94
master
5,632
require 'test_helper' class QueryBuilderTest < MiniTest::Test def test_can_filter stub_request(:get, "http://example.com/articles") .with(query: {filter: {author: '5'}}) .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: [] }.to_json) Article.where(author...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/implementation_test.rb
Ruby
apache-2.0
94
master
1,159
require 'test_helper' class ImplementationTest < MiniTest::Test def test_defaults_on_missing_fields stub_request(:get, "http://example.com/articles") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: [{ type: "articles", id: "1", attributes...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/server_side_error_test.rb
Ruby
apache-2.0
94
master
1,694
require 'test_helper' class ServerSideErrorTest < MiniTest::Test def test_can_handle_validations stub_request(:post, "http://example.com/users") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { errors: [ { id: 'someguid', status: "400", ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/top_level_links_test.rb
Ruby
apache-2.0
94
master
8,125
require 'test_helper' class TopLevelLinksTest < MiniTest::Test def test_can_parse_global_links stub_request(:get, "http://example.com/articles/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { type: "articles", id: "1", attributes: { ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/schemable_test.rb
Ruby
apache-2.0
94
master
3,754
require 'test_helper' class CustomTypeCaster def self.cast(*) :mock end end JSONAPI::Consumer::Schema.register custom: CustomTypeCaster class SchemaResource < TestResource property :a, type: :string, default: 'foo' property :b, type: :boolean, default: false property :c property :d, type: :integer e...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/serializing_test.rb
Ruby
apache-2.0
94
master
8,278
require 'test_helper' class SerializingTest < MiniTest::Test class LimitedField < TestResource self.read_only_attributes += ['foo'] end class CustomSerializerAttributes < TestResource protected def attributes_for_serialization { foo: "bar" } end end class InheritedCus...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/coercion_test.rb
Ruby
apache-2.0
94
master
2,795
require 'test_helper' class CoercionTest < MiniTest::Test TIME_STRING = '2015-04-28 10:45:35 -0700' class CoercionTypes < TestResource property :bool_me, type: :boolean property :float_me, type: :float property :int_me, type: :int property :integer_me, type: :integer property :string_me, type:...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/creation_test.rb
Ruby
apache-2.0
94
master
5,122
require 'test_helper' class CreationTest < MiniTest::Test class CallbackTest < TestResource include JSONAPI::Consumer::Helpers::Callbacks before_save do self.foo = 10 end after_create :after_create_method def after_create_method self.bar = 100 end end class Author < TestRe...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/custom_endpoint_test.rb
Ruby
apache-2.0
94
master
1,761
require 'test_helper' class Country < TestResource custom_endpoint :autocomplete, on: :collection, request_method: :get custom_endpoint :publish, on: :member, request_method: :post custom_endpoint :publish_now, on: :member, request_method: :post self.route_format = :dasherized_route end class CustomEndpoint...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/association_test.rb
Ruby
apache-2.0
94
master
17,144
require 'test_helper' class Owner < TestResource has_many :properties end class Property < TestResource has_one :owner end class Specified < TestResource belongs_to :foo, class_name: "Property" has_many :bars, class_name: "Owner" end class PrefixedOwner < TestResource has_many :prefixed_properties end cl...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/custom_paginator_test.rb
Ruby
apache-2.0
94
master
605
require 'test_helper' class CustomPaginatorTest < MiniTest::Test class CustomPaginator < JSONAPI::Consumer::Paginating::Paginator def total_entries 42 end end class Book < JSONAPI::Consumer::Resource self.site = "http://example.com/" self.paginator = CustomPaginator end def test_can_...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/persistence_test.rb
Ruby
apache-2.0
94
master
2,201
require 'test_helper' class PersistenceTest < MiniTest::Test def test_standard_primary_key user = User.new assert !user.persisted? user = User.new(id: 1234) assert !user.persisted? user = User.load(id: 1234) assert user.persisted? end def test_non_standard_primary_key user_prefere...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/finding_test.rb
Ruby
apache-2.0
94
master
2,035
require 'test_helper' # This tests this Resource.find method class FindingTest < MiniTest::Test def test_find_by_id stub_request(:get, "http://example.com/articles/1") .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: { type: "articles", id: "1", ...
github
jsmestad/jsonapi-consumer
https://github.com/jsmestad/jsonapi-consumer
test/unit/resource_test.rb
Ruby
apache-2.0
94
master
3,059
require 'test_helper' class ResourceTest < MiniTest::Test def test_basic assert_equal :id, Article.primary_key assert_equal "articles", Article.table_name assert_equal "article", Article.resource_name end def test_each_on_scope stub_request(:get, "http://example.com/articles") .with(query...