Class: LedgerSync::Util::ResourcesBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/ledger_sync/util/resources_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cast: true, data:, ignore_unrecognized_attributes: false, root_resource_external_id:, root_resource_type:) ⇒ ResourcesBuilder

Returns a new instance of ResourcesBuilder.



12
13
14
15
16
17
18
19
# File 'lib/ledger_sync/util/resources_builder.rb', line 12

def initialize(cast: true, data:, ignore_unrecognized_attributes: false, root_resource_external_id:, root_resource_type:)
  @all_resources = {}
  @cast = cast
  @data = Util::HashHelpers.deep_symbolize_keys(data)
  @ignore_unrecognized_attributes = ignore_unrecognized_attributes
  @root_resource_external_id = root_resource_external_id
  @root_resource_type = root_resource_type
end

Instance Attribute Details

#castObject (readonly)

Returns the value of attribute cast.



6
7
8
# File 'lib/ledger_sync/util/resources_builder.rb', line 6

def cast
  @cast
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/ledger_sync/util/resources_builder.rb', line 6

def data
  @data
end

#ignore_unrecognized_attributesObject (readonly)

Returns the value of attribute ignore_unrecognized_attributes.



6
7
8
# File 'lib/ledger_sync/util/resources_builder.rb', line 6

def ignore_unrecognized_attributes
  @ignore_unrecognized_attributes
end

#root_resource_external_idObject (readonly)

Returns the value of attribute root_resource_external_id.



6
7
8
# File 'lib/ledger_sync/util/resources_builder.rb', line 6

def root_resource_external_id
  @root_resource_external_id
end

#root_resource_typeObject (readonly)

Returns the value of attribute root_resource_type.



6
7
8
# File 'lib/ledger_sync/util/resources_builder.rb', line 6

def root_resource_type
  @root_resource_type
end

Instance Method Details

#resourceObject



21
22
23
24
25
26
# File 'lib/ledger_sync/util/resources_builder.rb', line 21

def resource
  @resource ||= build_resource(
    external_id: root_resource_external_id,
    type: root_resource_type
  )
end

#resourcesObject



28
29
30
31
32
33
# File 'lib/ledger_sync/util/resources_builder.rb', line 28

def resources
  @resources ||= begin
    resource
    @all_resources.values
  end
end