figaro 0.2.0 → 0.3.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.
@@ -9,3 +9,5 @@ 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
@@ -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
- To configure your application `ENV` on Heroku, you can do the following from the command line using the `heroku` gem and your production configuration information.
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.
@@ -11,7 +11,7 @@ Feature: Rails
11
11
  """
12
12
 
13
13
  Scenario: Has no application.yml
14
- When I run "bundle exec rake hello"
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 "bundle exec rake hello"
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 "bundle exec rake hello"
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 "bundle exec rake hello"
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 "bundle exec rake hello"
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 "bundle exec rails generate figaro:install"
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 "bundle exec rails generate figaro:install"
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"
@@ -1,3 +1,7 @@
1
+ Given /^the "([^"]+)" command is:$/ do |command, content|
2
+ write_command(command, content)
3
+ end
4
+
1
5
  When /^I create "([^"]+)" with:$/ do |path, content|
2
6
  write_file(path, content)
3
7
  end
@@ -7,6 +7,6 @@ Before do
7
7
  @aruba_timeout_seconds = 60
8
8
  end
9
9
 
10
- After "~@no-clobber" do
10
+ After do
11
11
  FileUtils.rm_rf(current_dir)
12
12
  end
@@ -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
@@ -1 +1,5 @@
1
- ROOT = File.expand_path("../../..", __FILE__)
1
+ require "pathname"
2
+
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.2.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(/^spec\//)
21
+ gem.test_files = gem.files.grep(/^features\//)
22
22
  gem.require_paths = ["lib"]
23
23
  end
@@ -1 +1,17 @@
1
1
  require "figaro/railtie"
2
+
3
+ module Figaro
4
+ extend self
5
+
6
+ def env
7
+ yaml && YAML.load(yaml) || {}
8
+ end
9
+
10
+ def yaml
11
+ File.exist?(path) ? File.read(path) : nil
12
+ end
13
+
14
+ def path
15
+ Rails.root.join("config/application.yml")
16
+ end
17
+ end
@@ -4,8 +4,11 @@ require "yaml"
4
4
  module Figaro
5
5
  class Railtie < ::Rails::Railtie
6
6
  config.before_configuration do
7
- path = Rails.root.join("config/application.yml")
8
- ENV.update(YAML.load(File.read(path)) || {}) if File.exist?(path)
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
@@ -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.2.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-03 00:00:00.000000000 Z
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