Sha256: 56ae5232be345f7095324832de2803737888fae48a34463c0cac7396db2a4015

Contents?: true

Size: 619 Bytes

Versions: 10

Compression:

Stored size: 619 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
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
json_api_client-1.5.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.4.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.3.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.2.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.1.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.1.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.0.2 lib/json_api_client/associations/base_association.rb
json_api_client-1.0.1 lib/json_api_client/associations/base_association.rb
json_api_client-1.0.0 lib/json_api_client/associations/base_association.rb
json_api_client-1.0.0.beta7 lib/json_api_client/associations/base_association.rb