figaro 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,5 +9,3 @@ rvm:
9
9
  - 1.9.2
10
10
  - 1.9.3
11
11
  - ruby-head
12
- env:
13
- secure: "SBq3viHypfDJrrU0dRw6U+tNZFVb3NjMHWN1HROgZ+ecF0ycRKDxHZQCHWg2\nV0FwRDb/pd6eZgk12Yxp0PyE2rxtiU/LulQkp0EvpcGXjuQHudWXTZ2c/RiY\n7FVwvy6SYB6D/3pDmVEtTRu/BQjgE9fMlLaaZms64+t5MtRFSCU="
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.
@@ -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
- When I create "config/application.yml" with:
18
+ Given I create "config/application.yml" with:
19
19
  """
20
20
  GOODBYE: Ruby Tuesday
21
21
  """
22
- And I run "rake hello"
22
+ When I run "rake hello"
23
23
  Then the output should be "Hello!"
24
24
 
25
25
  Scenario: Has blank application.yml
26
- When I create "config/application.yml" with:
26
+ Given I create "config/application.yml" with:
27
27
  """
28
28
  """
29
- And I run "rake hello"
29
+ When I run "rake hello"
30
30
  Then the output should be "Hello!"
31
31
 
32
32
  Scenario: Has commented application.yml
33
- When I create "config/application.yml" with:
33
+ Given I create "config/application.yml" with:
34
34
  """
35
35
  # Comment
36
36
  """
37
- And I run "rake hello"
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
- When I create "config/application.yml" with:
41
+ Given I create "config/application.yml" with:
42
42
  """
43
43
  HELLO: world
44
44
  """
45
- And I run "rake hello"
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
@@ -1,5 +1,3 @@
1
1
  require "pathname"
2
2
 
3
3
  ROOT = Pathname.new(File.expand_path("../../..", __FILE__))
4
-
5
- puts "Travis ENV test: #{ENV["TRAVIS_ENV_TEST"].inspect}"
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "figaro"
5
- gem.version = "0.3.0"
5
+ gem.version = "0.4.0"
6
6
 
7
7
  gem.authors = ["Steve Richert"]
8
8
  gem.email = ["steve.richert@gmail.com"]
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: figaro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: