Top Level Namespace
Defined Under Namespace
Modules: ApplicationHelper, Orats Classes: Account, AccountTest
Instance Method Summary collapse
- #add_account_fixtures ⇒ Object
- #add_account_model ⇒ Object
- #add_account_unit_tests ⇒ Object
- #add_auth_links_to_the_navbar ⇒ Object
- #add_backup_lib ⇒ Object
- #add_backup_task ⇒ Object
- #add_current_user_alias ⇒ Object
- #add_devise_controller_override ⇒ Object
- #add_devise_initializers ⇒ Object
- #add_devise_migration ⇒ Object
- #add_devise_views ⇒ Object
- #add_dotenv ⇒ Object
- #add_en_locale_for_authorization ⇒ Object
- #add_favicon_task ⇒ Object
- #add_helpers ⇒ Object
- #add_http_error_pages ⇒ Object
- #add_layout ⇒ Object
- #add_layout_partials ⇒ Object
- #add_license ⇒ Object
- #add_main_playbook ⇒ Object
- #add_markdown_readme ⇒ Object
- #add_mini_profiler_initializer ⇒ Object
- #add_playbook_directory ⇒ Object
- #add_procfile ⇒ Object
- #add_puma_config ⇒ Object
- #add_pundit ⇒ Object
- #add_seed_user ⇒ Object
- #add_sidekiq_config ⇒ Object
- #add_sidekiq_initializer ⇒ Object
- #add_sitemap_config ⇒ Object
- #add_staging_environment ⇒ Object
- #add_whenever_config ⇒ Object
- #copy_base_favicon ⇒ Object
- #copy_from_local_gem(source, dest = '') ⇒ Object
- #copy_gemfile ⇒ Object
-
#delete_app_css ⇒ Object
—.
-
#delete_generated_rails_code ⇒ Object
—.
-
#generate_token ⇒ Object
—————————————————————————– private functions —————————————————————————–.
- #git_commit(message) ⇒ Object
- #git_config(field) ⇒ Object
-
#initial_git_commit ⇒ Object
—.
- #log_complete ⇒ Object
- #log_task(message) ⇒ Object
- #method_to_sentence(method) ⇒ Object
- #migrate(table_name, migration = '') ⇒ Object
- #remove_unused_files_from_git ⇒ Object
- #run_bundle_install ⇒ Object
- #update_app_config ⇒ Object
- #update_app_secrets ⇒ Object
- #update_coffeescript ⇒ Object
- #update_database_config ⇒ Object
- #update_development_environment ⇒ Object
- #update_devise_initializer ⇒ Object
- #update_dotenv ⇒ Object
- #update_gemfile ⇒ Object
- #update_gitignore ⇒ Object
- #update_production_environment ⇒ Object
- #update_routes ⇒ Object
- #update_sass ⇒ Object
- #update_sidekiq_config ⇒ Object
- #update_test_helper ⇒ Object
Instance Method Details
#add_account_fixtures ⇒ Object
279 280 281 282 283 |
# File 'lib/orats/templates/auth.rb', line 279 def add_account_fixtures log_task __method__ copy_from_local_gem 'test/fixtures/accounts.yml' git_commit 'Add account fixtures' end |
#add_account_model ⇒ Object
251 252 253 254 255 256 |
# File 'lib/orats/templates/auth.rb', line 251 def add_account_model log_task __method__ copy_from_local_gem 'app/models/account.rb' git_commit 'Add account model' end |
#add_account_unit_tests ⇒ Object
285 286 287 288 289 290 |
# File 'lib/orats/templates/auth.rb', line 285 def add_account_unit_tests log_task __method__ copy_from_local_gem 'test/models/account_test.rb' git_commit 'Add account unit tests' end |
#add_auth_links_to_the_navbar ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/orats/templates/auth.rb', line 342 def log_task __method__ copy_from_local_gem 'app/views/layouts/_navigation_auth.html.erb' inject_into_file 'app/views/layouts/_navigation.html.erb', after: "</ul>\n" do <<-S <ul class="nav navbar-nav nav-auth"> <%= render 'layouts/navigation_auth' %> </ul> S end append_file 'app/assets/stylesheets/application.css.scss' do <<-S @media (min-width: $screen-sm) { .nav-auth { float: right; } } S end git_commit 'Add authentication links to the layout' end |
#add_backup_lib ⇒ Object
311 312 313 314 315 316 317 |
# File 'lib/orats/templates/base.rb', line 311 def add_backup_lib log_task __method__ copy_from_local_gem 'lib/backup/config.rb' copy_from_local_gem 'lib/backup/models/backup.rb' git_commit 'Add backup library' end |
#add_backup_task ⇒ Object
326 327 328 329 330 331 332 |
# File 'lib/orats/templates/base.rb', line 326 def add_backup_task log_task __method__ copy_from_local_gem 'lib/tasks/orats/backup.rake' gsub_file 'lib/tasks/orats/backup.rake', 'app_name', app_name git_commit 'Add an application backup task' end |
#add_current_user_alias ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/orats/templates/auth.rb', line 292 def add_current_user_alias log_task __method__ inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-S alias_method :current_user, :current_account S end git_commit 'Add current_user alias' end |
#add_devise_controller_override ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/orats/templates/auth.rb', line 304 def add_devise_controller_override log_task __method__ inject_into_file 'app/controllers/application_controller.rb', before: "end\n" do <<-S private # override devise to customize the after sign in path #def after_sign_in_path_for(resource) # if resource.is? :admin # admin_path # else # somewhere_path # end #end S end git_commit 'Add devise after_sign_in_path_for override' end |
#add_devise_initializers ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/orats/templates/auth.rb', line 128 def add_devise_initializers log_task __method__ copy_from_local_gem 'config/initializers/devise_async.rb' generate 'devise:install' git_commit 'Add the devise and devise async initializers' end |
#add_devise_migration ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/orats/templates/auth.rb', line 210 def add_devise_migration log_task __method__ migrate :accounts, %{ create_table(:accounts) do |t| ## Database authenticatable t.string :email, :null => false, :default => '' t.string :encrypted_password, :null => false, :default => '' ## Recoverable t.string :reset_password_token t.datetime :reset_password_sent_at ## Rememberable t.datetime :remember_created_at ## Trackable t.integer :sign_in_count, :default => 0, :null => false t.datetime :current_sign_in_at t.datetime :last_sign_in_at t.string :current_sign_in_ip t.string :last_sign_in_ip ## Lockable t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts t.string :unlock_token # Only if unlock strategy is :email or :both t.datetime :locked_at ## Role t.string :role, default: 'guest' t.timestamps end add_index :accounts, :email, :unique => true add_index :accounts, :reset_password_token, :unique => true add_index :accounts, :unlock_token, :unique => true } git_commit 'Add devise model migration' end |
#add_devise_views ⇒ Object
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/orats/templates/auth.rb', line 324 def add_devise_views log_task __method__ copy_from_local_gem 'app/views/devise/confirmations/new.html.erb' copy_from_local_gem 'app/views/devise/mailer/confirmation_instructions.html.erb' copy_from_local_gem 'app/views/devise/mailer/confirmation_instructions.html.erb' copy_from_local_gem 'app/views/devise/mailer/reset_password_instructions.html.erb' copy_from_local_gem 'app/views/devise/mailer/unlock_instructions.html.erb' copy_from_local_gem 'app/views/devise/passwords/edit.html.erb' copy_from_local_gem 'app/views/devise/passwords/new.html.erb' copy_from_local_gem 'app/views/devise/registrations/edit.html.erb' copy_from_local_gem 'app/views/devise/registrations/new.html.erb' copy_from_local_gem 'app/views/devise/sessions/new.html.erb' copy_from_local_gem 'app/views/devise/unlocks/new.html.erb' copy_from_local_gem 'app/views/devise/shared/_links.html.erb' git_commit 'Add devise views' end |
#add_dotenv ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/orats/templates/base.rb', line 97 def add_dotenv log_task 'add_dotenv' copy_from_local_gem '.env', '.env' gsub_file '.env', 'generate_token', generate_token gsub_file '.env', 'app_name', app_name git_commit 'Add development environment file' end |
#add_en_locale_for_authorization ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/orats/templates/auth.rb', line 197 def log_task __method__ gsub_file 'config/locales/en.yml', "hello: \"Hello world\"\n", '' append_file 'config/locales/en.yml' do <<-S authorization: error: 'You are not authorized to perform this action.' S end git_commit 'Add en locale entry for authorization errors' end |
#add_favicon_task ⇒ Object
319 320 321 322 323 324 |
# File 'lib/orats/templates/base.rb', line 319 def add_favicon_task log_task __method__ copy_from_local_gem 'lib/tasks/orats/favicon.rake' git_commit 'Add a favicon generator task' end |
#add_helpers ⇒ Object
334 335 336 337 338 339 |
# File 'lib/orats/templates/base.rb', line 334 def add_helpers log_task __method__ copy_from_local_gem 'app/helpers/application_helper.rb' git_commit 'Add various helpers' end |
#add_http_error_pages ⇒ Object
372 373 374 375 376 377 378 379 380 381 |
# File 'lib/orats/templates/base.rb', line 372 def add_http_error_pages log_task __method__ copy_from_local_gem 'public/404.html' copy_from_local_gem 'public/422.html' copy_from_local_gem 'public/500.html' copy_from_local_gem 'public/502.html' git_commit 'Add http status code pages' end |
#add_layout ⇒ Object
341 342 343 344 345 346 |
# File 'lib/orats/templates/base.rb', line 341 def add_layout log_task __method__ copy_from_local_gem 'app/views/layouts/application.html.erb' git_commit 'Add layout' end |
#add_layout_partials ⇒ Object
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/orats/templates/base.rb', line 348 def add_layout_partials log_task __method__ copy_from_local_gem 'app/views/layouts/_flash.html.erb' copy_from_local_gem 'app/views/layouts/_navigation.html.erb' gsub_file 'app/views/layouts/_navigation.html.erb', 'app_name', app_name copy_from_local_gem 'app/views/layouts/_navigation_links.html.erb' copy_from_local_gem 'app/views/layouts/_footer.html.erb' gsub_file 'app/views/layouts/_footer.html.erb', 'Time.now.year.to_s', Time.now.year.to_s gsub_file 'app/views/layouts/_footer.html.erb', 'app_name', app_name copy_from_local_gem 'app/views/layouts/_google_analytics_snippet.html.erb' copy_from_local_gem 'app/views/layouts/_google_analytics_tracker.html.erb' copy_from_local_gem 'app/views/layouts/_disqus_comments_snippet.html.erb' copy_from_local_gem 'app/views/layouts/_disqus_count_snippet.html.erb' git_commit 'Add layout partials' end |
#add_license ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/orats/templates/base.rb', line 120 def add_license log_task __method__ = git_config 'name' = git_config 'email' copy_from_local_gem '../../common/LICENSE', 'LICENSE' gsub_file 'LICENSE', 'Time.now.year', Time.now.year.to_s gsub_file 'LICENSE', 'author_name', gsub_file 'LICENSE', 'author_email', git_commit 'Add MIT license' end |
#add_main_playbook ⇒ Object
81 82 83 84 85 86 |
# File 'lib/orats/templates/playbook.rb', line 81 def add_main_playbook log_task __method__ copy_from_local_gem 'site.yml', 'site.yml' git_commit 'Add the main playbook' end |
#add_markdown_readme ⇒ Object
113 114 115 116 117 118 |
# File 'lib/orats/templates/base.rb', line 113 def add_markdown_readme log_task __method__ copy_from_local_gem 'README.md' git_commit 'Add markdown readme' end |
#add_mini_profiler_initializer ⇒ Object
237 238 239 240 241 242 |
# File 'lib/orats/templates/base.rb', line 237 def add_mini_profiler_initializer log_task __method__ copy_from_local_gem 'config/initializers/mini_profiler.rb' git_commit 'Add the mini profiler initializer' end |
#add_playbook_directory ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/orats/templates/playbook.rb', line 58 def add_playbook_directory log_task __method__ run "mkdir -p #{app_name}" run "mv #{app_name}/* ." run "rm -rf #{app_name}" git :init git_commit 'Initial commit' end |
#add_procfile ⇒ Object
106 107 108 109 110 111 |
# File 'lib/orats/templates/base.rb', line 106 def add_procfile log_task __method__ copy_from_local_gem 'Procfile' git_commit 'Add Procfile' end |
#add_puma_config ⇒ Object
200 201 202 203 204 205 |
# File 'lib/orats/templates/base.rb', line 200 def add_puma_config log_task __method__ copy_from_local_gem 'config/puma.rb' git_commit 'Add the puma config' end |
#add_pundit ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/orats/templates/auth.rb', line 99 def add_pundit log_task __method__ generate 'pundit:install' inject_into_file 'app/controllers/application_controller.rb', after: "::Base\n" do <<-S include Pundit S end inject_into_file 'app/controllers/application_controller.rb', after: ":exception\n" do <<-S rescue_from Pundit::NotAuthorizedError, with: :account_not_authorized S end inject_into_file 'app/controllers/application_controller.rb', after: " #end\n" do <<-S def account_not_authorized redirect_to request.headers['Referer'] || root_path, flash: { error: I18n.t('authorization.error') } end S end git_commit 'Add pundit policy and controller logic' end |
#add_seed_user ⇒ Object
258 259 260 261 262 263 264 |
# File 'lib/orats/templates/auth.rb', line 258 def add_seed_user log_task __method__ append_file 'db/seeds.rb', "\nAccount.create({ email: \"admin@#{app_name}.com\", password: \"password\", role: \"admin\" })" git_commit 'Add seed user' end |
#add_sidekiq_config ⇒ Object
207 208 209 210 211 212 |
# File 'lib/orats/templates/base.rb', line 207 def add_sidekiq_config log_task __method__ copy_from_local_gem 'config/sidekiq.yml' git_commit 'Add the sidekiq config' end |
#add_sidekiq_initializer ⇒ Object
229 230 231 232 233 234 235 |
# File 'lib/orats/templates/base.rb', line 229 def add_sidekiq_initializer log_task __method__ copy_from_local_gem 'config/initializers/sidekiq.rb' gsub_file 'config/initializers/sidekiq.rb', 'ns_app', app_name git_commit 'Add the sidekiq initializer' end |
#add_sitemap_config ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/orats/templates/base.rb', line 214 def add_sitemap_config log_task __method__ copy_from_local_gem 'config/sitemap.rb' gsub_file 'config/sitemap.rb', 'app_name', app_name git_commit 'Add the sitemap config' end |
#add_staging_environment ⇒ Object
244 245 246 247 248 249 250 251 |
# File 'lib/orats/templates/base.rb', line 244 def add_staging_environment log_task __method__ copy_from_local_gem 'config/environments/staging.rb' gsub_file 'config/environments/staging.rb', 'app_name.humanize', app_name.humanize git_commit 'Add a staging environment' end |
#add_whenever_config ⇒ Object
222 223 224 225 226 227 |
# File 'lib/orats/templates/base.rb', line 222 def add_whenever_config log_task __method__ copy_from_local_gem 'config/whenever.rb' git_commit 'Add the whenever config' end |
#copy_base_favicon ⇒ Object
90 91 92 93 94 95 |
# File 'lib/orats/templates/base.rb', line 90 def copy_base_favicon log_task __method__ copy_from_local_gem 'app/assets/favicon/favicon_base.png' git_commit 'Add a 256x256 base favicon' end |
#copy_from_local_gem(source, dest = '') ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/orats/templates/auth.rb', line 46 def copy_from_local_gem(source, dest = '') dest = source if dest.empty? base_path = "#{File. File.dirname(__FILE__)}/includes/new/rails" run "mkdir -p #{File.dirname(dest)}" unless Dir.exist?(File.dirname(dest)) run "cp -f #{base_path}/#{source} #{dest}" end |
#copy_gemfile ⇒ Object
83 84 85 86 87 88 |
# File 'lib/orats/templates/base.rb', line 83 def copy_gemfile log_task __method__ copy_from_local_gem 'Gemfile' git_commit 'Add Gemfile' end |
#delete_app_css ⇒ Object
57 58 59 |
# File 'lib/orats/templates/auth.rb', line 57 def delete_app_css run 'rm -f app/assets/stylesheets/application.css' end |
#delete_generated_rails_code ⇒ Object
52 53 54 55 56 |
# File 'lib/orats/templates/playbook.rb', line 52 def delete_generated_rails_code log_task __method__ run 'rm -rf * .git .gitignore' end |
#generate_token ⇒ Object
private functions
12 13 14 |
# File 'lib/orats/templates/auth.rb', line 12 def generate_token SecureRandom.hex(64) end |
#git_commit(message) ⇒ Object
28 29 30 31 |
# File 'lib/orats/templates/auth.rb', line 28 def git_commit() git add: '-A' git commit: "-m '#{}'" end |
#git_config(field) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/orats/templates/base.rb', line 33 def git_config(field) command = "git config --global user.#{field}" git_field_value = run(command, capture: true).gsub("\n", '') default_value = "YOUR_#{field.upcase}" git_field_value.to_s.empty? ? default_value : git_field_value end |
#initial_git_commit ⇒ Object
52 53 54 55 56 57 |
# File 'lib/orats/templates/base.rb', line 52 def initial_git_commit log_task __method__ git :init git_commit 'Initial git commit' end |
#log_complete ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/orats/templates/playbook.rb', line 95 def log_complete puts say_status 'success', "\e[1m\Everything has been setup successfully\e[0m", :cyan puts say_status 'question', 'Are most of your apps similar?', :yellow say_status 'answer', 'You only need to generate one playbook and you just did', :white say_status 'answer', 'Use the inventory in each project to customize certain things', :white puts say_status 'question', 'Are you new to ansible?', :yellow say_status 'answer', 'http://docs.ansible.com/intro_getting_started.html', :white puts end |
#log_task(message) ⇒ Object
22 23 24 25 26 |
# File 'lib/orats/templates/auth.rb', line 22 def log_task() puts say_status 'task', "#{method_to_sentence(.to_s)}:", :yellow puts '-'*80, ''; sleep 0.25 end |
#method_to_sentence(method) ⇒ Object
16 17 18 19 20 |
# File 'lib/orats/templates/auth.rb', line 16 def method_to_sentence(method) method.tr!('_', ' ') method[0] = method[0].upcase method end |
#migrate(table_name, migration = '') ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/orats/templates/auth.rb', line 33 def migrate(table_name, migration='') utc_now = Time.now.getutc.strftime("%Y%m%d%H%M%S") class_name = table_name.to_s.classify.pluralize file "db/migrate/#{utc_now}_create_#{table_name}.rb", %{ class Create#{class_name} < ActiveRecord::Migration def change #{migration} end end } end |
#remove_unused_files_from_git ⇒ Object
367 368 369 370 371 372 |
# File 'lib/orats/templates/auth.rb', line 367 def remove_unused_files_from_git log_task __method__ git add: '-u' git_commit 'Remove unused files' end |
#run_bundle_install ⇒ Object
93 94 95 96 97 |
# File 'lib/orats/templates/auth.rb', line 93 def run_bundle_install log_task __method__ run 'bundle install' end |
#update_app_config ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/orats/templates/base.rb', line 140 def update_app_config log_task __method__ inject_into_file 'config/application.rb', after: "automatically loaded.\n" do <<-S config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => ENV['SMTP_ADDRESS'], :port => ENV['SMTP_PORT'].to_i, :domain => ENV['SMTP_DOMAIN'], :user_name => ENV['SMTP_USERNAME'], :password => ENV['SMTP_PASSWORD'], :authentication => ENV['SMTP_AUTH'] } config.action_mailer.smtp_settings[:enable_starttls_auto] = true if ENV['SMTP_ENCRYPTION'] == 'starttls' config.action_mailer.smtp_settings[:ssl] = true if ENV['SMTP_ENCRYPTION'] == 'ssl' config.action_mailer.default_options = { from: ENV['ACTION_MAILER_DEFAULT_FROM'] } config.action_mailer.default_url_options = { host: ENV['ACTION_MAILER_HOST'] } redis_store_options = { host: ENV['CACHE_HOST'], port: ENV['CACHE_PORT'].to_i, db: ENV['CACHE_DATABASE'].to_i, namespace: '#{app_name}::cache' } redis_store_options[:password] = ENV['CACHE_PASSWORD'] if ENV['CACHE_PASSWORD'].present? config.cache_store = :redis_store, redis_store_options # run `bundle exec rake time:zones:all` to get a complete list of valid time zone names config.time_zone = ENV['TIME_ZONE'] unless ENV['TIME_ZONE'] == 'UTC' # http://www.loc.gov/standards/iso639-2/php/English_list.php config.i18n.default_locale = ENV['DEFAULT_LOCALE'] unless ENV['DEFAULT_LOCALE'] == 'en' S end append_file 'config/application.rb' do <<-'S' ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if html_tag =~ /\<label/ html_tag else errors = Array(instance.error_message).join(',') %(#{html_tag}<p class="validation-error"> #{errors}</p>).html_safe end end S end git_commit 'Configure the mailer/redis, update the timezone and adjust the validation output' end |
#update_app_secrets ⇒ Object
133 134 135 136 137 138 |
# File 'lib/orats/templates/base.rb', line 133 def update_app_secrets log_task __method__ copy_from_local_gem 'config/secrets.yml' git_commit 'DRY out the yaml' end |
#update_coffeescript ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/orats/templates/base.rb', line 465 def update_coffeescript log_task __method__ gsub_file 'app/assets/javascripts/application.js', "//= require jquery\n", '' git_commit 'Remove jquery because it is loaded from a CDN' inject_into_file 'app/assets/javascripts/application.js', "//= require jquery.turbolinks\n", before: "//= require_tree .\n" inject_into_file 'app/assets/javascripts/application.js', before: "//= require_tree .\n" do <<-S //= require bootstrap/affix //= require bootstrap/alert //= require bootstrap/button //= require bootstrap/carousel //= require bootstrap/collapse //= require bootstrap/dropdown //= require bootstrap/modal //= require bootstrap/tooltip //= require bootstrap/popover //= require bootstrap/scrollspy //= require bootstrap/tab //= require bootstrap/transition S end git_commit 'Add jquery.turbolinks and bootstrap' end |
#update_database_config ⇒ Object
193 194 195 196 197 198 |
# File 'lib/orats/templates/base.rb', line 193 def update_database_config log_task __method__ copy_from_local_gem 'config/database.yml' git_commit 'DRY out the yaml' end |
#update_development_environment ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/orats/templates/base.rb', line 253 def update_development_environment log_task __method__ inject_into_file 'config/environments/development.rb', before: "\nend" do <<-'S' # Set the default generator asset engines config.generators.stylesheet_engine = :scss config.generators.javascript_engine = :coffee S end git_commit 'Update the default generator asset engines' end |
#update_devise_initializer ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/orats/templates/auth.rb', line 136 def update_devise_initializer log_task 'Update the devise initializer' gsub_file 'config/initializers/devise.rb', "'[email protected]'", "ENV['ACTION_MAILER_DEVISE_DEFAULT_EMAIL']" gsub_file 'config/initializers/devise.rb', /(?<=key = )'\w{128}'/, "ENV['TOKEN_DEVISE_SECRET']" gsub_file 'config/initializers/devise.rb', /(?<=pepper = )'\w{128}'/, "ENV['TOKEN_DEVISE_PEPPER']" gsub_file 'config/initializers/devise.rb', '# config.timeout_in = 30.minutes', 'config.timeout_in = 2.hours' gsub_file 'config/initializers/devise.rb', '# config.expire_auth_token_on_timeout = false', 'config.expire_auth_token_on_timeout = true' gsub_file 'config/initializers/devise.rb', '# config.lock_strategy = :failed_attempts', 'config.lock_strategy = :failed_attempts' gsub_file 'config/initializers/devise.rb', '# config.unlock_strategy = :both', 'config.unlock_strategy = :both' gsub_file 'config/initializers/devise.rb', '# config.maximum_attempts = 20', 'config.maximum_attempts = 7' gsub_file 'config/initializers/devise.rb', '# config.unlock_in = 1.hour', 'config.unlock_in = 2.hours' gsub_file 'config/initializers/devise.rb', '# config.last_attempt_warning = false', 'config.last_attempt_warning = true' git_commit 'Update the devise defaults' end |
#update_dotenv ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/orats/templates/auth.rb', line 75 def update_dotenv log_task __method__ inject_into_file '.env', before: "\nSMTP_ADDRESS" do <<-CODE TOKEN_DEVISE_SECRET: #{generate_token} TOKEN_DEVISE_PEPPER: #{generate_token} CODE end inject_into_file '.env', before: "\nDATABASE_NAME" do <<-CODE ACTION_MAILER_DEVISE_DEFAULT_FROM: info@#{app_name}.com CODE end git_commit 'Add devise tokens and default e-mail' end |
#update_gemfile ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/orats/templates/auth.rb', line 61 def update_gemfile log_task __method__ inject_into_file 'Gemfile', before: "\ngem 'kaminari'" do <<-S gem 'devise', '~> 3.2.4' gem 'devise-async', '~> 0.9.0' gem 'pundit', '~> 0.2.3' S end git_commit 'Add authentication related gems' end |
#update_gitignore ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/orats/templates/base.rb', line 59 def update_gitignore log_task __method__ append_to_file '.gitignore' do <<-S # OS and editor files .DS_Store */**.DS_Store ._* .*.sw* *~ .idea/ # the dotenv file .env # app specific folders /vendor/bundle /public/assets/* S end git_commit 'Add common OS files, editor files and other paths' end |
#update_production_environment ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/orats/templates/base.rb', line 267 def update_production_environment log_task __method__ inject_into_file 'config/environments/production.rb', after: "config.log_level = :info\n" do <<-'S' config.logger = Logger.new(config.paths['log'].first, 'daily') S end git_commit 'Update the logger to rotate daily' inject_into_file 'config/environments/production.rb', after: "%w( search.js )\n" do <<-'S' config.assets.precompile << Proc.new { |path| if path =~ /\.(eot|svg|ttf|woff|png)\z/ true end } S end git_commit 'Update the assets precompiler to include common file types' gsub_file 'config/environments/production.rb', '# config.assets.css_compressor', 'config.assets.css_compressor' git_commit 'Add sass asset compression' end |
#update_routes ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/orats/templates/auth.rb', line 172 def update_routes log_task __method__ gsub_file 'config/routes.rb', "mount Sidekiq::Web => '/sidekiq'\n", '' inject_into_file 'config/routes.rb', after: "collection\n end\n" do <<-S # disable users from being able to register by uncommenting the lines below # get 'accounts/sign_up(.:format)', to: redirect('/') # post 'accounts(.:format)', to: redirect('/') # disable users from deleting their own account by uncommenting the line below # delete 'accounts(.:format)', to: redirect('/') devise_for :accounts authenticate :account, lambda { |account| account.is?(:admin) } do mount Sidekiq::Web => '/sidekiq' end S end git_commit 'Add the devise route and protect sidekiq with authentication' end |
#update_sass ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/orats/templates/base.rb', line 383 def update_sass log_task __method__ run 'mv app/assets/stylesheets/application.css app/assets/stylesheets/application.css.scss' inject_into_file 'app/assets/stylesheets/application.css.scss', " *= require font-awesome\n", before: " *= require_self\n" append_file 'app/assets/stylesheets/application.css.scss' do <<-S // Core variables and mixins @import "bootstrap/variables"; @import "bootstrap/mixins"; // Reset @import "bootstrap/normalize"; @import "bootstrap/print"; // Core CSS @import "bootstrap/scaffolding"; @import "bootstrap/type"; @import "bootstrap/code"; @import "bootstrap/grid"; @import "bootstrap/tables"; @import "bootstrap/forms"; @import "bootstrap/buttons"; // Components @import "bootstrap/component-animations"; // @import "bootstrap/glyphicons"; @import "bootstrap/dropdowns"; @import "bootstrap/button-groups"; @import "bootstrap/input-groups"; @import "bootstrap/navs"; @import "bootstrap/navbar"; @import "bootstrap/breadcrumbs"; @import "bootstrap/pagination"; @import "bootstrap/pager"; @import "bootstrap/labels"; @import "bootstrap/badges"; @import "bootstrap/jumbotron"; @import "bootstrap/thumbnails"; @import "bootstrap/alerts"; @import "bootstrap/progress-bars"; @import "bootstrap/media"; @import "bootstrap/list-group"; @import "bootstrap/panels"; @import "bootstrap/wells"; @import "bootstrap/close"; // Components w/ JavaScript @import "bootstrap/modals"; @import "bootstrap/tooltip"; @import "bootstrap/popovers"; @import "bootstrap/carousel"; // Utility classes @import "bootstrap/utilities"; @import "bootstrap/responsive-utilities"; .alert-notice { @extend .alert-success; } .alert-alert { @extend .alert-danger; } img { @extend .img-responsive; } .validation-error { margin-top: 2px; color: $brand-danger; font-size: $font-size-small; } S end git_commit 'Add font-awesome, bootstrap and a few default styles' end |
#update_sidekiq_config ⇒ Object
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/orats/templates/auth.rb', line 161 def update_sidekiq_config log_task __method__ append_file 'config/sidekiq.yml' do <<-S - mailer S end git_commit 'Add the devise mailer queue to sidekiq' end |
#update_test_helper ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/orats/templates/auth.rb', line 266 def update_test_helper log_task __method__ inject_into_file 'test/test_helper.rb', after: "end\n" do <<-S class ActionController::TestCase include Devise::TestHelpers end S end git_commit 'Add devise test helper' end |