Sha256: d7cb9e92176ba58de96671917906b45d3c4910548548ca8dd62ddc34638165ed

Contents?: true

Size: 815 Bytes

Versions: 24

Compression:

Stored size: 815 Bytes

Contents

module JsonApiClient
  module Associations
    module BelongsTo
      class Association < BaseAssociation
        include Helpers::URI

        attr_reader :param

        def initialize(attr_name, klass, options = {})
          super
          @param = options.fetch(:param, :"#{attr_name}_id").to_sym
          @shallow_path = options.fetch(:shallow_path, false)
        end

        def shallow_path?
          @shallow_path
        end

        def to_prefix_path(formatter)
          "#{formatter.format(attr_name.to_s.pluralize)}/%{#{param}}"
        end

        def set_prefix_path(attrs, formatter)
          return if shallow_path? && !attrs[param]
          attrs[param] = encode_part(attrs[param]) if attrs.key?(param)
          to_prefix_path(formatter) % attrs
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

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