configa 0.0.4 → 0.0.5
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 +15 -0
- data/lib/configa/version.rb +1 -1
- data/lib/configa.rb +8 -3
- data/spec/configa/configa_spec.rb +10 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -159,6 +159,21 @@ staging:
|
|
159
159
|
|
160
160
|
So you can see how for whole staging node we rewrite database adapter, then for each subnode we specify other properties.
|
161
161
|
|
162
|
+
Also you can define default environment:
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
dev = Configa.new(path, env: development)
|
166
|
+
all = Configa.new(path)
|
167
|
+
|
168
|
+
dev.mysql
|
169
|
+
# the same as
|
170
|
+
all.development.mysql
|
171
|
+
|
172
|
+
dev.production.mysql
|
173
|
+
# will raise an error
|
174
|
+
all.production.mysql
|
175
|
+
# will return mysql for production
|
176
|
+
|
162
177
|
## Contributing
|
163
178
|
|
164
179
|
1. Fork it
|
data/lib/configa/version.rb
CHANGED
data/lib/configa.rb
CHANGED
@@ -4,17 +4,20 @@ require "yaml"
|
|
4
4
|
module Configa
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def new(path)
|
8
|
-
MagicContainer.new(path)
|
7
|
+
def new(path, opts={})
|
8
|
+
MagicContainer.new(path, opts)
|
9
9
|
end
|
10
10
|
|
11
11
|
class MagicContainer
|
12
|
-
def initialize(path)
|
12
|
+
def initialize(path, opts={})
|
13
13
|
@base_extname = File.extname(path)
|
14
14
|
@base_env = File.basename(path, @base_extname)
|
15
15
|
@base_dir = File.dirname(path)
|
16
16
|
@yamls = {}
|
17
17
|
@yaml = {}
|
18
|
+
|
19
|
+
@default_env = opts[:env]
|
20
|
+
|
18
21
|
parser
|
19
22
|
end
|
20
23
|
|
@@ -26,7 +29,9 @@ module Configa
|
|
26
29
|
env ||= @base_env
|
27
30
|
env = env.to_s
|
28
31
|
load_yaml(env)
|
32
|
+
load_yaml(@default_env.to_s) if @default_env
|
29
33
|
@yaml = merge_yamls
|
34
|
+
@yaml = @yaml[@default_env.to_s] || {} if @default_env
|
30
35
|
@yaml = magic(@yaml)
|
31
36
|
end
|
32
37
|
|
@@ -76,4 +76,14 @@ describe Configa do
|
|
76
76
|
@config.development.users.tarantool.host.must_equal "212.11.3.1"
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
describe "options" do
|
81
|
+
it "should work with default env" do
|
82
|
+
path = File.expand_path("../../base.yml", __FILE__)
|
83
|
+
@config = Configa.new(path, env: :development)
|
84
|
+
@config.mysql.username.must_equal "root"
|
85
|
+
@config.storage.must_equal "tmp"
|
86
|
+
proc{ @config.production.mysql.username }.must_raise Configa::UnknownEnvironment
|
87
|
+
end
|
88
|
+
end
|
79
89
|
end
|