Module: KConfig

Defined in:
lib/k_config.rb,
lib/k_config/version.rb,
lib/k_config/configuration.rb

Overview

KConfig is a configuration helper for k_* GEMs.

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

Error =

raise KConfig::Error, ‘Sample message’

Class.new(StandardError)
VERSION =
'0.0.11'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configuration(config_name = :default) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/k_config.rb', line 23

def configuration(config_name = :default)
  @configuration ||= Hash.new do |h, key|
    h[key] = default_configuration_type.new
  end
  config = @configuration[config_name]
  config.config_name = config_name if config.respond_to?(:config_name) && config.config_name.nil?
  config
end

.default_configuration_typeObject



19
20
21
# File 'lib/k_config.rb', line 19

def default_configuration_type
  @default_configuration_type ||= KConfig::Configuration
end

Class Method Details

.configure(config_name = :default) {|configuration(config_name)| ... } ⇒ Object

Yields:



41
42
43
# File 'lib/k_config.rb', line 41

def configure(config_name = :default)
  yield(configuration(config_name))
end

.reset(config_name = :default) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/k_config.rb', line 32

def reset(config_name = :default)
  @configuration ||= Hash.new do |h, key|
    h[key] = default_configuration_type.new
  end
  config = default_configuration_type.new
  config.config_name = config_name if config.respond_to?(:config_name) && config.config_name.nil?
  @configuration[config_name] = config
end