Class: KDomain::Config::Configuration
- Inherits:
-
Object
- Object
- KDomain::Config::Configuration
- Includes:
- KLog::Logging
- Defined in:
- lib/k_domain/config/configuration.rb
Overview
Configuration object for Domain Configuration
Defined Under Namespace
Classes: ConfigModel
Instance Attribute Summary collapse
-
#default_main_key ⇒ Object
Returns the value of attribute default_main_key.
-
#default_traits ⇒ Object
Returns the value of attribute default_traits.
-
#fallback_keys ⇒ Object
Returns the value of attribute fallback_keys.
-
#models ⇒ Object
Returns the value of attribute models.
Instance Method Summary collapse
- #debug(heading: 'Domain configuration') ⇒ Object
- #fallback_key(columns) ⇒ Object
- #find_model(table_name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #model(name, main_key: nil, traits: nil) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 19 20 21 |
# File 'lib/k_domain/config/configuration.rb', line 16 def initialize @default_main_key = nil @default_traits = %i[trait1 trait2 trait3] @fallback_keys = %i[] @models = [] end |
Instance Attribute Details
#default_main_key ⇒ Object
Returns the value of attribute default_main_key.
11 12 13 |
# File 'lib/k_domain/config/configuration.rb', line 11 def default_main_key @default_main_key end |
#default_traits ⇒ Object
Returns the value of attribute default_traits.
12 13 14 |
# File 'lib/k_domain/config/configuration.rb', line 12 def default_traits @default_traits end |
#fallback_keys ⇒ Object
Returns the value of attribute fallback_keys.
13 14 15 |
# File 'lib/k_domain/config/configuration.rb', line 13 def fallback_keys @fallback_keys end |
#models ⇒ Object
Returns the value of attribute models.
14 15 16 |
# File 'lib/k_domain/config/configuration.rb', line 14 def models @models end |
Instance Method Details
#debug(heading: 'Domain configuration') ⇒ Object
51 52 53 54 |
# File 'lib/k_domain/config/configuration.rb', line 51 def debug(heading: 'Domain configuration') log.structure(to_h, title: heading) # , line_width: 150, formatter: formatter) '' end |
#fallback_key(columns) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/k_domain/config/configuration.rb', line 43 def fallback_key(columns) column_names = columns.each_with_object({}) do |column, hash| hash[column.name.to_sym] = column.name.to_sym end fallback_keys.find { |key| column_names.key?(key) } end |
#find_model(table_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/k_domain/config/configuration.rb', line 31 def find_model(table_name) @find_model ||= Hash.new do |h, key| h[key] = begin entity = models.find { |e| e.name == key } entity ||= new_config_model(key) entity end end @find_model[table_name] end |
#model(name, main_key: nil, traits: nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/k_domain/config/configuration.rb', line 23 def model(name, main_key: nil, traits: nil) @models << new_config_model( name, main_key: main_key || default_main_key, traits: traits || default_traits ) end |
#to_h ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/k_domain/config/configuration.rb', line 56 def to_h { default_main_key: default_main_key, default_traits: default_traits, fallback_keys: fallback_keys, models: models.map(&:to_h) } end |