Class: LedgerSync::Adaptors::LedgerSerializerAttributeSet
- Inherits:
-
Object
- Object
- LedgerSync::Adaptors::LedgerSerializerAttributeSet
- Defined in:
- lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id_attribute ⇒ Object
readonly
Returns the value of attribute id_attribute.
-
#ledger_attribute_keyed_hash ⇒ Object
readonly
Returns the value of attribute ledger_attribute_keyed_hash.
-
#resource_attribute_keyed_hash ⇒ Object
readonly
Returns the value of attribute resource_attribute_keyed_hash.
-
#serializer_class ⇒ Object
readonly
Returns the value of attribute serializer_class.
Instance Method Summary collapse
- #add(attribute) ⇒ Object
-
#initialize(serializer_class:) ⇒ LedgerSerializerAttributeSet
constructor
A new instance of LedgerSerializerAttributeSet.
- #ledger_attribute?(key) ⇒ Boolean
Constructor Details
#initialize(serializer_class:) ⇒ LedgerSerializerAttributeSet
Returns a new instance of LedgerSerializerAttributeSet.
18 19 20 21 22 23 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 18 def initialize(serializer_class:) @attributes = [] @ledger_attribute_keyed_hash = {} @resource_attribute_keyed_hash = {} @serializer_class = serializer_class end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def attributes @attributes end |
#id_attribute ⇒ Object (readonly)
Returns the value of attribute id_attribute.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def id_attribute @id_attribute end |
#ledger_attribute_keyed_hash ⇒ Object (readonly)
Returns the value of attribute ledger_attribute_keyed_hash.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def ledger_attribute_keyed_hash @ledger_attribute_keyed_hash end |
#resource_attribute_keyed_hash ⇒ Object (readonly)
Returns the value of attribute resource_attribute_keyed_hash.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def resource_attribute_keyed_hash @resource_attribute_keyed_hash end |
#serializer_class ⇒ Object (readonly)
Returns the value of attribute serializer_class.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def serializer_class @serializer_class end |
Instance Method Details
#add(attribute) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 25 def add(attribute) @attributes << attribute @id_attribute = attribute if attribute.id if attribute.ledger_attribute.present? raise "ledger_attribute already defined for #{serializer_class.name}: #{attribute.ledger_attribute}" if ledger_attribute_keyed_hash.key?(attribute.ledger_attribute.to_s) ledger_attribute_keyed_hash[attribute.ledger_attribute.to_s] = attribute end if attribute.resource_attribute.present? raise "resource_attribute already defined for #{serializer_class.name}: #{attribute.resource_attribute}" if resource_attribute_keyed_hash.key?(attribute.resource_attribute.to_s) resource_attribute_keyed_hash[attribute.resource_attribute.to_s] = attribute end # TODO: Can make this validate something like `expense.vendor.id` # raise "#{resource_attribute} is not an attribute of the resource #{_inferred_resource_class}" if !resource_attribute.nil? && !_inferred_resource_class.serialize_attribute?(resource_attribute) attribute end |
#ledger_attribute?(key) ⇒ Boolean
46 47 48 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 46 def ledger_attribute?(key) ledger_attribute_keyed_hash.include?(key.to_s) end |