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.
-
#deserializable_attributes ⇒ Object
readonly
Returns the value of attribute deserializable_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.
-
#serializable_attributes ⇒ Object
readonly
Returns the value of attribute serializable_attributes.
-
#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.
20 21 22 23 24 25 26 27 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 20 def initialize(serializer_class:) @attributes = [] @deserializable_attributes = [] @ledger_attribute_keyed_hash = {} @resource_attribute_keyed_hash = {} @serializable_attributes = [] @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 |
#deserializable_attributes ⇒ Object (readonly)
Returns the value of attribute deserializable_attributes.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def deserializable_attributes @deserializable_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 |
#serializable_attributes ⇒ Object (readonly)
Returns the value of attribute serializable_attributes.
6 7 8 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 6 def serializable_attributes @serializable_attributes 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 29 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 serializable_attributes << attribute if attribute.serialize? deserializable_attributes << attribute if attribute.deserialize? # 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
53 54 55 |
# File 'lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb', line 53 def ledger_attribute?(key) ledger_attribute_keyed_hash.include?(key.to_s) end |