konfa 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/konfa.rb +33 -18
  2. metadata +2 -2
@@ -12,12 +12,16 @@ module Konfa
12
12
  # they will then be public
13
13
  #
14
14
 
15
- attr_writer :configuration
15
+ attr_writer :configuration, :deferred
16
16
 
17
17
  def configuration
18
18
  @configuration ||= self.allowed_variables
19
19
  end
20
20
 
21
+ def deferred
22
+ @deferred ||= nil
23
+ end
24
+
21
25
  def truthy?(value)
22
26
  (!value.nil? && value =~ /^\s*(?:true|1|yes|on)\s*$/i) ? true : false
23
27
  end
@@ -31,6 +35,11 @@ module Konfa
31
35
  end
32
36
  end
33
37
 
38
+ def do_deferred_initialization
39
+ self.send(self.deferred.first, *self.deferred[1..-1])
40
+ self.deferred = nil
41
+ end
42
+
34
43
  public
35
44
 
36
45
  #
@@ -55,6 +64,7 @@ module Konfa
55
64
  #
56
65
 
57
66
  def get(variable)
67
+ self.do_deferred_initialization unless self.deferred.nil?
58
68
  raise UnsupportedVariableError.new(variable) unless self.configuration.has_key? variable
59
69
  self.configuration[variable]
60
70
  end
@@ -75,11 +85,31 @@ module Konfa
75
85
  self.configuration.dup
76
86
  end
77
87
 
88
+ def initialize_deferred(method, *args)
89
+ self.deferred = [method, *args]
90
+ end
91
+
92
+ def after_initialize
93
+ end
94
+
95
+ def with_config(overrides={})
96
+ original_config = dump
97
+ overrides.each_pair {|k,v| self.store(k, v) }
98
+
99
+ begin
100
+ result = yield
101
+ ensure
102
+ self.configuration = original_config
103
+ end
104
+
105
+ result
106
+ end
107
+
108
+ # FIXME: Move out to external package
78
109
  def initialize_from_yaml(path)
79
110
  # FIXME: It would be a lot cleaner if the YAML library would raise an
80
111
  # exception if it fails to read the file. We'll handle it like this for now
81
112
  # load_file just returns "false" if it fails
82
-
83
113
  yaml_data = YAML.load_file(path)
84
114
 
85
115
  unless yaml_data.nil?
@@ -94,6 +124,7 @@ module Konfa
94
124
  dump
95
125
  end
96
126
 
127
+ # FIXME: Move out to external package
97
128
  def initialize_from_env
98
129
  conf_prefix = self.env_variable_prefix.upcase
99
130
 
@@ -107,22 +138,6 @@ module Konfa
107
138
  after_initialize
108
139
  dump
109
140
  end
110
-
111
- def after_initialize
112
- end
113
-
114
- def with_config(overrides={})
115
- original_config = dump
116
- overrides.each_pair {|k,v| self.store(k, v) }
117
-
118
- begin
119
- result = yield
120
- ensure
121
- self.configuration = original_config
122
- end
123
-
124
- result
125
- end
126
141
  end
127
142
  end
128
143
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -31,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 1.9.3
35
35
  required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  none: false
37
37
  requirements: