Class: ZuoraConnectUi::Serializer::Relationship
- Inherits:
-
Object
- Object
- ZuoraConnectUi::Serializer::Relationship
- Defined in:
- lib/zuora_connect_ui/serializer/relationship.rb
Overview
The configuration for a relationship between models
Instance Attribute Summary collapse
-
#id_method_name ⇒ Object
readonly
key may be plural, record_type will always be singular.
-
#key ⇒ Object
readonly
key may be plural, record_type will always be singular.
-
#plural_type ⇒ Object
readonly
key may be plural, record_type will always be singular.
-
#record_type ⇒ Object
readonly
key may be plural, record_type will always be singular.
-
#relationship_type ⇒ Object
readonly
key may be plural, record_type will always be singular.
Instance Method Summary collapse
-
#initialize(key:, relationship_type:) ⇒ Relationship
constructor
A new instance of Relationship.
- #serialize(resources, fields) ⇒ Object
Constructor Details
#initialize(key:, relationship_type:) ⇒ Relationship
Returns a new instance of Relationship.
11 12 13 14 15 16 17 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 11 def initialize(key:, relationship_type:) @camel_fields = {} @key = key @relationship_type = relationship_type set_id_method_name end |
Instance Attribute Details
#id_method_name ⇒ Object (readonly)
key may be plural, record_type will always be singular
8 9 10 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 8 def id_method_name @id_method_name end |
#key ⇒ Object (readonly)
key may be plural, record_type will always be singular
8 9 10 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 8 def key @key end |
#plural_type ⇒ Object (readonly)
key may be plural, record_type will always be singular
8 9 10 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 8 def plural_type @plural_type end |
#record_type ⇒ Object (readonly)
key may be plural, record_type will always be singular
8 9 10 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 8 def record_type @record_type end |
#relationship_type ⇒ Object (readonly)
key may be plural, record_type will always be singular
8 9 10 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 8 def relationship_type @relationship_type end |
Instance Method Details
#serialize(resources, fields) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zuora_connect_ui/serializer/relationship.rb', line 19 def serialize(resources, fields) relationship_hash = {} resources.each do |resource| relations = resource.public_send(key) next if relations.nil? relations = [relations] unless @relationship_type == :has_many relations.each do |relation| next if relationship_hash.key? relation.id relationship_hash[relation.id] = record_hash(relation, fields) end end relationship_hash end |