confuse 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,8 +14,8 @@ module Confuse
14
14
 
15
15
  def initialize(*paths)
16
16
  load_namespaces(self.class.namespaces)
17
- read_files(self.class.config_path)
18
- read_files(paths)
17
+ read_files(self.class.config_path.flatten)
18
+ read_files(paths.flatten)
19
19
  end
20
20
 
21
21
  def config
@@ -7,7 +7,7 @@ module Confuse
7
7
 
8
8
  def initialize(name, &block)
9
9
  @key = name
10
- instance_eval(&block)
10
+ instance_eval(&block) unless block.nil?
11
11
  end
12
12
 
13
13
  def description(description = nil)
@@ -34,6 +34,15 @@ module Confuse
34
34
  ns[rest_of_key, self]
35
35
  end
36
36
 
37
+ def to_hash
38
+ namespaces.reduce({}) do |memo, (name, namespace)|
39
+ namespace.keys.each do |key|
40
+ memo["#{name}_#{key}"] = namespace[key, self]
41
+ end
42
+ memo
43
+ end
44
+ end
45
+
37
46
  # We allow the namespace and the key to be concatenated with an '_', so this
38
47
  # method is to search the possible substrings that could make up the
39
48
  # namespace for a key.
@@ -78,8 +87,9 @@ module Confuse
78
87
 
79
88
  def mixin_config!(config)
80
89
  config.each do |key, value|
81
- namespace = @namespaces[find_namespace(key) || :default]
82
- if value.respond_to? :keys
90
+ namespace_name = find_namespace(key) || :default
91
+ namespace = @namespaces[namespace_name]
92
+ if value.respond_to?(:keys)
83
93
  # if its a hash, set each key in the hash as a config item in the
84
94
  # namespace
85
95
  value.each do |k, v|
@@ -87,7 +97,7 @@ module Confuse
87
97
  end
88
98
  else
89
99
  # otherwise, set it directly in the namespace
90
- namespace[key] = value
100
+ namespace[rest_of_key(key, namespace_name)] = value
91
101
  end
92
102
  end
93
103
  end
@@ -40,6 +40,10 @@ module Confuse
40
40
  item && item.value = value
41
41
  end
42
42
 
43
+ def keys
44
+ @items.keys
45
+ end
46
+
43
47
  def create_new_key(key, value)
44
48
  if @supress_warnings_flag
45
49
  puts "Warning: config includes unknown option '#{key}'"
@@ -1,3 +1,3 @@
1
1
  module Confuse
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
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: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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-03 00:00:00 Z
18
+ date: 2013-10-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: inifile