confuse 0.1.3 → 0.1.4
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.
- data/lib/confuse/config.rb +11 -2
- data/lib/confuse/config_item.rb +4 -0
- data/lib/confuse/config_mixin.rb +3 -1
- data/lib/confuse/namespace.rb +13 -3
- data/lib/confuse/version.rb +1 -1
- data/test/test_config_base.rb +24 -0
- metadata +6 -4
data/lib/confuse/config.rb
CHANGED
@@ -12,8 +12,17 @@ module Confuse
|
|
12
12
|
include ConfigMixin
|
13
13
|
extend DSL
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def namespaces
|
16
|
+
@namespaces ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(options = {})
|
20
|
+
load_namespaces(self.class.namespaces.clone)
|
21
|
+
paths = options[:paths] || []
|
22
|
+
load_defaults = begin
|
23
|
+
d = options[:load_defaults]
|
24
|
+
d.nil? ? true : d
|
25
|
+
end
|
17
26
|
if paths.flatten.empty?
|
18
27
|
read_files(self.class.config_path.flatten)
|
19
28
|
else
|
data/lib/confuse/config_item.rb
CHANGED
data/lib/confuse/config_mixin.rb
CHANGED
@@ -12,8 +12,9 @@ module Confuse
|
|
12
12
|
def load_namespaces(new_namespaces)
|
13
13
|
new_namespaces.each do |key, value|
|
14
14
|
existing = namespaces[key]
|
15
|
-
existing ? existing.merge!(value) : namespaces[key] = value
|
15
|
+
existing ? existing.merge!(value) : namespaces[key] = value.clone
|
16
16
|
end
|
17
|
+
@foo = true
|
17
18
|
end
|
18
19
|
|
19
20
|
def read_files(file_paths)
|
@@ -35,6 +36,7 @@ module Confuse
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def []=(key, value)
|
39
|
+
puts "WARNING: changing config after it has been set!"
|
38
40
|
mixin_config!({key => value})
|
39
41
|
end
|
40
42
|
|
data/lib/confuse/namespace.rb
CHANGED
@@ -9,8 +9,8 @@ module Confuse
|
|
9
9
|
|
10
10
|
def initialize(&block)
|
11
11
|
@items = {}
|
12
|
-
@
|
13
|
-
@
|
12
|
+
@supress_warnings_flag = false
|
13
|
+
@strict_flag = false
|
14
14
|
instance_eval(&block)
|
15
15
|
end
|
16
16
|
|
@@ -58,7 +58,17 @@ module Confuse
|
|
58
58
|
def merge!(namespace)
|
59
59
|
@strict_flag = namespace.strict
|
60
60
|
@supress_warnings_flag = namespace.supress_warnings
|
61
|
-
@items.merge! namespace.items
|
61
|
+
@items.merge! namespace.clone.items
|
62
|
+
end
|
63
|
+
|
64
|
+
def clone
|
65
|
+
c = super
|
66
|
+
items = @items.reduce({}) do |m, (k, v)|
|
67
|
+
m[k] = v.clone
|
68
|
+
m
|
69
|
+
end
|
70
|
+
c.instance_variable_set(:"@items", items)
|
71
|
+
c
|
62
72
|
end
|
63
73
|
|
64
74
|
end
|
data/lib/confuse/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'confuse'
|
3
|
+
|
4
|
+
class Foo < Confuse::ConfigBase
|
5
|
+
define :foo do
|
6
|
+
default 'foo'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestConfigBase < MiniTest::Unit::TestCase
|
11
|
+
def test_two_instances_can_exist_with_different_values
|
12
|
+
# instatiate two versions of the config
|
13
|
+
config1 = Foo.new
|
14
|
+
config2 = Foo.new
|
15
|
+
|
16
|
+
# change the values of one of them
|
17
|
+
config1[:foo] = 'bar'
|
18
|
+
|
19
|
+
# assert only one has changed
|
20
|
+
assert_equal 'bar', config1[:foo]
|
21
|
+
assert_equal 'foo', config2[:foo]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
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-
|
18
|
+
date: 2013-10-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: inifile
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/confuse/namespace.rb
|
93
93
|
- lib/confuse/version.rb
|
94
94
|
- test/test_config.rb
|
95
|
+
- test/test_config_base.rb
|
95
96
|
- test/test_namespace.rb
|
96
97
|
homepage: https://github.com/mediasp/confuse
|
97
98
|
licenses:
|
@@ -128,5 +129,6 @@ specification_version: 3
|
|
128
129
|
summary: A DSL for defining configuration options in classes
|
129
130
|
test_files:
|
130
131
|
- test/test_config.rb
|
132
|
+
- test/test_config_base.rb
|
131
133
|
- test/test_namespace.rb
|
132
134
|
has_rdoc:
|