thyone_creator 0.0.2

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.
Files changed (63) hide show
  1. data/bin/thyone +7 -0
  2. data/lib/rails_wizard/command.rb +116 -0
  3. data/lib/rails_wizard/config.rb +88 -0
  4. data/lib/rails_wizard/recipe.rb +106 -0
  5. data/lib/rails_wizard/recipes.rb +38 -0
  6. data/lib/rails_wizard/template.rb +73 -0
  7. data/lib/rails_wizard.rb +10 -0
  8. data/recipes/action_mailer.rb +123 -0
  9. data/recipes/active_admin.rb +44 -0
  10. data/recipes/activerecord.rb +37 -0
  11. data/recipes/add_user.rb +129 -0
  12. data/recipes/airbrake.rb +34 -0
  13. data/recipes/backbone.rb +23 -0
  14. data/recipes/capybara.rb +34 -0
  15. data/recipes/cleanup.rb +40 -0
  16. data/recipes/cloudfiles.rb +36 -0
  17. data/recipes/compass.rb +46 -0
  18. data/recipes/compass_960.rb +48 -0
  19. data/recipes/cucumber.rb +75 -0
  20. data/recipes/datamapper.rb +111 -0
  21. data/recipes/devise.rb +114 -0
  22. data/recipes/extras.rb +80 -0
  23. data/recipes/git.rb +40 -0
  24. data/recipes/guard.rb +99 -0
  25. data/recipes/haml.rb +23 -0
  26. data/recipes/heroku.rb +62 -0
  27. data/recipes/home_page.rb +58 -0
  28. data/recipes/home_page_users.rb +47 -0
  29. data/recipes/html5.rb +153 -0
  30. data/recipes/inherited_resources.rb +23 -0
  31. data/recipes/less.rb +12 -0
  32. data/recipes/mongohq.rb +59 -0
  33. data/recipes/mongoid.rb +39 -0
  34. data/recipes/mongolab.rb +59 -0
  35. data/recipes/omniauth.rb +192 -0
  36. data/recipes/omniauth_email.rb +82 -0
  37. data/recipes/paperclip.rb +79 -0
  38. data/recipes/rails_admin.rb +21 -0
  39. data/recipes/redis.rb +23 -0
  40. data/recipes/responders.rb +10 -0
  41. data/recipes/resque.rb +25 -0
  42. data/recipes/rspec.rb +133 -0
  43. data/recipes/sass.rb +25 -0
  44. data/recipes/seed_database.rb +76 -0
  45. data/recipes/settingslogic.rb +43 -0
  46. data/recipes/simple_form.rb +54 -0
  47. data/recipes/slim.rb +46 -0
  48. data/recipes/static_page.rb +43 -0
  49. data/recipes/subdomains.rb +121 -0
  50. data/recipes/users_page.rb +165 -0
  51. data/spec/rails_wizard/config_spec.rb +108 -0
  52. data/spec/rails_wizard/recipe_spec.rb +81 -0
  53. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  54. data/spec/rails_wizard/recipes_spec.rb +24 -0
  55. data/spec/rails_wizard/template_spec.rb +78 -0
  56. data/spec/spec_helper.rb +11 -0
  57. data/spec/support/rails_directory.rb +17 -0
  58. data/spec/support/template_runner.rb +28 -0
  59. data/templates/helpers.erb +45 -0
  60. data/templates/layout.erb +83 -0
  61. data/templates/recipe.erb +10 -0
  62. data/version.rb +3 -0
  63. metadata +251 -0
