Class: FunWithJsonApi::Attributes::Relationship
- Inherits:
-
FunWithJsonApi::Attribute
- Object
- FunWithJsonApi::Attribute
- FunWithJsonApi::Attributes::Relationship
- Defined in:
- lib/fun_with_json_api/attributes/relationship.rb
Instance Attribute Summary collapse
-
#deserializer_class ⇒ Object
readonly
Returns the value of attribute deserializer_class.
Attributes inherited from FunWithJsonApi::Attribute
Class Method Summary collapse
-
.create(name, deserializer_class_or_callable, options = {}) ⇒ Object
Creates a new Relationship with name.
Instance Method Summary collapse
- #decode(id_value) ⇒ Object
- #deserializer ⇒ Object
-
#has_many? ⇒ Boolean
rubocop:disable Style/PredicateName.
-
#initialize(name, deserializer_class, options = {}) ⇒ Relationship
constructor
A new instance of Relationship.
-
#param_value ⇒ Object
rubocop:enable Style/PredicateName.
Methods inherited from FunWithJsonApi::Attribute
Constructor Details
#initialize(name, deserializer_class, options = {}) ⇒ Relationship
Returns a new instance of Relationship.
16 17 18 19 20 21 22 23 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 16 def initialize(name, deserializer_class, = {}) = .reverse_merge( attributes: [], relationships: [] ) super(name, ) @deserializer_class = deserializer_class end |
Instance Attribute Details
#deserializer_class ⇒ Object (readonly)
Returns the value of attribute deserializer_class.
13 14 15 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 13 def deserializer_class @deserializer_class end |
Class Method Details
.create(name, deserializer_class_or_callable, options = {}) ⇒ Object
Creates a new Relationship with name
9 10 11 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 9 def self.create(name, deserializer_class_or_callable, = {}) new(name, deserializer_class_or_callable, ) end |
Instance Method Details
#decode(id_value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 25 def decode(id_value) return nil if id_value.nil? if id_value.is_a?(Array) raise build_invalid_relationship_error(id_value) end resource = deserializer.load_resource_from_id_value(id_value) raise build_missing_relationship_error(id_value) if resource.nil? (resource, id_value) resource.id end |
#deserializer ⇒ Object
52 53 54 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 52 def deserializer @deserializer ||= end |
#has_many? ⇒ Boolean
rubocop:disable Style/PredicateName
42 43 44 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 42 def has_many? false end |
#param_value ⇒ Object
rubocop:enable Style/PredicateName
48 49 50 |
# File 'lib/fun_with_json_api/attributes/relationship.rb', line 48 def param_value :"#{as}_id" end |