Class: LedgerSync::LedgerConfigurationStore

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ledger_sync/ledger_configuration_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLedgerConfigurationStore

Returns a new instance of LedgerConfigurationStore.



9
10
11
12
13
14
15
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 9

def initialize
  @keys = []
  @base_module_to_config_mapping = {}
  @configs = {}
  @inflections = []
  @class_configs = {}
end

Instance Attribute Details

#base_module_to_config_mappingObject (readonly)

Returns the value of attribute base_module_to_config_mapping.



7
8
9
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 7

def base_module_to_config_mapping
  @base_module_to_config_mapping
end

#configsObject (readonly)

Returns the value of attribute configs.



7
8
9
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 7

def configs
  @configs
end

#inflectionsObject (readonly)

Returns the value of attribute inflections.



7
8
9
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 7

def inflections
  @inflections
end

Instance Method Details

#add_alias(client_key, existing_config) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 17

def add_alias(client_key, existing_config)
  if respond_to?(client_key)
    raise "Alias already taken: #{client_key}" if send(client_key) != existing_config

    return
  end

  _instance_methods_for(client_key: client_key, ledger_config: existing_config)
end

#config_from_base_module(base_module:) ⇒ Object



31
32
33
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 31

def config_from_base_module(base_module:)
  @base_module_to_config_mapping.fetch(base_module, nil)
end

#config_from_class(client_class:) ⇒ Object



27
28
29
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 27

def config_from_class(client_class:)
  @class_configs.fetch(client_class)
end

#each(&block) ⇒ Object



35
36
37
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 35

def each(&block)
  configs.each(&block)
end

#find(&block) ⇒ Object



39
40
41
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 39

def find(&block)
  configs.values.find(&block)
end

#register_ledger(ledger_config:) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ledger_sync/ledger_configuration_store.rb', line 43

def register_ledger(ledger_config:)
  @base_module_to_config_mapping[ledger_config.base_module] = ledger_config

  _instance_methods_for(
    client_key: ledger_config.root_key,
    ledger_config: ledger_config
  )
end