configa 0.0.5 → 0.0.6
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/README.md +7 -0
- data/lib/configa/version.rb +1 -1
- data/lib/configa.rb +9 -1
- data/spec/configa/configa_spec.rb +6 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -29,8 +29,14 @@ config.development.mongodb.user
|
|
29
29
|
#=> "pedro"
|
30
30
|
config.development.mongodb(:user, :password)
|
31
31
|
#=> ["pedro", "password"]
|
32
|
+
config.development.mongodb(:user, :password, hash: true)
|
33
|
+
#=> { user: "pedro", password: "password"}
|
32
34
|
config.production.root.password
|
33
35
|
#=> Error is raised ;)
|
36
|
+
|
37
|
+
config = Configa.new(config_file_path, env: :development)
|
38
|
+
config.mongodb.user
|
39
|
+
#=> "pedro"
|
34
40
|
```
|
35
41
|
|
36
42
|
## Why anyone needs configa?
|
@@ -173,6 +179,7 @@ dev.production.mysql
|
|
173
179
|
# will raise an error
|
174
180
|
all.production.mysql
|
175
181
|
# will return mysql for production
|
182
|
+
```
|
176
183
|
|
177
184
|
## Contributing
|
178
185
|
|
data/lib/configa/version.rb
CHANGED
data/lib/configa.rb
CHANGED
@@ -77,13 +77,21 @@ module Configa
|
|
77
77
|
def magic(data)
|
78
78
|
data.each do |k,v|
|
79
79
|
data.define_singleton_method(k) do |*args|
|
80
|
-
|
80
|
+
opts = {}
|
81
|
+
opts = args.pop if Hash === args.last
|
82
|
+
hash = opts[:hash]
|
83
|
+
res = if args.any?
|
81
84
|
args.map do |arg|
|
82
85
|
data[k][arg.to_s]
|
83
86
|
end
|
84
87
|
else
|
85
88
|
data[k]
|
86
89
|
end
|
90
|
+
if hash
|
91
|
+
Hash[ [res].flatten.map{ |r| [args.shift, r]} ]
|
92
|
+
else
|
93
|
+
res
|
94
|
+
end
|
87
95
|
end
|
88
96
|
data.define_singleton_method(:method_missing) do |name, *args, &blk|
|
89
97
|
raise Configa::UnknownKey, "Unknown key '#{name}' for current node. Available keys are: '#{data.keys * '\', \''}'. Current node: #{data.inspect}"
|
@@ -85,5 +85,11 @@ describe Configa do
|
|
85
85
|
@config.storage.must_equal "tmp"
|
86
86
|
proc{ @config.production.mysql.username }.must_raise Configa::UnknownEnvironment
|
87
87
|
end
|
88
|
+
|
89
|
+
it "should return result as a hash" do
|
90
|
+
path = File.expand_path("../../config.yml", __FILE__)
|
91
|
+
@config = Configa.new(path)
|
92
|
+
@config.production.mysql(:username, :database, hash: true).must_equal({ username: "admin", database: "mysql_prod" })
|
93
|
+
end
|
88
94
|
end
|
89
95
|
end
|