Class: LedgerSync::Serialization::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/serialization/attribute.rb

Direct Known Subclasses

DeserializerAttribute, SerializerAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Attribute



14
15
16
17
18
19
20
# File 'lib/ledger_sync/serialization/attribute.rb', line 14

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) || Type::ValueType.new
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



8
9
10
# File 'lib/ledger_sync/serialization/attribute.rb', line 8

def block
  @block
end

#hash_attributeObject (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

#resource_attributeObject (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_classObject (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

#typeObject (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



22
23
24
# File 'lib/ledger_sync/serialization/attribute.rb', line 22

def block_value_for(args = {})
  block.call(args.merge(attribute: self))
end

#hash_attribute_dot_partsObject



26
27
28
# File 'lib/ledger_sync/serialization/attribute.rb', line 26

def hash_attribute_dot_parts
  @hash_attribute_dot_parts ||= hash_attribute.split('.')
end

#reference?Boolean



30
31
32
# File 'lib/ledger_sync/serialization/attribute.rb', line 30

def reference?
  references_many? || references_one?
end

#references_many?Boolean



34
35
36
# File 'lib/ledger_sync/serialization/attribute.rb', line 34

def references_many?
  type.is_a?(Type::ReferencesManyType)
end

#references_one?Boolean



38
39
40
# File 'lib/ledger_sync/serialization/attribute.rb', line 38

def references_one?
  type.is_a?(Type::ReferencesOneType)
end

#resource_attribute_dot_partsObject



42
43
44
# File 'lib/ledger_sync/serialization/attribute.rb', line 42

def resource_attribute_dot_parts
  @resource_attribute_dot_parts ||= resource_attribute.split('.')
end