figaro 0.3.0 → 0.4.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.
- data/.travis.yml +0 -2
- data/README.md +12 -0
- data/features/rails.feature +42 -8
- data/features/support/env.rb +0 -2
- data/figaro.gemspec +1 -1
- data/lib/figaro.rb +14 -0
- metadata +1 -1
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,18 @@ Pusher.key = ENV["PUSHER_KEY"]
|
|
44
44
|
Pusher.secret = ENV["PUSHER_SECRET"]
|
45
45
|
```
|
46
46
|
|
47
|
+
If your app requires Rails-environment-specific configuration, you can also namespace your configuration under a key for `Rails.environment`. For instance:
|
48
|
+
|
49
|
+
```yaml
|
50
|
+
HELLO: world
|
51
|
+
development:
|
52
|
+
HELLO: developers
|
53
|
+
production:
|
54
|
+
HELLO: users
|
55
|
+
```
|
56
|
+
|
57
|
+
In this case, `ENV["HELLO"]` will produce `"developers"` in development, `"users"` in production and `"world"` otherwise.
|
58
|
+
|
47
59
|
## How does it work with Heroku?
|
48
60
|
|
49
61
|
Heroku's beautifully simple application configuration was the [inspiration](http://laserlemon.com/blog/2011/03/08/heroku-friendly-application-configuration/) for Figaro.
|
data/features/rails.feature
CHANGED
@@ -15,36 +15,70 @@ Feature: Rails
|
|
15
15
|
Then the output should be "Hello!"
|
16
16
|
|
17
17
|
Scenario: Has application.yml without requested key
|
18
|
-
|
18
|
+
Given I create "config/application.yml" with:
|
19
19
|
"""
|
20
20
|
GOODBYE: Ruby Tuesday
|
21
21
|
"""
|
22
|
-
|
22
|
+
When I run "rake hello"
|
23
23
|
Then the output should be "Hello!"
|
24
24
|
|
25
25
|
Scenario: Has blank application.yml
|
26
|
-
|
26
|
+
Given I create "config/application.yml" with:
|
27
27
|
"""
|
28
28
|
"""
|
29
|
-
|
29
|
+
When I run "rake hello"
|
30
30
|
Then the output should be "Hello!"
|
31
31
|
|
32
32
|
Scenario: Has commented application.yml
|
33
|
-
|
33
|
+
Given I create "config/application.yml" with:
|
34
34
|
"""
|
35
35
|
# Comment
|
36
36
|
"""
|
37
|
-
|
37
|
+
When I run "rake hello"
|
38
38
|
Then the output should be "Hello!"
|
39
39
|
|
40
40
|
Scenario: Has application.yml with requested key
|
41
|
-
|
41
|
+
Given I create "config/application.yml" with:
|
42
42
|
"""
|
43
43
|
HELLO: world
|
44
44
|
"""
|
45
|
-
|
45
|
+
When I run "rake hello"
|
46
46
|
Then the output should be "Hello, world!"
|
47
47
|
|
48
|
+
Scenario: Has application.yml with a RAILS_ENV
|
49
|
+
Given I create "config/application.yml" with:
|
50
|
+
"""
|
51
|
+
HELLO: world
|
52
|
+
development:
|
53
|
+
HELLO: developers
|
54
|
+
"""
|
55
|
+
When I run "rake hello RAILS_ENV=development"
|
56
|
+
Then the output should be "Hello, developers!"
|
57
|
+
|
58
|
+
Scenario: Has application.yml without a RAILS_ENV, but has env variables set
|
59
|
+
Given I create "config/application.yml" with:
|
60
|
+
"""
|
61
|
+
HELLO: world
|
62
|
+
development:
|
63
|
+
HELLO: developers
|
64
|
+
"""
|
65
|
+
When I run "rake hello"
|
66
|
+
Then the output should be "Hello, world!"
|
67
|
+
|
68
|
+
Scenario: Has application.yml with a RAILS_ENV, with multiple envs configured.
|
69
|
+
Given I create "config/application.yml" with:
|
70
|
+
"""
|
71
|
+
HELLO: world
|
72
|
+
development:
|
73
|
+
HELLO: developers
|
74
|
+
production:
|
75
|
+
HELLO: users
|
76
|
+
"""
|
77
|
+
When I run "rake hello RAILS_ENV=development"
|
78
|
+
Then the output should be "Hello, developers!"
|
79
|
+
When I run "rake hello RAILS_ENV=production"
|
80
|
+
Then the output should be "Hello, users!"
|
81
|
+
|
48
82
|
Scenario: Generator creates and ignores application.yml file
|
49
83
|
When I run "rails generate figaro:install"
|
50
84
|
Then "config/application.yml" should exist
|
data/features/support/env.rb
CHANGED
data/figaro.gemspec
CHANGED
data/lib/figaro.rb
CHANGED
@@ -4,6 +4,10 @@ module Figaro
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def env
|
7
|
+
flatten(raw).merge(raw.fetch(environment, {}))
|
8
|
+
end
|
9
|
+
|
10
|
+
def raw
|
7
11
|
yaml && YAML.load(yaml) || {}
|
8
12
|
end
|
9
13
|
|
@@ -14,4 +18,14 @@ module Figaro
|
|
14
18
|
def path
|
15
19
|
Rails.root.join("config/application.yml")
|
16
20
|
end
|
21
|
+
|
22
|
+
def environment
|
23
|
+
ENV["RAILS_ENV"] || ENV["RACK_ENV"]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def flatten(hash)
|
29
|
+
hash.reject{|_,v| Hash === v }
|
30
|
+
end
|
17
31
|
end
|