Sha256: 535b1507c5029c1020430de1f97fd2427828f86f8c18fdf4845efd061c592dd9

Contents?: true

Size: 791 Bytes

Versions: 1

Compression:

Stored size: 791 Bytes

Contents

module JsonApiClient
  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 += [BelongsTo::Association.new(attr_name, self, options)]
        end
      end

      class Association < BaseAssociation
        include Helpers::URI
        def param
          :"#{attr_name}_id"
        end

        def to_prefix_path
          "#{attr_name.to_s.pluralize}/%{#{param}}"
        end

        def set_prefix_path(attrs)
          attrs[param] = encode_part(attrs[param]) if attrs.key?(param)
          to_prefix_path % attrs
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
json_api_client-1.5.1 lib/json_api_client/associations/belongs_to.rb