configue 0.1.0
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.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/README.md +18 -0
- data/Rakefile +8 -0
- data/configue.gemspec +19 -0
- data/lib/configue/container.rb +19 -0
- data/lib/configue/inner_hash.rb +50 -0
- data/lib/configue/setting.rb +25 -0
- data/lib/configue.rb +5 -0
- data/spec/configue_spec.rb +126 -0
- data/spec/multiple_yaml/foo/baa.yml +3 -0
- data/spec/multiple_yaml/foo/bar/ding.yml +5 -0
- data/spec/multiple_yaml/foo/bar/tick.yml +5 -0
- data/spec/multiple_yaml/foo/pee.yml +4 -0
- data/spec/multiple_yaml_conf.rb +5 -0
- data/spec/single_yaml/conf.yml +17 -0
- data/spec/single_yaml_conf.rb +5 -0
- data/spec/spec_helper.rb +6 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86dd4fa550a529d4050ba85051d25b434c657dff
|
4
|
+
data.tar.gz: 54fd3e9d60f20f95863df2431020dcdce4252222
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2c90a3fd197642ee4fb7a92bfc307aa69b5a903135bb88a24e2ac9d487c0d3527367a5f840f12ff1774e4c60ab2e498bb710fca84a3ef81944ed53a97f09221
|
7
|
+
data.tar.gz: 7bb08f81f3621dab09766199e4a00aa1b35d92792877eaa0dad6da686e7c2b74af9131aa6235fe8acdce0863bd5c913d3644c9f5b596cba7b7fb2a6b01dd358f
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Configue
|
2
|
+
Configue is a configuration / settings solution that uses YAML files.
|
3
|
+
It is almost a fork of SettingsLogic.
|
4
|
+
Configue can read multiple YAML files and you can use big configration data
|
5
|
+
simply.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
```
|
9
|
+
gem install configue
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
### Define your class
|
14
|
+
```ruby
|
15
|
+
class Conf < Configue::Container
|
16
|
+
config_setting.source_dir "#{File.dirname(__FILE__)}/config"
|
17
|
+
end
|
18
|
+
```
|
data/Rakefile
ADDED
data/configue.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "configue"
|
6
|
+
s.authors = ["hosim"]
|
7
|
+
s.email = ["github.hosim@gmail.com"]
|
8
|
+
s.description = "Configue is a simple configuration solution."
|
9
|
+
s.summary = "A simple configuration solution"
|
10
|
+
s.homepage = "https://github.com/hosim/configue"
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map {|f| File.basename(f) }
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
s.version = "0.1.0"
|
16
|
+
s.license = "MIT"
|
17
|
+
|
18
|
+
s.add_development_dependency 'rspec'
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Configue
|
4
|
+
class Container
|
5
|
+
class << self
|
6
|
+
def config_setting
|
7
|
+
@setting ||= Setting.new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](*args)
|
11
|
+
key = args[0].to_s
|
12
|
+
@setting.hash[key]
|
13
|
+
end
|
14
|
+
|
15
|
+
def key?(key); @setting.hash.key?(key.to_s); end
|
16
|
+
alias_method :has_key?, :key?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Configue
|
4
|
+
class InnerHash < Hash
|
5
|
+
def initialize(source_hash=nil)
|
6
|
+
if source_hash
|
7
|
+
deep_update(source_hash)
|
8
|
+
|
9
|
+
sig = class << self; self; end
|
10
|
+
source_hash.keys.each do |k|
|
11
|
+
sig.__send__(:define_method, k, ->{ self[k] })
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch(key, *args); super(key.to_s, *args); end
|
17
|
+
def delete(key); super(key.to_s); end
|
18
|
+
def key?(key); super(key.to_s); end
|
19
|
+
alias_method :has_key?, :key?
|
20
|
+
|
21
|
+
alias_method :_get_value, :[]
|
22
|
+
alias_method :_set_value, :[]=
|
23
|
+
private :_get_value
|
24
|
+
private :_set_value
|
25
|
+
|
26
|
+
def [](key)
|
27
|
+
value = _get_value(key.to_s)
|
28
|
+
value = self.class.new(value) if value.is_a? Hash
|
29
|
+
yield value if block_given?
|
30
|
+
value
|
31
|
+
end
|
32
|
+
|
33
|
+
def []=(key, value)
|
34
|
+
v = value
|
35
|
+
v = self.class.new(v) if v.is_a? Hash
|
36
|
+
_set_value(key.to_s, v)
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def deep_update(other_hash, &b)
|
41
|
+
other_hash.each do |k, v|
|
42
|
+
if v.is_a?(Hash)
|
43
|
+
v = self.key?(k) ? self[k].deep_update(v) : self.class.new(v)
|
44
|
+
end
|
45
|
+
self[k] = v
|
46
|
+
end
|
47
|
+
self
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Configue
|
4
|
+
class Setting
|
5
|
+
def initialize(owner_class)
|
6
|
+
@owner_class = owner_class
|
7
|
+
end
|
8
|
+
|
9
|
+
def source_dir(dir)
|
10
|
+
@hash ||= InnerHash.new
|
11
|
+
Dir.glob("#{dir}/**/*.yml") do |filenm|
|
12
|
+
h = YAML.load_file(filenm)
|
13
|
+
@hash.__send__(:deep_update, h)
|
14
|
+
|
15
|
+
sig = class << @owner_class; self; end
|
16
|
+
h.keys.each do |k|
|
17
|
+
sig.__send__(:define_method, k, ->{ self[k] })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@hash
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :hash
|
24
|
+
end
|
25
|
+
end
|
data/lib/configue.rb
ADDED
@@ -0,0 +1,126 @@
|
|
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
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: configue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hosim
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Configue is a simple configuration solution.
|
28
|
+
email:
|
29
|
+
- github.hosim@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- Gemfile
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- configue.gemspec
|
38
|
+
- lib/configue.rb
|
39
|
+
- lib/configue/container.rb
|
40
|
+
- lib/configue/inner_hash.rb
|
41
|
+
- lib/configue/setting.rb
|
42
|
+
- spec/configue_spec.rb
|
43
|
+
- spec/multiple_yaml/foo/baa.yml
|
44
|
+
- spec/multiple_yaml/foo/bar/ding.yml
|
45
|
+
- spec/multiple_yaml/foo/bar/tick.yml
|
46
|
+
- spec/multiple_yaml/foo/pee.yml
|
47
|
+
- spec/multiple_yaml_conf.rb
|
48
|
+
- spec/single_yaml/conf.yml
|
49
|
+
- spec/single_yaml_conf.rb
|
50
|
+
- spec/spec_helper.rb
|
51
|
+
homepage: https://github.com/hosim/configue
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A simple configuration solution
|
75
|
+
test_files:
|
76
|
+
- spec/configue_spec.rb
|
77
|
+
- spec/multiple_yaml/foo/baa.yml
|
78
|
+
- spec/multiple_yaml/foo/bar/ding.yml
|
79
|
+
- spec/multiple_yaml/foo/bar/tick.yml
|
80
|
+
- spec/multiple_yaml/foo/pee.yml
|
81
|
+
- spec/multiple_yaml_conf.rb
|
82
|
+
- spec/single_yaml/conf.yml
|
83
|
+
- spec/single_yaml_conf.rb
|
84
|
+
- spec/spec_helper.rb
|