Class: RailsMaint::CLI

Inherits:
Thor
  • Object
show all
Includes:
MaintenancePageHelper
Defined in:
lib/rails_maint/cli.rb

Constant Summary

Constants included from MaintenancePageHelper

MaintenancePageHelper::ALLOWED_LOCALE_PATTERN

Instance Method Summary collapse

Methods included from MaintenancePageHelper

#available_locales, #default_maintenance_page_content

Instance Method Details

#disableObject



42
43
44
45
46
47
# File 'lib/rails_maint/cli.rb', line 42

def disable
  delete_file('tmp/maintenance_mode.txt')
  puts 'Maintenance mode disabled.'
  Instrumentation.instrument('disabled')
  notify_webhook('maintenance.disabled')
end

#enableObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_maint/cli.rb', line 28

def enable
  FileUtils.mkdir_p('tmp')

  data = build_schedule_data
  File.write('tmp/maintenance_mode.txt', data)
  puts 'Maintenance mode enabled.'
  puts "  Scheduled start: #{options[:start]}" if options[:start]
  puts "  Scheduled end: #{options[:end]}" if options[:end]

  Instrumentation.instrument('enabled', start_time: options[:start], end_time: options[:end])
  notify_webhook('maintenance.enabled')
end

#installObject



18
19
20
21
22
23
# File 'lib/rails_maint/cli.rb', line 18

def install
  create_config_file
  create_locale_file(options[:locale])
  puts "RailsMaint has been installed with #{options[:locale]} locale."
  puts 'Tip: In Rails apps, you can also use: rails generate rails_maint:install'
end

#statusObject



50
51
52
# File 'lib/rails_maint/cli.rb', line 50

def status
  StatusPrinter.new.print
end

#uninstallObject



55
56
57
58
59
60
61
# File 'lib/rails_maint/cli.rb', line 55

def uninstall
  delete_file('tmp/maintenance_mode.txt')
  delete_file('config/rails_maint.yml')
  Dir.glob('config/locales/rails_maint.*.yml').each { |f| delete_file(f) }
  delete_file('config/initializers/rails_maint.rb')
  puts 'RailsMaint has been uninstalled and all related files have been removed.'
end