# Application template recipe for the rails_apps_composer. Change the recipe here: # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/init.rb after_everything do say_wizard "recipe running after everything" ### CONFIGURATION FILE ### ## EMAIL case prefs[:email] when 'none' credentials = '' when 'smtp' credentials = '' when 'gmail' credentials = "GMAIL_USERNAME: Your_Username\nGMAIL_PASSWORD: Your_Password\n" when 'sendgrid' credentials = "SENDGRID_USERNAME: Your_Username\nSENDGRID_PASSWORD: Your_Password\n" when 'mandrill' credentials = "MANDRILL_USERNAME: Your_Username\nMANDRILL_API_KEY: Your_API_Key\n" end append_file 'config/application.yml', credentials if prefs[:local_env_file] if prefs[:local_env_file] ## DEFAULT USER unless prefer :starter_app, false append_file 'config/application.yml' do <<-FILE users: - admin: name: Test User 1 email: test@intersect.org.au password: Pass.123 - user: name: Test User 2 email: test2@intersect.org.au password: Pass.123 - user: name: Test User 3 email: test3@intersect.org.au password: Pass.123 FILE end end ## AUTHENTICATION if prefer :authentication, 'omniauth' append_file 'config/application.yml' do <<-FILE OMNIAUTH_PROVIDER_KEY: Your_OmniAuth_Provider_Key OMNIAUTH_PROVIDER_SECRET: Your_OmniAuth_Provider_Secret FILE end end ## AUTHORIZATION if (prefer :authorization, 'cancan') append_file 'config/application.yml', "ROLES: [admin, user]\n" end end ### SUBDOMAINS ### copy_from_repo 'config/application.yml', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app' ### APPLICATION.EXAMPLE.YML ### if prefs[:local_env_file] copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml' end ### DATABASE SEED ### if prefs[:local_env_file] append_file 'db/seeds.rb' do <<-FILE # Environment variables (ENV['...']) can be set in the file config/application.yml. # See http://railsapps.github.io/rails-environment-variables.html FILE end end if (prefer :authorization, 'cancan') unless prefer :orm, 'mongoid' append_file 'db/seeds.rb' do <<-FILE puts 'ROLES' YAML.load(ENV['ROLES']).each do |role| Role.find_or_create_by_name({ :name => role }, :without_protection => true) puts 'role: ' << role end FILE end ## Fix db seed for Rails 4.0 gsub_file 'db/seeds.rb', /{ :name => role }, :without_protection => true/, 'role' if rails_4? else append_file 'db/seeds.rb' do <<-FILE puts 'ROLES' YAML.load(ENV['ROLES']).each do |role| Role.mongo_session['roles'].insert({ :name => role }) puts 'role: ' << role end FILE end end end ## DEVISE-DEFAULT if prefer :authentication, 'devise' append_file 'db/seeds.rb' do <<-FILE puts 'DEFAULT USERS' application = YAML.load_file Rails.root.join('config/application.yml') application['users'].each do |user| type = user.first[0] u = User.find_or_create_by_email name: user['name'], email: user['email'], password: user['password'], password_confirmation: user['password'] u.add_role type.to_sym end FILE end # Mongoid doesn't have a 'find_or_create_by' method gsub_file 'db/seeds.rb', /find_or_create_by_email/, 'create!' if prefer :orm, 'mongoid' end ## DEVISE-CONFIRMABLE if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') append_file 'db/seeds.rb', "user.confirm!\n" end if (prefer :authorization, 'cancan') && !(prefer :authentication, 'omniauth') #append_file 'db/seeds.rb', 'user.add_role :admin' end ## DEVISE-INVITABLE if prefer :devise_modules, 'invitable' run 'bundle exec rake db:migrate' generate 'devise_invitable user' end ### APPLY DATABASE SEED ### unless prefer :orm, 'mongoid' unless prefer :database, 'default' ## ACTIVE_RECORD say_wizard "applying migrations and seeding the database" run 'bundle exec rake db:migrate' run 'bundle exec rake db:test:prepare' end else ## MONGOID say_wizard "dropping database, creating indexes and seeding the database" run 'bundle exec rake db:drop' run 'bundle exec rake db:mongoid:create_indexes' end unless prefs[:skip_seeds] unless prefer :railsapps, 'rails-recurly-subscription-saas' run 'bundle exec rake db:seed' end end ### GIT ### git :add => '-A' if prefer :git, true git :commit => '-qm "rails_apps_composer: set up database"' if prefer :git, true end # after_everything __END__ name: init description: "Set up and initialize database." author: RailsApps requires: [setup, gems, models] run_after: [setup, gems, models] category: initialize