Sha256: 4b2bc2d45f12ab25e7ddc92dfd42fcc81ed92474cb7936a729f4108a80edb1c9

Contents?: true

Size: 715 Bytes

Versions: 47

Compression:

Stored size: 715 Bytes

Contents

module JsonApiClient
  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)
        relations.has_key?(method.to_s) || super
      end

      def method_missing(method, *args)
        if respond_to_missing?(method)
          fetch_relation(method)
        else
          super
        end
      end

      def fetch_relation(relation_name)
        link_definition = relations.fetch(relation_name.to_s)
        record_class.requestor.linked(link_definition)
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
json_api_client-1.23.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.22.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.21.1 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.21.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.20.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.19.0 lib/json_api_client/relationships/top_level_relations.rb
carwow-json_api_client-1.19.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.18.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.17.1 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.17.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.16.1 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.16.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.15.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.14.1 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.14.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.13.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.12.2 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.12.1 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.12.0 lib/json_api_client/relationships/top_level_relations.rb
json_api_client-1.11.0 lib/json_api_client/relationships/top_level_relations.rb