Class: LedgerSync::ResourceAttributeSet
- Inherits:
-
Object
- Object
- LedgerSync::ResourceAttributeSet
- Defined in:
- lib/ledger_sync/resource_attribute_set.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
-
#references_many ⇒ Object
readonly
Returns the value of attribute references_many.
-
#references_one ⇒ Object
readonly
Returns the value of attribute references_one.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #add(attribute) ⇒ Object
-
#initialize(resource:) ⇒ ResourceAttributeSet
constructor
A new instance of ResourceAttributeSet.
- #to_a ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(resource:) ⇒ ResourceAttributeSet
Returns a new instance of ResourceAttributeSet.
21 22 23 24 25 26 27 28 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 21 def initialize(resource:) @attributes = {} @references = [] @references_one = [] @references_many = [] @resource = resource end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 5 def attributes @attributes end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
5 6 7 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 5 def references @references end |
#references_many ⇒ Object (readonly)
Returns the value of attribute references_many.
5 6 7 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 5 def references_many @references_many end |
#references_one ⇒ Object (readonly)
Returns the value of attribute references_one.
5 6 7 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 5 def references_one @references_one end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 5 def resource @resource end |
Instance Method Details
#add(attribute) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 30 def add(attribute) name = attribute.name raise "Attribute #{name} already exists on #{resource.name}." if attributes.key?(name) if attribute.is_a?(ResourceAttribute::Reference::One) @attributes[attribute.name] = attribute @references << attribute @references_one << attribute elsif attribute.is_a?(ResourceAttribute::Reference::Many) @attributes[attribute.name] = attribute @references << attribute @references_many << attribute elsif attribute.is_a?(ResourceAttribute) @attributes[attribute.name] = attribute else raise 'Unknown attribute class' end end |
#to_a ⇒ Object
49 50 51 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 49 def to_a attributes.values end |
#to_h ⇒ Object
53 54 55 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 53 def to_h Hash[attributes.map { |k, v| [k, v.value] }] end |