module RailsSafeTasks
Public Class Methods
custom_check(&block)
click to toggle source
Add a custom check which will be executed whenever we check to see if the current environment should allow dangerous tasks or not.
# File lib/rails_safe_tasks.rb, line 30 def custom_check(&block) @custom_checks ||= [] @custom_checks << block end
dangerous_tasks()
click to toggle source
An array of built-in task names which should be protected.
# File lib/rails_safe_tasks.rb, line 9 def dangerous_tasks @dangerous_tasks ||= [ 'db:drop', 'db:reset', 'db:schema:load', 'db:migrate:reset' ] end
restrict?()
click to toggle source
Should the current environment be protected from running dangerous tasks?
# File lib/rails_safe_tasks.rb, line 38 def restrict? # Check the list of restricted environments restricted_environments.include?(Rails.env.to_s) || # Check that it's not deployed with Capistrano File.exist?(Rails.root.join('REVISION')) || # Check the custom checker (@custom_checks && @custom_checks.any? { |c| c.call == true }) || # Nothing else matched, it's OK false end
restricted_environments()
click to toggle source
An array of RAILS_ENV values which should not permit dangerous tasks to be executed.
# File lib/rails_safe_tasks.rb, line 22 def restricted_environments @restricted_environments ||= ['production'] end