Class: Konfa::Base

Inherits:
Object
  • Object
show all
Includes:
Initializer
Defined in:
lib/konfa.rb

Class Method Summary collapse

Methods included from Initializer

included

Class Method Details

.after_initializeObject



110
111
# File 'lib/konfa.rb', line 110

def after_initialize
end

.allowed_variablesObject



55
56
57
# File 'lib/konfa.rb', line 55

def allowed_variables
  {}
end

.dumpObject



84
85
86
# File 'lib/konfa.rb', line 84

def dump
  self.configuration.dup
end

.env_variable_prefixObject

The following methods should be overridden and used to configure the configuration class



51
52
53
# File 'lib/konfa.rb', line 51

def env_variable_prefix
  'APP_'
end

.false?(variable) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/konfa.rb', line 76

def false?(variable)
  self.true?(variable) == false
end

.get(variable) ⇒ Object

The following methods provides the interface to this class



67
68
69
70
# File 'lib/konfa.rb', line 67

def get(variable)
  raise UnsupportedVariableError.new(variable) unless self.configuration.has_key? variable
  self.configuration[variable]
end

.initObject



92
93
94
95
96
97
98
99
# File 'lib/konfa.rb', line 92

def init
  return unless self.init?
  # Set to true before calling to prevent recursion if
  # an initializer is accessing the configuration
  self.initialized = true
  self.send(self.initializer.first, *self.initializer[1..-1])
  self.after_initialize
end

.init?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/konfa.rb', line 88

def init?
  !self.initialized && !self.initializer.nil?
end

.init_with(suffix, *args) ⇒ Object



101
102
103
104
# File 'lib/konfa.rb', line 101

def init_with(suffix, *args)
  self.initializer = [:"init_with_#{suffix}", *args]
  self
end

.on_key_missing(key, value) ⇒ Object



59
60
61
# File 'lib/konfa.rb', line 59

def on_key_missing(key, value)
  raise UnsupportedVariableError.new(key)
end

.reinitObject



106
107
108
# File 'lib/konfa.rb', line 106

def reinit
  self.initialized = false
end

.true?(variable) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/konfa.rb', line 72

def true?(variable)
  self.truthy?(self.get(variable))
end

.variablesObject



80
81
82
# File 'lib/konfa.rb', line 80

def variables
  self.configuration.keys
end

.with_config(overrides = {}) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/konfa.rb', line 113

def with_config(overrides={})
  original_config = dump
  overrides.each_pair {|k,v| self.store(k, v) }

  begin
    result = yield
  ensure
    self.configuration = original_config
  end

  result
end