Class: LedgerSync::Serialization::Attribute
- Inherits:
-
Object
- Object
- LedgerSync::Serialization::Attribute
- Defined in:
- lib/ledger_sync/serialization/attribute.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#hash_attribute ⇒ Object
readonly
Returns the value of attribute hash_attribute.
-
#if_method ⇒ Object
readonly
Returns the value of attribute if_method.
-
#resource_attribute ⇒ Object
readonly
Returns the value of attribute resource_attribute.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #block_value_for(args = {}) ⇒ Object
- #hash_attribute_dot_parts ⇒ Object
-
#initialize(args = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #reference? ⇒ Boolean
- #resource_attribute_dot_parts ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Attribute
Returns a new instance of Attribute.
15 16 17 18 19 20 21 22 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 15 def initialize(args = {}) @block = args.fetch(:block, nil) @hash_attribute = args.fetch(:hash_attribute, nil).try(:to_s) @resource_attribute = args.fetch(:resource_attribute, nil).try(:to_s) @resource_class = args.fetch(:resource_class, nil) @type = args.fetch(:type, nil) || LedgerSync::Type::Value.new @if_method = args.fetch(:if, nil) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def block @block end |
#hash_attribute ⇒ Object (readonly)
Returns the value of attribute hash_attribute.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def hash_attribute @hash_attribute end |
#if_method ⇒ Object (readonly)
Returns the value of attribute if_method.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def if_method @if_method end |
#resource_attribute ⇒ Object (readonly)
Returns the value of attribute resource_attribute.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def resource_attribute @resource_attribute end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def resource_class @resource_class end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 8 def type @type end |
Instance Method Details
#block_value_for(args = {}) ⇒ Object
24 25 26 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 24 def block_value_for(args = {}) block.call(args.merge(attribute: self)) end |
#hash_attribute_dot_parts ⇒ Object
28 29 30 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 28 def hash_attribute_dot_parts @hash_attribute_dot_parts ||= hash_attribute.split('.') end |
#reference? ⇒ Boolean
32 33 34 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 32 def reference? references_many? || references_one? end |
#resource_attribute_dot_parts ⇒ Object
36 37 38 |
# File 'lib/ledger_sync/serialization/attribute.rb', line 36 def resource_attribute_dot_parts @resource_attribute_dot_parts ||= resource_attribute.split('.') end |