Class: KConfig::Configuration

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging, KUtil::Data::InstanceVariablesToH
Defined in:
lib/k_config/configuration.rb

Overview

Configuration object for all k_* GEMs.

Hooks:

You can use hooks to add your own customizations to configuration extensions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize configuration.

Will call #configuration_key_initialize method if it exists.



17
18
19
20
21
22
# File 'lib/k_config/configuration.rb', line 17

def initialize
  self.class.registered_keys.each do |key|
    method = "#{key}_initialize".to_sym
    send(method) if respond_to?(method)
  end
end

Instance Attribute Details

#config_nameObject

Returns the value of attribute config_name.



12
13
14
# File 'lib/k_config/configuration.rb', line 12

def config_name
  @config_name
end

Class Method Details

.register(key, extension) ⇒ Object

Register configuration extension key

This key provides a unique method name prefix to common methods such as debug and initialize_copy



54
55
56
57
58
59
60
61
62
# File 'lib/k_config/configuration.rb', line 54

def register(key, extension)
  if registered_keys.include?(key)
    puts "Key #{key} already registered ... skipping"
    return registered_keys
  end

  include(extension)
  registered_keys << key
end

.registered_keysObject



47
48
49
# File 'lib/k_config/configuration.rb', line 47

def registered_keys
  @registered_keys ||= []
end

Instance Method Details

#debugObject

Debug configuration is used for debugging.

Will call #configuration_key_debug method if it exists.



27
28
29
30
31
32
33
34
# File 'lib/k_config/configuration.rb', line 27

def debug
  log.section_heading(config_name) if config_name

  self.class.registered_keys.each do |key|
    method = "#{key}_debug".to_sym
    send(method) if respond_to?(method)
  end
end

#initialize_copy(orig) ⇒ Object

Initialize_copy, used during clone.

Will call #configuration_key_initialize_copy method if it exists.



39
40
41
42
43
44
# File 'lib/k_config/configuration.rb', line 39

def initialize_copy(orig)
  self.class.registered_keys.each do |key|
    method = "#{key}_initialize_copy".to_sym
    send(method, orig) if respond_to?(method)
  end
end