Sha256: 6065b21f455047d942fc0b9f5323eb4582e753a026b00b3f28694f4cc32c4c45

Contents?: true

Size: 807 Bytes

Versions: 13

Compression:

Stored size: 807 Bytes

Contents

module JsonApiClient
  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 ||= Utils.compute_type(klass, options.fetch(:class_name) do
          attr_name.to_s.classify
        end)
      end

      def data(url)
        from_result_set(association_class.requestor.linked(url))
      end

      def from_result_set(result_set)
        result_set.to_a
      end

      def load_records(data)
        data.map do |d|
          record_class = Utils.compute_type(klass, d["type"].classify)
          record_class.load id: d["id"]
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
json_api_client-1.17.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.17.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.16.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.16.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.15.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.14.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.14.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.13.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.12.2 lib/json_api_client/associations/base_association.rb
json_api_client-1.12.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.12.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.11.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.10.0 lib/json_api_client/associations/base_association.rb