Skip to content

Commit

Permalink
Some new recipes, some fixes for old ones.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Mar 22, 2011
1 parent 77345c5 commit 3d72eae
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/rails_wizard/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def new(name)
while recipe = ask("#{print_recipes}#{bold}Which recipe would you like to add? #{clear}#{yellow}(blank to finish)#{clear}")
if recipe == ''
run_template(name, @recipes)
break
elsif RailsWizard::Recipes.list.include?(recipe)
@recipes << recipe
puts
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_wizard/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Recipe
def self.<=>(another)
return -1 if another.run_after.include?(self.key) || self.run_before.include?(another.key)
return 1 if another.run_before.include?(self.key) || self.run_after.include?(another.key)
0
self.key <=> another.key
end

ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires)
Expand Down
2 changes: 1 addition & 1 deletion recipes/capybara.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gem 'capybara'
gem 'capybara', :group => [:development, :test]

after_bundler do
create_file "spec/support/capybara.rb", <<-RUBY
Expand Down
4 changes: 2 additions & 2 deletions recipes/cucumber.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
gem 'cucumber-rails', :group => :test
gem 'capybara', :group => :test
gem 'cucumber-rails', :group => [:development, :test]
gem 'capybara', :group => [:development, :test]

after_bundler do
generate "cucumber:install --capybara#{' --rspec' if recipes.include?('rspec')}#{' -D' unless recipes.include?('activerecord')}"
Expand Down
54 changes: 54 additions & 0 deletions recipes/env_yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@


say_wizard "Generating config/env.yaml..."

append_file "config/application.rb", <<-RUBY
require 'env_yaml'
RUBY

create_file "lib/env_yaml.rb", <<-RUBY
require 'yaml'
begin
env_yaml = YAML.load_file(File.dirname(__FILE__) + '/../config/env.yml')
if env_hash = env_yaml[ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development']
puts env_hash.inspect
env_hash.each_pair do |k,v|
ENV[k] = v.to_s
end
end
rescue StandardError => e
end
RUBY

create_file "config/env.yml", <<-YAML
defaults:
ENV_YAML: true
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
YAML

def env(k,v,rack_env='development')
inject_into_file "config/env.yml", :after => "#{rack_env}:\n <<: *defaults" do
<<-YAML
#{k}: #{v.inspect}
YAML
end
end

__END__

name: EnvYAML
description: "Allows you to set environment variables in a YAML file at config/env.yaml"
author: mbleigh

category: other
tags: [utilities, configuration]
2 changes: 1 addition & 1 deletion recipes/jammit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
config:
- pre_commit:
type: boolean
prompt: "Do you a git pre-commit hook to generate assets for Heroku?"
prompt: "Create a git pre-commit hook to generate assets for Heroku?"
if_recipe: heroku
6 changes: 6 additions & 0 deletions recipes/redis.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
gem 'redis'

say_wizard "Generating Redis initializer..."

initializer "redis.rb", <<-RUBY
REDIS = Redis.new
RUBY

__END__

name: Redis
Expand Down
39 changes: 39 additions & 0 deletions recipes/redistogo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
prepend_file "config/initializers/redis.rb", <<-RUBY
uri = URI.parse(ENV['REDISTOGO_URL'])
RUBY

inject_into_file "config/initializers/redis.rb", :after => "Redis.new" do
"(:host => uri.host, :port => uri.port, :password => uri.password)"
end

env("REDISTOGO_URL", "redis://localhost:6379")

after_bundler do
if config['use_heroku']
say_wizard "Adding redistogo:nano Heroku addon, you can always upgrade later."
run "heroku addons:add redistogo:nano"
else
env("REDISTOGO_URL", config['url'], 'production') if config['url']
end
end
__END__

name: RedisToGo
description: "Use RedisToGo hosting for this app's Redis."
author: mbleigh

requires: [redis, env_yaml]
run_after: [redis, env_yaml]
category: services

config:
- use_heroku:
type: boolean
prompt: "Use the RedisToGo Heroku addon?"
if_recipe: heroku
- url:
type: string
prompt: "Enter your RedisToGo URL:"
unless: use_heroku

0 comments on commit 3d72eae

Please sign in to comment.