figaro 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/README.md +13 -1
- data/features/rails.feature +33 -7
- data/features/step_definitions/common_steps.rb +4 -0
- data/features/support/aruba.rb +1 -1
- data/features/support/commands.rb +30 -0
- data/features/support/env.rb +5 -1
- data/figaro.gemspec +2 -2
- data/lib/figaro.rb +16 -0
- data/lib/figaro/railtie.rb +5 -2
- data/lib/figaro/tasks.rb +9 -0
- metadata +12 -3
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -48,7 +48,7 @@ Pusher.secret = ENV["PUSHER_SECRET"]
|
|
48
48
|
|
49
49
|
Heroku's beautifully simple application configuration was the [inspiration](http://laserlemon.com/blog/2011/03/08/heroku-friendly-application-configuration/) for Figaro.
|
50
50
|
|
51
|
-
|
51
|
+
Typically, to configure your application `ENV` on Heroku, you would do the following from the command line using the `heroku` gem:
|
52
52
|
|
53
53
|
```bash
|
54
54
|
heroku config:add PUSHER_APP_ID=8926
|
@@ -58,6 +58,18 @@ heroku config:add STRIPE_API_KEY=jHXKPPE0dUW84xJNYzn6CdWM2JfrCbPE
|
|
58
58
|
heroku config:add STRIPE_PUBLIC_KEY=pk_HHtUKJwlN7USCT6nE5jiXgoduiNl3
|
59
59
|
```
|
60
60
|
|
61
|
+
But Figaro provides a rake task to do just that! Just run:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
rake figaro:heroku
|
65
|
+
```
|
66
|
+
|
67
|
+
Optionally, you can pass in the name of the Heroku app:
|
68
|
+
|
69
|
+
```bash
|
70
|
+
rake figaro:heroku[my-awesome-app]
|
71
|
+
```
|
72
|
+
|
61
73
|
## What if I'm not using Heroku?
|
62
74
|
|
63
75
|
No problem. Just add `config/application.yml` to your production app on the server.
|
data/features/rails.feature
CHANGED
@@ -11,7 +11,7 @@ Feature: Rails
|
|
11
11
|
"""
|
12
12
|
|
13
13
|
Scenario: Has no application.yml
|
14
|
-
When I run "
|
14
|
+
When I run "rake hello"
|
15
15
|
Then the output should be "Hello!"
|
16
16
|
|
17
17
|
Scenario: Has application.yml without requested key
|
@@ -19,14 +19,14 @@ Feature: Rails
|
|
19
19
|
"""
|
20
20
|
GOODBYE: Ruby Tuesday
|
21
21
|
"""
|
22
|
-
And I run "
|
22
|
+
And I run "rake hello"
|
23
23
|
Then the output should be "Hello!"
|
24
24
|
|
25
25
|
Scenario: Has blank application.yml
|
26
26
|
When I create "config/application.yml" with:
|
27
27
|
"""
|
28
28
|
"""
|
29
|
-
And I run "
|
29
|
+
And I run "rake hello"
|
30
30
|
Then the output should be "Hello!"
|
31
31
|
|
32
32
|
Scenario: Has commented application.yml
|
@@ -34,7 +34,7 @@ Feature: Rails
|
|
34
34
|
"""
|
35
35
|
# Comment
|
36
36
|
"""
|
37
|
-
And I run "
|
37
|
+
And I run "rake hello"
|
38
38
|
Then the output should be "Hello!"
|
39
39
|
|
40
40
|
Scenario: Has application.yml with requested key
|
@@ -42,16 +42,42 @@ Feature: Rails
|
|
42
42
|
"""
|
43
43
|
HELLO: world
|
44
44
|
"""
|
45
|
-
And I run "
|
45
|
+
And I run "rake hello"
|
46
46
|
Then the output should be "Hello, world!"
|
47
47
|
|
48
48
|
Scenario: Generator creates and ignores application.yml file
|
49
|
-
When I run "
|
49
|
+
When I run "rails generate figaro:install"
|
50
50
|
Then "config/application.yml" should exist
|
51
51
|
And ".gitignore" should contain "/config/application.yml"
|
52
52
|
|
53
53
|
Scenario: Generator only creates application.yml if not using Git
|
54
54
|
Given I run "rm .gitignore"
|
55
|
-
When I run "
|
55
|
+
When I run "rails generate figaro:install"
|
56
56
|
Then "config/application.yml" should exist
|
57
57
|
But ".gitignore" should not exist
|
58
|
+
|
59
|
+
Scenario: Rake task attempts to configure Heroku
|
60
|
+
Given the "heroku" command is:
|
61
|
+
"""
|
62
|
+
#!/usr/bin/env ruby
|
63
|
+
puts "Attempted: heroku #{ARGV.join(" ")}"
|
64
|
+
"""
|
65
|
+
And I create "config/application.yml" with:
|
66
|
+
"""
|
67
|
+
FOO: bar
|
68
|
+
"""
|
69
|
+
When I run "rake figaro:heroku"
|
70
|
+
Then the output should be "Attempted: heroku config:add FOO=bar"
|
71
|
+
|
72
|
+
Scenario: Rake task attempts to configure a specific Heroku app
|
73
|
+
Given the "heroku" command is:
|
74
|
+
"""
|
75
|
+
#!/usr/bin/env ruby
|
76
|
+
puts "Attempted: heroku #{ARGV.join(" ")}"
|
77
|
+
"""
|
78
|
+
And I create "config/application.yml" with:
|
79
|
+
"""
|
80
|
+
FOO: bar
|
81
|
+
"""
|
82
|
+
When I run "rake figaro:heroku[my-app]"
|
83
|
+
Then the output should be "Attempted: heroku config:add FOO=bar --app my-app"
|
data/features/support/aruba.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module CommandHelpers
|
2
|
+
PATH = ROOT.join("tmp/commands")
|
3
|
+
|
4
|
+
def write_command(command, content)
|
5
|
+
path = PATH.join(command)
|
6
|
+
File.open(path, "w"){|f| f << content }
|
7
|
+
FileUtils.chmod(0755, path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def patch_path
|
11
|
+
FileUtils.mkdir_p(PATH)
|
12
|
+
@original_paths = ENV["PATH"] ? ENV["PATH"].split(File::PATH_SEPARATOR) : []
|
13
|
+
ENV["PATH"] = ([PATH] + @original_paths).join(File::PATH_SEPARATOR)
|
14
|
+
end
|
15
|
+
|
16
|
+
def restore_path
|
17
|
+
ENV["PATH"] = @original_paths.join(File::PATH_SEPARATOR)
|
18
|
+
FileUtils.rm_r(PATH)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
World(CommandHelpers)
|
23
|
+
|
24
|
+
Before do
|
25
|
+
patch_path
|
26
|
+
end
|
27
|
+
|
28
|
+
After do
|
29
|
+
restore_path
|
30
|
+
end
|
data/features/support/env.rb
CHANGED
data/figaro.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "figaro"
|
5
|
-
gem.version = "0.
|
5
|
+
gem.version = "0.3.0"
|
6
6
|
|
7
7
|
gem.authors = ["Steve Richert"]
|
8
8
|
gem.email = ["steve.richert@gmail.com"]
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency "rake", ">= 0.8.7"
|
19
19
|
|
20
20
|
gem.files = `git ls-files`.split($\)
|
21
|
-
gem.test_files = gem.files.grep(/^
|
21
|
+
gem.test_files = gem.files.grep(/^features\//)
|
22
22
|
gem.require_paths = ["lib"]
|
23
23
|
end
|
data/lib/figaro.rb
CHANGED
data/lib/figaro/railtie.rb
CHANGED
@@ -4,8 +4,11 @@ require "yaml"
|
|
4
4
|
module Figaro
|
5
5
|
class Railtie < ::Rails::Railtie
|
6
6
|
config.before_configuration do
|
7
|
-
|
8
|
-
|
7
|
+
ENV.update(Figaro.env)
|
8
|
+
end
|
9
|
+
|
10
|
+
rake_tasks do
|
11
|
+
load "figaro/tasks.rb"
|
9
12
|
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/figaro/tasks.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :figaro do
|
2
|
+
desc "Configure Heroku according to application.yml"
|
3
|
+
task :heroku, [:app] => :environment do |_, args|
|
4
|
+
vars = Figaro.env.map{|k,v| "#{k}=#{v}" }.join(" ")
|
5
|
+
command = "heroku config:add #{vars}"
|
6
|
+
command << " --app #{args[:app]}" if args[:app]
|
7
|
+
system(command)
|
8
|
+
end
|
9
|
+
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.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- features/step_definitions/common_steps.rb
|
112
112
|
- features/step_definitions/rails_steps.rb
|
113
113
|
- features/support/aruba.rb
|
114
|
+
- features/support/commands.rb
|
114
115
|
- features/support/env.rb
|
115
116
|
- figaro.gemspec
|
116
117
|
- gemfiles/rails30.gemfile
|
@@ -118,6 +119,7 @@ files:
|
|
118
119
|
- gemfiles/rails32.gemfile
|
119
120
|
- lib/figaro.rb
|
120
121
|
- lib/figaro/railtie.rb
|
122
|
+
- lib/figaro/tasks.rb
|
121
123
|
- lib/generators/figaro/install/install_generator.rb
|
122
124
|
- lib/generators/figaro/install/templates/application.yml
|
123
125
|
homepage: https://github.com/laserlemon/figaro
|
@@ -144,4 +146,11 @@ rubygems_version: 1.8.21
|
|
144
146
|
signing_key:
|
145
147
|
specification_version: 3
|
146
148
|
summary: Simple Rails app configuration
|
147
|
-
test_files:
|
149
|
+
test_files:
|
150
|
+
- features/rails.feature
|
151
|
+
- features/step_definitions/bundler_steps.rb
|
152
|
+
- features/step_definitions/common_steps.rb
|
153
|
+
- features/step_definitions/rails_steps.rb
|
154
|
+
- features/support/aruba.rb
|
155
|
+
- features/support/commands.rb
|
156
|
+
- features/support/env.rb
|