confuse 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,13 +20,13 @@ module Confuse
20
20
  @type
21
21
  end
22
22
 
23
- def default(default = nil)
24
- @default = default unless default.nil?
25
- @default
23
+ def default(value = nil, &block)
24
+ @default_value = value unless value.nil?
25
+ @default_value = block unless block.nil?
26
26
  end
27
27
 
28
28
  def value
29
- @value || @default
29
+ @value || @default_value
30
30
  end
31
31
  end
32
32
  end
@@ -31,7 +31,7 @@ module Confuse
31
31
  rest_of_key = rest_of_key(key, namespace)
32
32
  ns = namespaces[namespace]
33
33
  return ns unless rest_of_key
34
- ns[rest_of_key]
34
+ ns[rest_of_key, self]
35
35
  end
36
36
 
37
37
  # We allow the namespace and the key to be concatenated with an '_', so this
@@ -1,4 +1,4 @@
1
- require 'configuration'
1
+ require 'confuse'
2
2
 
3
3
  # Monkey patch class to easily allow a class to be configurable.
4
4
  class Class
data/lib/confuse/dsl.rb CHANGED
@@ -47,7 +47,7 @@ module Confuse
47
47
  end
48
48
  else
49
49
  define_method(name) do
50
- config[namespace][name]
50
+ config[namespace][name, config]
51
51
  end
52
52
  end
53
53
  end
@@ -26,8 +26,13 @@ module Confuse
26
26
  @strict_flag = true
27
27
  end
28
28
 
29
- def [](key)
30
- (i = get_item(key)) && i.value
29
+ def [](key, config = nil)
30
+ value = (i = get_item(key)) && i.value
31
+ if value.respond_to?(:call) && !config.nil?
32
+ value.call(config)
33
+ else
34
+ value
35
+ end
31
36
  end
32
37
 
33
38
  def []=(key, value)
@@ -39,7 +44,7 @@ module Confuse
39
44
  if @supress_warnings_flag
40
45
  puts "Warning: config includes unknown option '#{key}'"
41
46
  end
42
- @items[key] = ConfigItem.new(key, &(Proc.new {})) unless @strict_flag
47
+ @items[key] = ConfigItem.new(key, &nil) unless @strict_flag
43
48
  end
44
49
 
45
50
  def get_item(key)
@@ -1,3 +1,3 @@
1
1
  module Confuse
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confuse
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Chipchase
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-10-01 00:00:00 Z
18
+ date: 2013-10-02 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: inifile