configfiles 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/Changelog +3 -0
  2. data/lib/configfiles.rb +33 -14
  3. metadata +2 -2
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.3.0
2
+ * options to avoid validation and extra computation on Base#load
3
+
1
4
  0.2.0
2
5
  * add 'virtual' parameter
3
6
 
data/lib/configfiles.rb CHANGED
@@ -7,7 +7,7 @@ require 'configfiles/extensions/enumerable'
7
7
 
8
8
  module ConfigFiles
9
9
 
10
- VERSION = '0.2.0'
10
+ VERSION = '0.3.0'
11
11
 
12
12
  # You should write a read(io) method,
13
13
  # taking an IO object and returnig a key-value hash, where keys
@@ -65,9 +65,8 @@ module ConfigFiles
65
65
  end
66
66
  end
67
67
 
68
- # +circumstance+ must be an elements of +CIRCUMSTANCES+
69
- #
70
- # returns an elements of +PREDEFINED_ACTIONS+ or a user-defined Proc
68
+ # +circumstance+ must be an element of +CIRCUMSTANCES+ .
69
+ # Returns an element of +PREDEFINED_ACTIONS+ or a user-defined Proc
71
70
  def behavior_on(circumstance); on(circumstance); end
72
71
 
73
72
  # Add a parameter.
@@ -173,7 +172,7 @@ module ConfigFiles
173
172
  end
174
173
  end
175
174
 
176
- # Set validaion rules. For example, if parameter 'a' must be
175
+ # Set validation rules. For example, if parameter 'a' must be
177
176
  # smaller than 'b':
178
177
  #
179
178
  # validate do |confdata|
@@ -200,9 +199,27 @@ module ConfigFiles
200
199
  # Load the Hash h onto the ConfigFiles object, carrying on conversions
201
200
  # to Ruby objects, validation, and default actions
202
201
  # if needed. h's keys are Symbols, h's values are typically Strings
203
- # or Enumerables yielding Strings. See also ConfigFiles::Base.parameter
204
- # and ConfigFiles::Base.on.
205
- def load(h)
202
+ # or Enumerables yielding Strings. See also ConfigFiles::Base::parameter
203
+ # and ConfigFiles::Base::on.
204
+ #
205
+ # Option Hash opt_h keys:
206
+ #
207
+ # * +:compute_defaults+ (default +true+)
208
+ # compute/assign default values to unset params if possible
209
+ #
210
+ # * +:compute_deferred+ (default +true+)
211
+ # compute/assign parameters which are function of others
212
+ #
213
+ # * +:validate+ (default +true+)
214
+ # perform validation defined in ConfigFiles::Base::validate
215
+ #
216
+ def load(h, opt_h={})
217
+ opt_h_defaults = {
218
+ :compute_defaults => true,
219
+ :compute_deferred => true,
220
+ :validate => true
221
+ }
222
+ opt_h = opt_h_defaults.merge(opt_h)
206
223
 
207
224
  h.each_pair do |id, value|
208
225
  if @@parameters[id] and @@parameters[id][:converter]
@@ -217,16 +234,18 @@ module ConfigFiles
217
234
  end
218
235
  end
219
236
 
220
- # assign default values to the remaining params
221
- @@parameters.each_pair do |name, h|
222
- if !@data[name] and @@parameters[name][:default]
223
- @data[name] = @@parameters[name][:default]
237
+ if opt_h[:defaults]
238
+ # assign default values to the remaining params
239
+ @@parameters.each_pair do |name, h|
240
+ if !@data[name] and @@parameters[name][:default]
241
+ @data[name] = @@parameters[name][:default]
242
+ end
224
243
  end
225
244
  end
226
245
 
227
- @data.merge! deferred_data
246
+ @data.merge! deferred_data if opt_h[:deferred]
228
247
 
229
- validate
248
+ validate if opt_h[:validate]
230
249
  end
231
250
 
232
251
  # Like Hash#[], but more rigidly! Raise an Exception on unknown
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guido De Rosa