config_yml 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/configuration/version.rb +1 -1
- data/lib/configuration.rb +8 -2
- data/spec/lib/configuration_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50141adecf0852edc755f184600240f10c219f05
|
4
|
+
data.tar.gz: 6d2a3cec733919f63b6f44df8bace847dab31197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed1e0848acccc1dbd458efe227ea3c1fc2062cf26afa877e5261c3cc4d7fd1ccdba1141545829b5b3954023a9507a3cf225cdcb05adaea6908549c506444ec0
|
7
|
+
data.tar.gz: a7b6155edb94d7ae02803ad02b949e30e6b1bf50c69270ce3317509a894c45ab8cddeebc401f4fbddd26a6499dfe3ad3d7e5ed13ffb958135756a2cb16dad2e6
|
data/Gemfile.lock
CHANGED
data/lib/configuration.rb
CHANGED
@@ -20,14 +20,16 @@ module Configuration
|
|
20
20
|
# Configuration.database # => { :host => "localhost", :username => "root" }
|
21
21
|
#
|
22
22
|
class << self
|
23
|
+
attr_accessor :root
|
24
|
+
|
23
25
|
def method_missing(method, *args)
|
24
|
-
if file = files.select { |f| f ==
|
26
|
+
if file = files.select { |f| f == files_path(method.to_s) }[0]
|
25
27
|
hash[method] ||= load_yml(file)
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
31
|
def files
|
30
|
-
@files ||= Dir.glob(
|
32
|
+
@files ||= Dir.glob(files_path)
|
31
33
|
end
|
32
34
|
|
33
35
|
def env
|
@@ -36,6 +38,10 @@ module Configuration
|
|
36
38
|
|
37
39
|
private
|
38
40
|
|
41
|
+
def files_path(filename="*")
|
42
|
+
root.nil? ? "config/#{filename}.yml" : File.join(root, "config/#{filename}.yml")
|
43
|
+
end
|
44
|
+
|
39
45
|
def hash
|
40
46
|
@hash ||= {}
|
41
47
|
end
|
@@ -103,6 +103,28 @@ describe Configuration do
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
|
+
context "when the configuration root is specified" do
|
107
|
+
let(:file_a) do
|
108
|
+
{ "key" => "value_test" }
|
109
|
+
end
|
110
|
+
let(:file_b) { double }
|
111
|
+
let(:files) { ["foo/bar/config/file_a.yml", "foo/bar/config/file_b.yml"] }
|
112
|
+
|
113
|
+
before do
|
114
|
+
subject.instance_variable_set(:@files, nil)
|
115
|
+
Configuration.root = "foo/bar"
|
116
|
+
end
|
117
|
+
after { Configuration.root = nil }
|
118
|
+
|
119
|
+
it "has a root set" do
|
120
|
+
Configuration.root.should be_eql "foo/bar"
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns value" do
|
124
|
+
subject.file_a[:key].should be_eql "value_test"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
106
128
|
context "when configuration file doesn't exist" do
|
107
129
|
let(:file_a) { double }
|
108
130
|
let(:file_b) { double }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_yml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitor Kiyoshi Arimitsu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A very simple way of configure your ruby applications through yaml files.
|
14
14
|
email: to@vitork.com
|