Class: JsonApiClient::Associations::BelongsTo::Association
- Inherits:
-
JsonApiClient::Associations::BaseAssociation
- Object
- JsonApiClient::Associations::BaseAssociation
- JsonApiClient::Associations::BelongsTo::Association
- Includes:
- Helpers::URI
- Defined in:
- lib/json_api_client/associations/belongs_to.rb
Instance Attribute Summary collapse
-
#param ⇒ Object
readonly
Returns the value of attribute param.
Attributes inherited from JsonApiClient::Associations::BaseAssociation
Instance Method Summary collapse
-
#initialize(attr_name, klass, options = {}) ⇒ Association
constructor
A new instance of Association.
- #set_prefix_path(attrs, formatter) ⇒ Object
- #shallow_path? ⇒ Boolean
- #to_prefix_path(formatter) ⇒ Object
Methods included from Helpers::URI
Methods inherited from JsonApiClient::Associations::BaseAssociation
#association_class, #data, #from_result_set, #load_records
Constructor Details
#initialize(attr_name, klass, options = {}) ⇒ Association
Returns a new instance of Association.
9 10 11 12 13 |
# File 'lib/json_api_client/associations/belongs_to.rb', line 9 def initialize(attr_name, klass, = {}) super @param = .fetch(:param, :"#{attr_name}_id").to_sym @shallow_path = .fetch(:shallow_path, false) end |
Instance Attribute Details
#param ⇒ Object (readonly)
Returns the value of attribute param.
7 8 9 |
# File 'lib/json_api_client/associations/belongs_to.rb', line 7 def param @param end |
Instance Method Details
#set_prefix_path(attrs, formatter) ⇒ Object
23 24 25 26 27 |
# File 'lib/json_api_client/associations/belongs_to.rb', line 23 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 |
#shallow_path? ⇒ Boolean
15 16 17 |
# File 'lib/json_api_client/associations/belongs_to.rb', line 15 def shallow_path? @shallow_path end |
#to_prefix_path(formatter) ⇒ Object
19 20 21 |
# File 'lib/json_api_client/associations/belongs_to.rb', line 19 def to_prefix_path(formatter) "#{formatter.format(attr_name.to_s.pluralize)}/%{#{param}}" end |