Class: Suspenders::JobsGenerator

Inherits:
Generators::Base show all
Defined in:
lib/suspenders/generators/jobs_generator.rb

Instance Method Summary collapse

Methods inherited from Generators::Base

default_source_root

Methods included from Actions

#action_mailer_asset_host, #action_mailer_host, #configure_environment, #expand_json, #replace_in_file

Instance Method Details

#add_jobs_gemObject



5
6
7
8
# File 'lib/suspenders/generators/jobs_generator.rb', line 5

def add_jobs_gem
  gem "sidekiq"
  Bundler.with_clean_env { run "bundle install" }
end

#configure_active_jobObject



45
46
47
48
49
50
51
# File 'lib/suspenders/generators/jobs_generator.rb', line 45

def configure_active_job
  inject_into_file(
    "config/application.rb",
    "\n    config.active_job.queue_adapter = :sidekiq\n",
    before: "\n  end",
  )
end

#configure_foremanObject



10
11
12
13
14
15
# File 'lib/suspenders/generators/jobs_generator.rb', line 10

def configure_foreman
  append_to_file(
    'Procfile',
    "worker: bundle exec sidekiq -C config/sidekiq.yml\n"
  )
end

#configure_sidekiqObject



17
18
19
20
21
22
# File 'lib/suspenders/generators/jobs_generator.rb', line 17

def configure_sidekiq
  copy_file(
    "config_sidekiq.yml",
    "config/sidekiq.yml"
  )
end

#configure_sidekiq_testObject



38
39
40
41
42
43
# File 'lib/suspenders/generators/jobs_generator.rb', line 38

def configure_sidekiq_test
  copy_file(
    "spec_support_sidekiq.rb",
    "spec/support/sidekiq.rb"
  )
end

#configure_sidekiq_webObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/suspenders/generators/jobs_generator.rb', line 24

def configure_sidekiq_web
  inject_into_file(
    "config/routes.rb",
    "require 'sidekiq/web'\n\n",
    before: "Rails.application.routes.draw do\n"
  )
  inject_into_file(
    "config/routes.rb",
    "  mount Sidekiq::Web => '/sidekiq'\n",
    after: "Rails.application.routes.draw do\n"
  )
  warn "Sidekiq web is public! Read https://github.com/mperham/sidekiq/wiki/Monitoring to learn how to add authentication"
end