configue 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -4
- data/configue.gemspec +1 -1
- data/lib/configue/container.rb +27 -7
- data/lib/configue/criteria.rb +29 -0
- data/lib/configue/inner_hash.rb +9 -6
- data/lib/configue/setting.rb +67 -10
- data/lib/configue/yaml_loader.rb +14 -0
- data/lib/configue.rb +1 -1
- data/spec/base_namespace_conf.rb +8 -0
- data/spec/configue/basic_spec.rb +49 -0
- data/spec/configue/namespace_spec.rb +55 -0
- data/spec/multiple_yaml_conf.rb +1 -1
- data/spec/namespace/base/pee/kaa/conf.yml +10 -0
- data/spec/namespace/dev/pee/kaa/conf.yml +7 -0
- data/spec/namespace/test/pee/kaa/conf.yml +7 -0
- data/spec/namespace_conf.rb +7 -0
- data/spec/single_yaml_conf.rb +1 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/support/inner_hash.rb +91 -0
- metadata +20 -4
- data/spec/configue_spec.rb +0 -126
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a6932c57f41d3a8e0face2437eb0ed9c6c9577
|
4
|
+
data.tar.gz: 4efa8934701bd705a9c79030782465f2a8a93813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61a7c799b95237f0278b333a85fb460f17790106940145e22c8a34f3e26fe2a04c5cd62762bac6988a04ec716a06c3da21ed829d5ac747ecb3d8db6afb923674
|
7
|
+
data.tar.gz: d00f683e0554cde0dd4f43ce81f947a2133f96146d7fe8e6061017190feae6ad6aefd649620dd161b4b5b9856b477727d58e1c59730ada7800f205021155a05e
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Configue
|
2
2
|
Configue is a configuration / settings solution that uses YAML files.
|
3
3
|
It is almost a fork of SettingsLogic.
|
4
|
-
Configue can read multiple YAML files and you can use big
|
4
|
+
Configue can read multiple YAML files and you can use big configuration data
|
5
5
|
simply.
|
6
6
|
|
7
7
|
## Installation
|
@@ -9,10 +9,91 @@ simply.
|
|
9
9
|
gem install configue
|
10
10
|
```
|
11
11
|
|
12
|
-
## Usage
|
12
|
+
## Basic Usage
|
13
13
|
### Define your class
|
14
14
|
```ruby
|
15
|
-
class
|
16
|
-
|
15
|
+
class MyConf < Configue::Container
|
16
|
+
config.source_dir "#{File.dirname(__FILE__)}/config"
|
17
17
|
end
|
18
18
|
```
|
19
|
+
|
20
|
+
### Write your settings in YAML file
|
21
|
+
```yaml
|
22
|
+
# config/accounts/admin_users.yml
|
23
|
+
config:
|
24
|
+
accounts:
|
25
|
+
admin_users:
|
26
|
+
- grumpy
|
27
|
+
- sneezy
|
28
|
+
```
|
29
|
+
|
30
|
+
You can make multiple settings files.
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
# config/accounts/test_users.yml
|
34
|
+
config:
|
35
|
+
accounts:
|
36
|
+
test_users:
|
37
|
+
- sleepy
|
38
|
+
- dopey
|
39
|
+
```
|
40
|
+
|
41
|
+
### Access your settings
|
42
|
+
```
|
43
|
+
>> MyConf.config.accounts.admin_users
|
44
|
+
=> ["grumpy", "sneezy"]
|
45
|
+
|
46
|
+
>> MyConf.config.accounts.test_users
|
47
|
+
=> ["sleepy", "dopey"]
|
48
|
+
```
|
49
|
+
|
50
|
+
## Other usage
|
51
|
+
### namespace
|
52
|
+
You can specify `namespace` and `base_namespace`.
|
53
|
+
|
54
|
+
When you write settings as follows:
|
55
|
+
```yaml
|
56
|
+
# config/settings/base.yml
|
57
|
+
base:
|
58
|
+
foo:
|
59
|
+
baa:
|
60
|
+
- a
|
61
|
+
- b
|
62
|
+
- c
|
63
|
+
baz:
|
64
|
+
- one
|
65
|
+
- two
|
66
|
+
- three
|
67
|
+
|
68
|
+
# config/settings/dev.yml
|
69
|
+
dev:
|
70
|
+
foo:
|
71
|
+
baa:
|
72
|
+
- pee
|
73
|
+
- kaa
|
74
|
+
- boo
|
75
|
+
|
76
|
+
# config/settings/test.yml
|
77
|
+
test:
|
78
|
+
foo:
|
79
|
+
baa:
|
80
|
+
- boo
|
81
|
+
- foo
|
82
|
+
- woo
|
83
|
+
```
|
84
|
+
and define a class for the settings
|
85
|
+
```ruby
|
86
|
+
class MyConf < Configue::Container
|
87
|
+
config.source_dir "#{File.dirname(__FILE__)}/config/settings"
|
88
|
+
config.base_namespace :base
|
89
|
+
config.namespace :test
|
90
|
+
end
|
91
|
+
```
|
92
|
+
you can access it in the following manner:
|
93
|
+
```
|
94
|
+
>> MyConf.foo.baa
|
95
|
+
=> ["boo", "foo", "woo"]
|
96
|
+
|
97
|
+
>> MyConf.foo.baz
|
98
|
+
=> ["one", "two", "three"]
|
99
|
+
```
|
data/configue.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
13
13
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
14
|
s.require_paths = ["lib"]
|
15
|
-
s.version = "0.1.
|
15
|
+
s.version = "0.1.1"
|
16
16
|
s.license = "MIT"
|
17
17
|
|
18
18
|
s.add_development_dependency 'rspec'
|
data/lib/configue/container.rb
CHANGED
@@ -1,19 +1,39 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require "forwardable"
|
4
|
+
require "configue/criteria"
|
5
|
+
|
3
6
|
module Configue
|
4
7
|
class Container
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :@node, :keys, :key?, :has_key?, :[]
|
11
|
+
|
12
|
+
def initialize(hash)
|
13
|
+
@node = hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def query(key=nil)
|
17
|
+
q = Criteria.new(@node)
|
18
|
+
q = key.split('.').each.inject(q) {|c, k| c[k] } if key
|
19
|
+
q
|
20
|
+
end
|
21
|
+
|
5
22
|
class << self
|
6
|
-
def
|
23
|
+
def config
|
7
24
|
@setting ||= Setting.new(self)
|
8
25
|
end
|
26
|
+
alias_method :config_setting, :config
|
9
27
|
|
10
|
-
|
11
|
-
|
12
|
-
@setting.
|
28
|
+
private
|
29
|
+
def method_missing(name, *args, &block)
|
30
|
+
@instance ||= new(@setting.load_source)
|
31
|
+
if @instance.key?(name)
|
32
|
+
@instance[name]
|
33
|
+
else
|
34
|
+
@instance.__send__(name, *args, &block)
|
35
|
+
end
|
13
36
|
end
|
14
|
-
|
15
|
-
def key?(key); @setting.hash.key?(key.to_s); end
|
16
|
-
alias_method :has_key?, :key?
|
17
37
|
end
|
18
38
|
end
|
19
39
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Configue
|
4
|
+
class Criteria
|
5
|
+
def initialize(hash, *path)
|
6
|
+
@hash = hash
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
self.class.new(@hash, *@path, key.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
def retrieve
|
15
|
+
@path.each.inject(@hash) do |h, key|
|
16
|
+
return nil unless h.is_a?(Hash) and h.has_key?(key)
|
17
|
+
h[key]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def exist?
|
22
|
+
@path.each.inject(@hash) do |h, key|
|
23
|
+
return false unless h.is_a?(Hash) and h.has_key?(key)
|
24
|
+
h[key]
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/configue/inner_hash.rb
CHANGED
@@ -3,14 +3,17 @@
|
|
3
3
|
module Configue
|
4
4
|
class InnerHash < Hash
|
5
5
|
def initialize(source_hash=nil)
|
6
|
-
if source_hash
|
7
|
-
|
6
|
+
deep_merge!(source_hash) if source_hash
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def deep_merge!(other)
|
10
|
+
deep_update(other)
|
11
|
+
|
12
|
+
sig = class << self; self; end
|
13
|
+
other.keys.each do |k|
|
14
|
+
sig.__send__(:define_method, k, ->{ self[k] })
|
13
15
|
end
|
16
|
+
self
|
14
17
|
end
|
15
18
|
|
16
19
|
def fetch(key, *args); super(key.to_s, *args); end
|
data/lib/configue/setting.rb
CHANGED
@@ -1,25 +1,82 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require "configue/yaml_loader"
|
4
|
+
|
3
5
|
module Configue
|
4
6
|
class Setting
|
5
7
|
def initialize(owner_class)
|
6
8
|
@owner_class = owner_class
|
9
|
+
@loader = YamlLoader.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def base_namespace(key=nil)
|
13
|
+
@base_namespace = key if key
|
14
|
+
@base_namespace
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_namespace=(key)
|
18
|
+
base_namespace(key)
|
7
19
|
end
|
8
20
|
|
9
|
-
def
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
def namespace(key=nil)
|
22
|
+
@namespace = key if key
|
23
|
+
@namespace
|
24
|
+
end
|
25
|
+
|
26
|
+
def namespace=(key)
|
27
|
+
namespace(key)
|
28
|
+
end
|
29
|
+
|
30
|
+
def source_dir(*dirs)
|
31
|
+
@source_dirs ||= []
|
32
|
+
@source_dirs += dirs unless dirs.empty?
|
33
|
+
@source_dirs
|
34
|
+
end
|
14
35
|
|
15
|
-
|
16
|
-
|
17
|
-
|
36
|
+
def source_dir=(dir)
|
37
|
+
if dir.is_a?(Array)
|
38
|
+
source_dir(*dir)
|
39
|
+
else
|
40
|
+
source_dir(dir)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def load_source
|
45
|
+
hash = load_sources
|
46
|
+
|
47
|
+
space = namespace.to_s
|
48
|
+
unless space.empty?
|
49
|
+
base = base_namespace.to_s
|
50
|
+
result = InnerHash.new
|
51
|
+
result.deep_merge!(hash[base]) if base_namespace
|
52
|
+
result.deep_merge!(hash[space]) if hash[space]
|
53
|
+
hash = result
|
54
|
+
end
|
55
|
+
hash
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def load_sources
|
60
|
+
@source_dirs.each.inject(InnerHash.new) do |root, dir|
|
61
|
+
Dir.glob("#{dir}/**/*.#{@loader.extention}") do |path|
|
62
|
+
source = @loader.load(path)
|
63
|
+
if namespace and source[namespace.to_s]
|
64
|
+
namespaced_hash(root, source)
|
65
|
+
else
|
66
|
+
root.deep_merge!(source)
|
67
|
+
end
|
18
68
|
end
|
69
|
+
root
|
19
70
|
end
|
20
|
-
@hash
|
21
71
|
end
|
22
72
|
|
23
|
-
|
73
|
+
def namespaced_hash(root, hash)
|
74
|
+
base = base_namespace.to_s
|
75
|
+
space = namespace.to_s
|
76
|
+
|
77
|
+
root.deep_merge!(base => hash[base]) if ! base.empty? and hash[base]
|
78
|
+
root.deep_merge!(space => hash[space])
|
79
|
+
root
|
80
|
+
end
|
24
81
|
end
|
25
82
|
end
|
data/lib/configue.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "Configue::Container" do
|
5
|
+
context "when reading a single yaml file" do
|
6
|
+
require "#{File.dirname(__FILE__)}/../single_yaml_conf"
|
7
|
+
|
8
|
+
context "1st level" do
|
9
|
+
it_should_behave_like "an InnerHash instance",
|
10
|
+
SingleYamlConf,
|
11
|
+
{"foo" => ["baa"], "pee" => ["kaa0", "kaa1"]}
|
12
|
+
end
|
13
|
+
|
14
|
+
context "2nd level" do
|
15
|
+
it_should_behave_like "an InnerHash instance",
|
16
|
+
SingleYamlConf["foo"],
|
17
|
+
{"baa" => ["baz0", "baz1"]}
|
18
|
+
it_should_behave_like "an InnerHash instance",
|
19
|
+
SingleYamlConf["pee"],
|
20
|
+
{"kaa0" => ["boo"], "kaa1" => ["boo"]}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when reading multiple yaml files" do
|
25
|
+
require "#{File.dirname(__FILE__)}/../multiple_yaml_conf"
|
26
|
+
|
27
|
+
context "1st level" do
|
28
|
+
it_should_behave_like "an InnerHash instance",
|
29
|
+
MultipleYamlConf,
|
30
|
+
{"foo" => ["baa", "bar", "pee"]}
|
31
|
+
end
|
32
|
+
|
33
|
+
context "2nd level" do
|
34
|
+
it_should_behave_like "an InnerHash instance",
|
35
|
+
MultipleYamlConf["foo"],
|
36
|
+
{"baa" => ["baz"], "bar" => ["ding", "tick"], "pee" => ["kaa", "boo"]}
|
37
|
+
end
|
38
|
+
|
39
|
+
context "3rd level" do
|
40
|
+
it_should_behave_like "an InnerHash instance",
|
41
|
+
MultipleYamlConf["foo"]["baa"], {"baz" => nil}
|
42
|
+
it_should_behave_like "an InnerHash instance",
|
43
|
+
MultipleYamlConf["foo"]["pee"], {"kaa" => nil, "boo" => nil}
|
44
|
+
it_should_behave_like "an InnerHash instance",
|
45
|
+
MultipleYamlConf["foo"]["bar"],
|
46
|
+
{"ding" => ["dong", "dang"], "tick" => ["tack", "toe"]}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path("../../spec_helper", __FILE__)
|
3
|
+
|
4
|
+
describe "Configue::Container" do
|
5
|
+
context "when specifing 'namespace'" do
|
6
|
+
require "#{File.dirname(__FILE__)}/../namespace_conf"
|
7
|
+
|
8
|
+
context "1st level" do
|
9
|
+
it_should_behave_like "an InnerHash instance",
|
10
|
+
NamespaceConf,
|
11
|
+
{"pee" => ["kaa"]}
|
12
|
+
end
|
13
|
+
|
14
|
+
context "2nd level" do
|
15
|
+
it_should_behave_like "an InnerHash instance",
|
16
|
+
NamespaceConf["pee"],
|
17
|
+
{"kaa" => ["boo"]}
|
18
|
+
end
|
19
|
+
|
20
|
+
context "3rd level" do
|
21
|
+
it_should_behave_like "an InnerHash instance",
|
22
|
+
NamespaceConf["pee"]["kaa"],
|
23
|
+
{"boo" => ["foo", "baa", "baz"]}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when specifing 'namespace' and 'base_namespace'" do
|
28
|
+
require "#{File.dirname(__FILE__)}/../base_namespace_conf"
|
29
|
+
|
30
|
+
context "1st level" do
|
31
|
+
it_should_behave_like "an InnerHash instance",
|
32
|
+
BaseNamespaceConf,
|
33
|
+
{"pee" => ["kaa"]}
|
34
|
+
end
|
35
|
+
|
36
|
+
context "2nd level" do
|
37
|
+
it_should_behave_like "an InnerHash instance",
|
38
|
+
BaseNamespaceConf["pee"],
|
39
|
+
{"kaa" => ["boo"]}
|
40
|
+
end
|
41
|
+
|
42
|
+
context "3rd level" do
|
43
|
+
it_should_behave_like "an InnerHash instance",
|
44
|
+
BaseNamespaceConf["pee"]["kaa"],
|
45
|
+
{"boo" => ["foo", "baa", "baz", "boo", "woo", "poo"]}
|
46
|
+
|
47
|
+
it "returns values defined in namespaced hash" do
|
48
|
+
root = BaseNamespaceConf.query[:pee][:kaa][:boo]
|
49
|
+
expect(root[:foo].retrieve).to eq "one"
|
50
|
+
expect(root[:baa].retrieve).to eq "two"
|
51
|
+
expect(root[:baz].retrieve).to eq "three"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/multiple_yaml_conf.rb
CHANGED
data/spec/single_yaml_conf.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,91 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
shared_examples_for "an InnerHash instance" do |object, hash|
|
4
|
+
describe ".has_key?" do
|
5
|
+
context "when specifing the existing key names" do
|
6
|
+
it "returns true" do
|
7
|
+
hash.keys.each do |key|
|
8
|
+
expect(object).to have_key(key)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when specifing the non-existing key names" do
|
14
|
+
it "returns false" do
|
15
|
+
hash.keys.each do |key|
|
16
|
+
expect(object).not_to have_key(key.reverse)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when specifing the existing key names in symbol" do
|
22
|
+
it "returns true" do
|
23
|
+
hash.keys.each do |key|
|
24
|
+
expect(object).to have_key(key.to_sym)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when specifing the non-existing key names in symbol" do
|
30
|
+
it "returns false" do
|
31
|
+
hash.keys.each do |key|
|
32
|
+
expect(object).not_to have_key(key.reverse.to_sym)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe ".[]" do
|
39
|
+
context "when specifing the existing key names" do
|
40
|
+
it "returns a Hash value" do
|
41
|
+
hash.each do |key, value|
|
42
|
+
expect(object[key]).to be_a(Hash) if value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "the Hash value" do
|
47
|
+
it "has keys described in the setting(s)" do
|
48
|
+
hash.each do |key, value|
|
49
|
+
expect(object[key].keys).to match_array(value) if value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when specifing the existing key names in symbol" do
|
56
|
+
it "returns a Hash value" do
|
57
|
+
hash.each do |key, value|
|
58
|
+
expect(object[key.to_sym]).to be_a(Hash) if value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "the Hash value" do
|
63
|
+
it "has keys described in the setting(s)" do
|
64
|
+
hash.each do |key, value|
|
65
|
+
expect(object[key.to_sym].keys).to match_array(value) if value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe ".(key_name)" do
|
73
|
+
context "when call methods which names are existing in the setting(s)" do
|
74
|
+
it "returns a Hash value" do
|
75
|
+
hash.each do |key, value|
|
76
|
+
expect(object.__send__(key)).to be_a(Hash) if value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "the Hash value" do
|
81
|
+
it "has keys described in the setting(s)" do
|
82
|
+
hash.each do |key, value|
|
83
|
+
next unless value
|
84
|
+
actual = object.__send__(key)
|
85
|
+
expect(actual.keys).to match_array(value)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hosim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -37,17 +37,26 @@ files:
|
|
37
37
|
- configue.gemspec
|
38
38
|
- lib/configue.rb
|
39
39
|
- lib/configue/container.rb
|
40
|
+
- lib/configue/criteria.rb
|
40
41
|
- lib/configue/inner_hash.rb
|
41
42
|
- lib/configue/setting.rb
|
42
|
-
-
|
43
|
+
- lib/configue/yaml_loader.rb
|
44
|
+
- spec/base_namespace_conf.rb
|
45
|
+
- spec/configue/basic_spec.rb
|
46
|
+
- spec/configue/namespace_spec.rb
|
43
47
|
- spec/multiple_yaml/foo/baa.yml
|
44
48
|
- spec/multiple_yaml/foo/bar/ding.yml
|
45
49
|
- spec/multiple_yaml/foo/bar/tick.yml
|
46
50
|
- spec/multiple_yaml/foo/pee.yml
|
47
51
|
- spec/multiple_yaml_conf.rb
|
52
|
+
- spec/namespace/base/pee/kaa/conf.yml
|
53
|
+
- spec/namespace/dev/pee/kaa/conf.yml
|
54
|
+
- spec/namespace/test/pee/kaa/conf.yml
|
55
|
+
- spec/namespace_conf.rb
|
48
56
|
- spec/single_yaml/conf.yml
|
49
57
|
- spec/single_yaml_conf.rb
|
50
58
|
- spec/spec_helper.rb
|
59
|
+
- spec/support/inner_hash.rb
|
51
60
|
homepage: https://github.com/hosim/configue
|
52
61
|
licenses:
|
53
62
|
- MIT
|
@@ -73,12 +82,19 @@ signing_key:
|
|
73
82
|
specification_version: 4
|
74
83
|
summary: A simple configuration solution
|
75
84
|
test_files:
|
76
|
-
- spec/
|
85
|
+
- spec/base_namespace_conf.rb
|
86
|
+
- spec/configue/basic_spec.rb
|
87
|
+
- spec/configue/namespace_spec.rb
|
77
88
|
- spec/multiple_yaml/foo/baa.yml
|
78
89
|
- spec/multiple_yaml/foo/bar/ding.yml
|
79
90
|
- spec/multiple_yaml/foo/bar/tick.yml
|
80
91
|
- spec/multiple_yaml/foo/pee.yml
|
81
92
|
- spec/multiple_yaml_conf.rb
|
93
|
+
- spec/namespace/base/pee/kaa/conf.yml
|
94
|
+
- spec/namespace/dev/pee/kaa/conf.yml
|
95
|
+
- spec/namespace/test/pee/kaa/conf.yml
|
96
|
+
- spec/namespace_conf.rb
|
82
97
|
- spec/single_yaml/conf.yml
|
83
98
|
- spec/single_yaml_conf.rb
|
84
99
|
- spec/spec_helper.rb
|
100
|
+
- spec/support/inner_hash.rb
|
data/spec/configue_spec.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
3
|
-
|
4
|
-
describe "Configue::Container" do
|
5
|
-
context "when reading a single yaml file" do
|
6
|
-
require "#{File.dirname(__FILE__)}/single_yaml_conf"
|
7
|
-
|
8
|
-
describe ".[]" do
|
9
|
-
context "when specifing the root keys in the yaml" do
|
10
|
-
it "returns a Hash value" do
|
11
|
-
expect(SingleYamlConf["foo"]).to be_a(Hash)
|
12
|
-
expect(SingleYamlConf["pee"]).to be_a(Hash)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "the Hash value (2nd level)" do
|
16
|
-
subject { SingleYamlConf["foo"] }
|
17
|
-
|
18
|
-
it "has keys described in the yaml" do
|
19
|
-
expect(subject).to have_key("baa")
|
20
|
-
expect(subject.keys.size).to be 1
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "the Hash value (3rd level)" do
|
24
|
-
subject { SingleYamlConf["foo"]["baa"] }
|
25
|
-
|
26
|
-
it "has keys described in the yaml" do
|
27
|
-
expect(subject).to have_key("baz0")
|
28
|
-
expect(subject).to have_key("baz1")
|
29
|
-
expect(subject.keys.size).to be 2
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when specifing the existing root key in symbol" do
|
36
|
-
it "returns a Hash value" do
|
37
|
-
expect(SingleYamlConf[:foo]).to be_a(Hash)
|
38
|
-
expect(SingleYamlConf[:pee]).to be_a(Hash)
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "the Hash value" do
|
42
|
-
subject { SingleYamlConf[:foo] }
|
43
|
-
|
44
|
-
it "has a key described in the yaml" do
|
45
|
-
expect(subject).to have_key(:baa)
|
46
|
-
expect(subject.keys.size).to be 1
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "the Hash value (3rd level)" do
|
50
|
-
subject { SingleYamlConf[:foo][:baa] }
|
51
|
-
|
52
|
-
it "has keys described in the yaml" do
|
53
|
-
expect(subject).to have_key(:baz0)
|
54
|
-
expect(subject).to have_key(:baz1)
|
55
|
-
expect(subject.keys.size).to be 2
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe ".(key)" do
|
63
|
-
context "when call a method which name is the root key in the yaml" do
|
64
|
-
it "returns a Hash value" do
|
65
|
-
expect(SingleYamlConf.foo).to be_a(Hash)
|
66
|
-
expect(SingleYamlConf.pee).to be_a(Hash)
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "the Hash value (2nd level)" do
|
70
|
-
subject { SingleYamlConf.foo }
|
71
|
-
|
72
|
-
it "has methods which names are name of keys described in the yaml" do
|
73
|
-
expect(subject).to respond_to(:baa)
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "the Hash value (3rd level)" do
|
77
|
-
subject { SingleYamlConf.foo.baa }
|
78
|
-
|
79
|
-
it "has methods which names are name of keys described in the yaml" do
|
80
|
-
expect(subject).to respond_to(:baz0)
|
81
|
-
expect(subject).to respond_to(:baz1)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "when reading multiple yaml files" do
|
90
|
-
require "#{File.dirname(__FILE__)}/multiple_yaml_conf"
|
91
|
-
|
92
|
-
describe ".[]" do
|
93
|
-
context "when specifing the root keys in the yaml" do
|
94
|
-
it "return a Hash value" do
|
95
|
-
expect(MultipleYamlConf["foo"]).to be_a(Hash)
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "the Hash value (2nd level)" do
|
99
|
-
subject { MultipleYamlConf["foo"] }
|
100
|
-
|
101
|
-
it "has keys described in the yaml files" do
|
102
|
-
expect(subject.keys).to match_array(["baa", "bar", "pee"])
|
103
|
-
end
|
104
|
-
|
105
|
-
describe "the Hash value (3rd level)" do
|
106
|
-
subject do
|
107
|
-
["baa", "bar", "pee"].map {|k|
|
108
|
-
MultipleYamlConf["foo"][k]
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
it "has keys described in the yaml files" do
|
113
|
-
expect(subject[0]).to have_key("baz")
|
114
|
-
|
115
|
-
expect(subject[1]).to have_key("ding")
|
116
|
-
expect(subject[1]).to have_key("tick")
|
117
|
-
|
118
|
-
expect(subject[2]).to have_key("kaa")
|
119
|
-
expect(subject[2]).to have_key("boo")
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|