@@ -0,0 +1,129 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/add_user.rb
3
+
4
+ after_bundler do
5
+
6
+ say_wizard "AddUser recipe running 'after bundler'"
7
+
8
+ if recipes.include? 'omniauth'
9
+ generate(:model, "user provider:string uid:string name:string email:string")
10
+ gsub_file 'app/models/user.rb', /end/ do
11
+ <<-RUBY
12
+ attr_accessible :provider, :uid, :name, :email
13
+ end
14
+ RUBY
15
+ end
16
+ end
17
+
18
+ if recipes.include? 'devise'
19
+
20
+ # Generate models and routes for a User
21
+ generate 'devise user'
22
+
23
+ if recipes.include? 'authorization'
24
+ # create'app/models/ability.rb'
25
+ generate 'cancan:ability'
26
+ # create 'app/models/role.rb'
27
+ # create 'config/initializers/rolify.rb'
28
+ # create 'db/migrate/...rolify_create_roles.rb'
29
+ # insert 'rolify' method in 'app/models/users.rb'
30
+ if recipes.include? 'mongoid'
31
+ generate 'rolify:role Role User mongoid'
32
+ else
33
+ generate 'rolify:role Role User'
34
+ end
35
+ end
36
+
37
+ # Add a 'name' attribute to the User model
38
+ if recipes.include? 'mongoid'
39
+ # for mongoid
40
+ gsub_file 'app/models/user.rb', /end/ do
41
+ <<-RUBY
42
+ # run 'rake db:mongoid:create_indexes' to create indexes
43
+ index :email, :unique => true
44
+ field :name
45
+ validates_presence_of :name
46
+ attr_accessible :name, :email, :password, :password_confirmation, :remember_me
47
+ end
48
+ RUBY
49
+ end
50
+ else
51
+ # for ActiveRecord
52
+ # Devise created a Users database, we'll modify it
53
+ generate 'migration AddNameToUsers name:string'
54
+ if recipes.include? 'devise-confirmable'
55
+ generate 'migration AddConfirmableToUsers confirmation_token:string confirmed_at:datetime confirmation_sent_at:datetime unconfirmed_email:string'
56
+ end
57
+ # Devise created a Users model, we'll modify it
58
+ gsub_file 'app/models/user.rb', /attr_accessible :email/, 'attr_accessible :name, :email'
59
+ inject_into_file 'app/models/user.rb', :before => 'validates_uniqueness_of' do
60
+ "validates_presence_of :name\n"
61
+ end
62
+ gsub_file 'app/models/user.rb', /validates_uniqueness_of :email/, 'validates_uniqueness_of :name, :email'
63
+ gsub_file 'app/models/user.rb', /# attr_accessible :title, :body/, ''
64
+ end
65
+
66
+ # needed for both mongoid and ActiveRecord
67
+ if recipes.include? 'devise-confirmable'
68
+ gsub_file 'app/models/user.rb', /:registerable,/, ":registerable, :confirmable,"
69
+ gsub_file 'app/models/user.rb', /:remember_me/, ':remember_me, :confirmed_at'
70
+ if recipes.include? 'mongoid'
71
+ gsub_file 'app/models/user.rb', /# field :confirmation_token/, "field :confirmation_token"
72
+ gsub_file 'app/models/user.rb', /# field :confirmed_at/, "field :confirmed_at"
73
+ gsub_file 'app/models/user.rb', /# field :confirmation_sent_at/, "field :confirmation_sent_at"
74
+ gsub_file 'app/models/user.rb', /# field :unconfirmed_email/, "field :unconfirmed_email"
75
+ end
76
+ end
77
+ if recipes.include? 'devise-invitable'
78
+ if recipes.include? 'mongoid'
79
+ gsub_file 'app/models/user.rb', /end/ do
80
+ <<-RUBY
81
+ #invitable
82
+ field :invitation_token, :type => String
83
+ field :invitation_sent_at, :type => Time
84
+ field :invitation_accepted_at, :type => Time
85
+ field :invitation_limit, :type => Integer
86
+ field :invited_by_id, :type => String
87
+ field :invited_by_type, :type => String
88
+ end
89
+ RUBY
90
+ end
91
+ end
92
+ end
93
+
94
+ unless recipes.include? 'haml'
95
+ # Generate Devise views (unless you are using Haml)
96
+ run 'rails generate devise:views'
97
+ # Modify Devise views to add 'name'
98
+ inject_into_file "app/views/devise/registrations/edit.html.erb", :after => "<%= devise_error_messages! %>\n" do
99
+ <<-ERB
100
+ <p><%= f.label :name %><br />
101
+ <%= f.text_field :name %></p>
102
+ ERB
103
+ end
104
+ inject_into_file "app/views/devise/registrations/new.html.erb", :after => "<%= devise_error_messages! %>\n" do
105
+ <<-ERB
106
+ <p><%= f.label :name %><br />
107
+ <%= f.text_field :name %></p>
108
+ ERB
109
+ end
110
+ else
111
+ # copy Haml versions of modified Devise views
112
+ get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/devise-views-haml/app/views/devise/shared/_links.html.haml', 'app/views/devise/shared/_links.html.haml'
113
+ get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/devise-views-haml/app/views/devise/registrations/edit.html.haml', 'app/views/devise/registrations/edit.html.haml'
114
+ get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/devise-views-haml/app/views/devise/registrations/new.html.haml', 'app/views/devise/registrations/new.html.haml'
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+ __END__
122
+
123
+ name: AddUser
124
+ description: "Add a User model including 'name' and 'email' attributes."
125
+ author: RailsApps
126
+
127
+ run_after: [devise]
128
+ category: other
129
+ tags: [utilities, configuration]
@@ -0,0 +1,34 @@
1
+
2
+ gem 'airbrake'
3
+
4
+ if config['use_heroku']
5
+ after_everything do
6
+ say_wizard "Adding airbrake:developer Heroku addon (you can always upgrade later)"
7
+ run "heroku addons:add airbrake:developer"
8
+ generate "airbrake --heroku"
9
+ end
10
+ else
11
+ after_bundler do
12
+ generate "airbrake --api-key #{config['api_key']}"
13
+ end
14
+ end
15
+
16
+ __END__
17
+
18
+ name: Airbrake
19
+ description: Add Airbrake exception reporting to your application.
20
+
21
+ category: services
22
+ exclusive: exception_notification
23
+ tags: [exception_notification]
24
+ run_after: [heroku]
25
+
26
+ config:
27
+ - use_heroku:
28
+ type: boolean
29
+ prompt: "Use the Airbrake Heroku addon?"
30
+ if_recipe: heroku
31
+ - api_key:
32
+ prompt: "Enter Airbrake API Key:"
33
+ type: string
34
+ unless: use_heroku
@@ -0,0 +1,23 @@
1
+ if config['backbone']
2
+ gem 'rails-backbone', :version => '>= 0.7.2'
3
+ after_bundler do
4
+ generate 'backbone:install'
5
+ end
6
+ else
7
+ recipes.delete('backbone')
8
+ end
9
+
10
+ __END__
11
+
12
+ name: Backbone.js
13
+ description: "Use the Backbone.js MVC framework"
14
+ author: ashley_woodard
15
+
16
+ exclusive: javascript_framework
17
+ category: assets
18
+ tags: [javascript, framework]
19
+
20
+ config:
21
+ - backbone:
22
+ type: boolean
23
+ prompt: Would you like to use the Backbone.js MVC framework?
@@ -0,0 +1,34 @@
1
+ gem 'capybara', :group => [:development, :test] unless recipes.include? 'cucumber'
2
+
3
+ after_bundler do
4
+ create_file "spec/support/capybara.rb", <<-RUBY
5
+ require 'capybara/rails'
6
+ require 'capybara/rspec'
7
+ RUBY
8
+
9
+ create_file "spec/requests/home_spec.rb", <<-RUBY
10
+ require 'spec_helper'
11
+
12
+ describe 'visiting the homepage' do
13
+ before do
14
+ visit '/'
15
+ end
16
+
17
+ it 'should have a body' do
18
+ page.should have_css('body')
19
+ end
20
+ end
21
+ RUBY
22
+ end
23
+
24
+ __END__
25
+
26
+ name: Capybara
27
+ description: "Use the Capybara acceptance testing libraries with RSpec."
28
+ author: mbleigh
29
+
30
+ requires: [rspec]
31
+ run_after: [rspec]
32
+ exclusive: acceptance_testing
33
+ category: testing
34
+ tags: [acceptance]
@@ -0,0 +1,40 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/cleanup.rb
3
+
4
+ after_bundler do
5
+
6
+ say_wizard "Cleanup recipe running 'after bundler'"
7
+
8
+ # remove unnecessary files
9
+ %w{
10
+ README
11
+ doc/README_FOR_APP
12
+ public/index.html
13
+ app/assets/images/rails.png
14
+ }.each { |file| remove_file file }
15
+
16
+ # add placeholder READMEs
17
+ get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/sample_readme.txt", "README"
18
+ get "https://raw.github.com/RailsApps/rails3-application-templates/master/files/sample_readme.textile", "README.textile"
19
+ gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}"
20
+ gsub_file "README.textile", /App_Name/, "#{app_name.humanize.titleize}"
21
+
22
+ # remove commented lines and multiple blank lines from Gemfile
23
+ # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
24
+ gsub_file 'Gemfile', /#.*\n/, "\n"
25
+ gsub_file 'Gemfile', /\n^\s*\n/, "\n"
26
+
27
+ # remove commented lines and multiple blank lines from config/routes.rb
28
+ gsub_file 'config/routes.rb', / #.*\n/, "\n"
29
+ gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
30
+
31
+ end
32
+
33
+ __END__
34
+
35
+ name: Cleanup
36
+ description: "Remove unnecessary files left over from generating a new Rails app."
37
+ author: RailsApps
38
+
39
+ category: other
40
+ tags: [utilities, configuration]
@@ -0,0 +1,36 @@
1
+ if config['cloudfiles']
2
+ gem 'cloudfiles'
3
+ else
4
+ recipes.delete('cloudfiles')
5
+ end
6
+
7
+ if config['cloudfiles']
8
+ after_bundler do
9
+ # Code here is run after Bundler installs all the gems for the project.
10
+ # You can run generators and rake tasks in this section.
11
+ end
12
+ end
13
+
14
+ if config['cloudfiles']
15
+ after_everything do
16
+ # These blocks are run after the bundler blocks and are reserved for
17
+ # special cases like committing the files to a git repository (something
18
+ # that depends on everything having been generated).
19
+ end
20
+ end
21
+ # A recipe is two parts: the Ruby code and YAML back-matter that comes
22
+ # after a blank line with the __END__ keyword.
23
+
24
+ __END__
25
+
26
+ name: Cloudfiles
27
+ description: "Use Cloudfiles to store files."
28
+ author: merlinvn
29
+
30
+ category: persistence
31
+ tags: [storage]
32
+
33
+ config:
34
+ - cloudfiles:
35
+ type: boolean
36
+ prompt: "Would you like to use Cloudfiles to store your files?"
@@ -0,0 +1,46 @@
1
+ if config['compass']
2
+ gem 'compass', :version => '~> 0.12.1', :group => [:assets]
3
+ gem 'compass-rails', :version => '~> 1.0.0', :group => [:assets]
4
+ after_bundler do
5
+ remove_file 'app/assets/stylesheets/application.css'
6
+
7
+ if File.exist?("config/initializers/sass.rb")
8
+ create_file "app/assets/stylesheets/application.css.sass" do <<-SASS
9
+ //= require_self
10
+ //= require_tree .
11
+
12
+ @import compass
13
+ @import _blueprint
14
+ SASS
15
+ end
16
+ else
17
+ create_file "app/assets/stylesheets/application.css.scss" do <<-SCSS
18
+ //= require_self
19
+ //= require_tree .
20
+
21
+ @import "compass";
22
+ @import "_blueprint";
23
+ SCSS
24
+ end
25
+ end
26
+ end
27
+ else
28
+ recipes.delete('compass')
29
+ end
30
+
31
+ __END__
32
+
33
+ name: Compass
34
+ description: "Utilize Compass framework for SASS."
35
+ author: ashley_woodard
36
+
37
+ requires: [sass]
38
+ run_after: [sass]
39
+ exclusive: css_framework
40
+ category: assets
41
+ tags: [css]
42
+
43
+ config:
44
+ - compass:
45
+ type: boolean
46
+ prompt: Would you like to use Compass for stylesheets?
@@ -0,0 +1,48 @@
1
+ if config['compass_960']
2
+ gem 'compass-960-plugin', :version => '~> 0.10.4', :group => [:assets]
3
+ after_bundler do
4
+
5
+ #create compass.rb initializer
6
+ create_file 'config/initializers/compass.rb' do <<-RUBY
7
+ require 'ninesixty'
8
+ RUBY
9
+ end
10
+
11
+ if File.exist?('config/initializers/sass.rb')
12
+ inject_into_file 'app/assets/stylesheets/application.css.sass', :after => "@import compass\n" do <<-SASS
13
+ @import 960/grid
14
+ SASS
15
+ end
16
+ else
17
+ inject_into_file 'app/assets/stylesheets/application.css.scss', :after => "@import \"compass\";\n" do <<-SCSS
18
+ @import "960/grid";
19
+ SCSS
20
+ end
21
+ end
22
+
23
+ inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
24
+ config.sass.load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
25
+ config.sass.load_paths << "#{Gem.loaded_specs['compass-960-plugin'].full_gem_path}/stylesheets"
26
+ RUBY
27
+ end
28
+
29
+ end
30
+ else
31
+ recipes.delete('compass_960')
32
+ end
33
+ __END__
34
+
35
+ name: Compass 960
36
+ description: "Add compass-960-plugin for Compass"
37
+ author: porta
38
+
39
+ requires: [compass]
40
+ run_after: [compass]
41
+ exclusive: css_framework
42
+ category: assets
43
+ tags: [css]
44
+
45
+ config:
46
+ - compass_960:
47
+ type: boolean
48
+ prompt: Would you like to add Compass 960 plugin for Compass?
@@ -0,0 +1,75 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/cucumber.rb
3
+
4
+ if config['cucumber']
5
+ gem 'cucumber-rails', '>= 1.3.0', :group => :test, :require => false
6
+ gem 'capybara', '>= 1.1.2', :group => :test
7
+ gem 'database_cleaner', '>= 0.7.2', :group => :test
8
+ gem 'launchy', '>= 2.1.0', :group => :test
9
+ else
10
+ recipes.delete('cucumber')
11
+ end
12
+
13
+ if config['cucumber']
14
+ after_bundler do
15
+ say_wizard "Cucumber recipe running 'after bundler'"
16
+ generate "cucumber:install --capybara#{' --rspec' if recipes.include?('rspec')}#{' -D' if recipes.include?('mongoid')}"
17
+ # make it easy to run Cucumber for single features without adding "--require features" to the command line
18
+ gsub_file 'config/cucumber.yml', /std_opts = "/, 'std_opts = "-r features/support/ -r features/step_definitions '
19
+ if recipes.include? 'mongoid'
20
+ gsub_file 'features/support/env.rb', /transaction/, "truncation"
21
+ inject_into_file 'features/support/env.rb', :after => 'begin' do
22
+ "\n DatabaseCleaner.orm = 'mongoid'"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ if config['cucumber']
29
+ if recipes.include? 'devise'
30
+ after_bundler do
31
+ say_wizard "Copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples"
32
+ begin
33
+ # copy all the Cucumber scenario files from the rails3-devise-rspec-cucumber example app
34
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_in.feature', 'features/users/sign_in.feature'
35
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_out.feature', 'features/users/sign_out.feature'
36
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/sign_up.feature', 'features/users/sign_up.feature'
37
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/user_edit.feature', 'features/users/user_edit.feature'
38
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/users/user_show.feature', 'features/users/user_show.feature'
39
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/step_definitions/user_steps.rb', 'features/step_definitions/user_steps.rb'
40
+ remove_file 'features/support/paths.rb'
41
+ get 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/features/support/paths.rb', 'features/support/paths.rb'
42
+ if recipes.include? 'devise-confirmable'
43
+ gsub_file 'features/step_definitions/user_steps.rb', /Welcome! You have signed up successfully./, "A message with a confirmation link has been sent to your email address."
44
+ inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do
45
+ <<-RUBY
46
+ Scenario: User has not confirmed account
47
+ Given I exist as an unconfirmed user
48
+ And I am not logged in
49
+ When I sign in with valid credentials
50
+ Then I see an unconfirmed account message
51
+ And I should be signed out
52
+ RUBY
53
+ end
54
+ end
55
+ rescue OpenURI::HTTPError
56
+ say_wizard "Unable to obtain Cucumber example files from the repo"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ __END__
63
+
64
+ name: Cucumber
65
+ description: "Use Cucumber for BDD (with Capybara)."
66
+ author: RailsApps
67
+
68
+ exclusive: acceptance_testing
69
+ category: testing
70
+ tags: [acceptance]
71
+
72
+ config:
73
+ - cucumber:
74
+ type: boolean
75
+ prompt: Would you like to use Cucumber for your BDD?
@@ -0,0 +1,111 @@
1
+ # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/datamapper.rb
3
+ RAILS_VERSION='~> 3.1.0'
4
+ DM_VERSION='~> 1.2.0'
5
+
6
+ if config['datamapper']
7
+ abort "DataMapper #{DM_VERSION} is only compatible with Rails #{RAILS_VERSION}" unless ::Rails::VERSION::MAJOR == 3 and ::Rails::VERSION::MINOR < 2
8
+ else
9
+ recipes.delete('datamapper')
10
+ end
11
+
12
+ if config['datamapper']
13
+ say_wizard "REMINDER: When creating a Rails app using DataMapper,"
14
+ say_wizard "you must add the '-O' flag to 'rails new'"
15
+ gem 'dm-rails', DM_VERSION
16
+ gem "dm-#{config['database']}-adapter", DM_VERSION
17
+ gem 'dm-migrations', DM_VERSION
18
+ gem 'dm-types', DM_VERSION
19
+ gem 'dm-constraints', DM_VERSION
20
+ gem 'dm-transactions', DM_VERSION
21
+ gem 'dm-aggregates', DM_VERSION
22
+ gem 'dm-timestamps', DM_VERSION
23
+ gem 'dm-observer', DM_VERSION
24
+ gem 'dm-validations', DM_VERSION if config['validations'] == 'dm-validations'
25
+ gem 'dm-devise', '>= 2.0.1' if recipes.include? 'devise'
26
+
27
+ inject_into_file 'config/application.rb', "require 'dm-rails/railtie'\n", :after => "require 'action_controller/railtie'\n"
28
+ prepend_file 'app/controllers/application_controller.rb', "require 'dm-rails/middleware/identity_map'\n"
29
+ inject_into_class 'app/controllers/application_controller.rb', 'ApplicationController', " use Rails::DataMapper::Middleware::IdentityMap\n"
30
+ create_file 'config/database.yml' do <<-YAML
31
+ defaults: &defaults
32
+ adapter: #{config['database']}
33
+
34
+ production:
35
+ <<: *defaults
36
+
37
+ development:
38
+ <<: *defaults
39
+
40
+ test:
41
+ <<: *defaults
42
+ YAML
43
+ end
44
+ case config['database']
45
+ when "mysql", "postgres", "oracle", "sqlserver"
46
+ sane_app_name = app_name.gsub(/[^a-zA-Z0-9_]/, '_')
47
+ dbname = ask_wizard "Database name \033[33m[#{sane_app_name}]\033[0m"
48
+ dbname = sane_app_name if dbname.empty?
49
+ dbhost = ask_wizard "Database host \033[33m[localhost]\033[0m"
50
+ dbhost = 'localhost' if dbhost.empty?
51
+ dbuser = ask_wizard "Database username \033[33m[root]\033[0m"
52
+ dbuser = 'root' if dbuser.empty?
53
+ dbpass = ask_wizard "Database password \033[33m[]\033[0m"
54
+ inject_into_file 'config/database.yml', " password: '#{dbpass}'\n", :after => " adapter: #{config['database']}\n"
55
+ inject_into_file 'config/database.yml', " username: #{dbuser}\n", :after => " adapter: #{config['database']}\n"
56
+ inject_into_file 'config/database.yml', " host: #{dbhost}\n", :after => " adapter: #{config['database']}\n"
57
+ inject_into_file 'config/database.yml', " database: #{dbname}\n", :before => "\ndevelopment:"
58
+ inject_into_file 'config/database.yml', " database: #{dbname}_development\n", :before => "\ntest:"
59
+ append_file 'config/database.yml', " database: #{dbname}_test"
60
+ when "sqlite"
61
+ inject_into_file 'config/database.yml', " database: db/production.db\n", :before => "\ndevelopment:"
62
+ inject_into_file 'config/database.yml', " database: db/development.db\n", :before => "\ntest:"
63
+ append_file 'config/database.yml', " database: db/test.db\n"
64
+ end
65
+ end
66
+
67
+ if config['datamapper']
68
+ after_bundler do
69
+ say_wizard "DataMapper recipe running 'after bundler'"
70
+ if recipes.include? 'devise'
71
+ generate 'data_mapper:devise_install'
72
+ gsub_file 'config/initializers/devise.rb', /# config.data_mapper_validation_lib = nil/, "config.data_mapper_validation_lib = '#{config['validations']}'"
73
+ end
74
+ rake "db:create:all" if config['auto_create']
75
+ end
76
+ end
77
+
78
+ __END__
79
+
80
+ name: DataMapper
81
+ description: "Use DataMapper to connect to a data store (requires Rails ~> 3.1.0)."
82
+ author: Peter Fern
83
+
84
+ category: persistence
85
+ exclusive: orm
86
+ tags: [orm, datamapper, sql]
87
+
88
+ args: ["-O"]
89
+
90
+ config:
91
+ - datamapper:
92
+ type: boolean
93
+ prompt: Would you like to use DataMapper to connect to a data store (requires Rails ~> 3.1.0)?
94
+ - database:
95
+ type: multiple_choice
96
+ prompt: "Which backend are you using?"
97
+ choices:
98
+ - ["SQLite", sqlite]
99
+ - ["MySQL", mysql]
100
+ - ["PostgreSQL", postgres]
101
+ - ["Oracle", oracle]
102
+ - ["MSSQL", sqlserver]
103
+ - validations:
104
+ type: multiple_choice
105
+ prompt: "Which validation method do you prefer?"
106
+ choices:
107
+ - ["DataMapper Validations", dm-validations]
108
+ - ["ActiveModel Validations", active_model]
109
+ - auto_create:
110
+ type: boolean
111
+ prompt: "Automatically create database with default configuration?"