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
Methods included from Util::Mixins::DelegateIterableMethodsMixin
Constructor Details
#initialize(resource:) ⇒ ResourceAttributeSet
Returns a new instance of ResourceAttributeSet.
17 18 19 20 21 22 23 24 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 17 def initialize(resource:) @attributes = {} @references = [] @references_one = [] @references_many = [] @resource = resource end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 7 def attributes @attributes end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
7 8 9 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 7 def references @references end |
#references_many ⇒ Object (readonly)
Returns the value of attribute references_many.
7 8 9 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 7 def references_many @references_many end |
#references_one ⇒ Object (readonly)
Returns the value of attribute references_one.
7 8 9 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 7 def references_one @references_one end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 7 def resource @resource end |
Instance Method Details
#add(attribute) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 26 def add(attribute) name = attribute.name raise "Attribute #{name} already exists on #{resource.name}." if attributes.key?(name) case attribute when ResourceAttribute::Reference::One @attributes[attribute.name] = attribute @references << attribute @references_one << attribute when ResourceAttribute::Reference::Many @attributes[attribute.name] = attribute @references << attribute @references_many << attribute when ResourceAttribute @attributes[attribute.name] = attribute else raise 'Unknown attribute class' end end |
#to_a ⇒ Object
46 47 48 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 46 def to_a attributes.values end |
#to_h ⇒ Object
50 51 52 |
# File 'lib/ledger_sync/resource_attribute_set.rb', line 50 def to_h attributes.transform_values(&:value) end |