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

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

#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

#if_methodObject (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_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



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_partsObject



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

Returns:

  • (Boolean)


32
33
34
# File 'lib/ledger_sync/serialization/attribute.rb', line 32

def reference?
  references_many? || references_one?
end

#resource_attribute_dot_partsObject



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