configru 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fe2eb4ab4567132c798bceaa960d6952f24f64f
4
- data.tar.gz: 610aab18e8619ece1f85c3c5a6e2b4119375e7b9
3
+ metadata.gz: 411032b2676edb0558982ceeeba01327afa061ea
4
+ data.tar.gz: e4cdc8a16b7d93d38fea32109f4f63c5470a2137
5
5
  SHA512:
6
- metadata.gz: 1b5684f556040ba711ebeae9b71012cb775ebc62209b8e067de935e1146ea130b7841d755512686983171b8487b9e0bcf04c22c30a9d6dabe67a6de48f1844b1
7
- data.tar.gz: 3927b8495c5402df1723a2ed18e96f23a74dafc587ee02c8253a247ee084a9834d60fae8c33632da984f60d58728885d9e18d7a06458fe4463bbcde4a827fa35
6
+ metadata.gz: c97c37b22cf0bf4e28bd076970b82d6a325cdb85a68d7312c821fcd747c943ac007fbb0650e0138c7ba33fd77c568b48e3010f85900bd540804b54db719533bb
7
+ data.tar.gz: 424fcc556bd4f9f42694db51fed76673153c0dc0ce4cf8ee9f6f4a095ebd27b819b58945f4751640be76980ceb39cebceac09418fd3afea37cb940c351955f0c
data/ChangeLog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.5.0 (9 October 2013)
4
+
5
+ * Treat `nil` as being the correct type
6
+
3
7
  ## 3.4.0 (8 October 2013)
4
8
 
5
9
  * Added `Configru::Config` class
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- configru (3.4.0)
4
+ configru (3.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -7,7 +7,7 @@ YAML configuration file loader
7
7
  Install the gem or add it to your `Gemfile`:
8
8
 
9
9
  ```ruby
10
- gem 'configru', '~> 3.4.0'
10
+ gem 'configru', '~> 3.5.0'
11
11
  ```
12
12
 
13
13
  Next, require it and load a configuration:
@@ -33,7 +33,10 @@ end
33
33
  ```
34
34
 
35
35
  `option` takes 4 arguments: the configuration key, the type of value,
36
- the default value, and an optional validation check.
36
+ the default value, and a validation check. The type defaults to
37
+ `Object`, the default value defaults to `nil` and the validation check
38
+ defaults to nothing. Note that a value of `nil` will be treated as the
39
+ correct type regardless of the specified type.
37
40
 
38
41
  The configuration option above can then be accessed in two ways:
39
42
 
@@ -24,6 +24,7 @@ module Configru
24
24
  # Load all defaults if no files were loaded
25
25
  # TODO: Some way to not special case this
26
26
  @option_path = Array.new
27
+ @file = '(none)'
27
28
  load_group(@options, self, {}) if loaded_files.empty?
28
29
  end
29
30
 
@@ -31,6 +32,7 @@ module Configru
31
32
 
32
33
  def load_file(file)
33
34
  @option_path = Array.new
35
+ @file = file
34
36
  load_group(@options, self, YAML.load_file(file) || {})
35
37
  end
36
38
 
@@ -41,7 +43,7 @@ module Configru
41
43
  # option is a group
42
44
  if option.is_a? Hash
43
45
  if input.has_key?(key) && !input[key].is_a?(Hash)
44
- raise OptionTypeError.new(@option_path, Hash, input[key].class)
46
+ raise OptionTypeError.new(@file, @option_path, Hash, input[key].class)
45
47
  end
46
48
  group_output = output[key] || StructHash.new
47
49
  load_group(option, group_output, input[key] || {})
@@ -56,17 +58,17 @@ module Configru
56
58
  @option_path.pop
57
59
  next
58
60
  elsif option.is_a? RequiredOption
59
- raise OptionRequiredError.new(@option_path)
61
+ raise OptionRequiredError.new(@file, @option_path)
60
62
  else # option has not been set
61
63
  value = option.default
62
64
  end
63
65
 
64
66
  unless option.type?(value)
65
- raise OptionTypeError.new(@option_path, option.type, value.class)
67
+ raise OptionTypeError.new(@file, @option_path, option.type, value.class)
66
68
  end
67
69
 
68
70
  unless option.valid?(value)
69
- raise OptionValidationError.new(@option_path, option.validation)
71
+ raise OptionValidationError.new(@file, @option_path, option.validation)
70
72
  end
71
73
 
72
74
  output[key] = option.transform(value)
@@ -1,28 +1,28 @@
1
1
  module Configru
2
2
  class OptionError < RuntimeError
3
- def initialize(path, message)
4
- super("#{path.join('.')}: #{message}")
3
+ def initialize(file, path, message)
4
+ super("in #{file} at #{path.join('.')}: #{message}")
5
5
  end
6
6
  end
7
7
 
8
8
  class OptionRequiredError < OptionError
9
- def initialize(path)
10
- super(path, 'option required')
9
+ def initialize(file, path)
10
+ super(file, path, 'option required')
11
11
  end
12
12
  end
13
13
 
14
14
  class OptionTypeError < OptionError
15
- def initialize(path, expected, got)
16
- super(path, "expected #{expected}, got #{got}")
15
+ def initialize(file, path, expected, got)
16
+ super(file, path, "expected #{expected}, got #{got}")
17
17
  end
18
18
  end
19
19
 
20
20
  class OptionValidationError < OptionError
21
- def initialize(path, validation = nil)
21
+ def initialize(file, path, validation)
22
22
  if validation.is_a?(Proc)
23
- super(path, "failed validation")
23
+ super(file, path, 'failed validation')
24
24
  else
25
- super(path, "failed validation `#{validation.inspect}`")
25
+ super(file, path, "failed validation `#{validation.inspect}`")
26
26
  end
27
27
  end
28
28
  end
@@ -1,7 +1,7 @@
1
1
  module Configru
2
2
  module OptionMethods
3
3
  def type?(value)
4
- value.is_a?(self.type)
4
+ value.nil? || value.is_a?(self.type)
5
5
  end
6
6
 
7
7
  def valid?(value)
@@ -1,3 +1,3 @@
1
1
  module Configru
2
- VERSION = "3.4.0"
2
+ VERSION = "3.5.0"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -96,6 +96,14 @@ describe Configru::Config do
96
96
  end.to raise_error(Configru::OptionTypeError)
97
97
  end
98
98
 
99
+ it 'treats nil as if it were the right type' do
100
+ c = described_class.new do
101
+ option :string, String
102
+ end
103
+
104
+ c.string.should == nil
105
+ end
106
+
99
107
  it 'validates options against values' do
100
108
  expect do
101
109
  c = described_class.new(example_file :d) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configru
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Curtis McEnroe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: YAML configuration file loader
14
14
  email: