Class: RuboCop::Cop::Rails::RakeEnvironment
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Rails::RakeEnvironment
- Defined in:
- lib/rubocop/cop/rails/rake_environment.rb
Overview
This cop checks for Rake tasks without the ‘:environment` task dependency. The `:environment` task loads application code for other Rake tasks. Without it, tasks cannot make use of application code like models.
You can ignore the offense if the task satisfies at least one of the following conditions:
-
The task does not need application code.
-
The task invokes the ‘:environment` task.
Constant Summary collapse
- MSG =
'Include `:environment` task as a dependency for all Rake tasks.'
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/rails/rake_environment.rb', line 44 def autocorrect(node) lambda do |corrector| task_name = node.arguments[0] task_dependency = correct_task_dependency(task_name) corrector.replace(task_name.loc.expression, task_dependency) end end |
#on_block(node) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/rails/rake_environment.rb', line 35 def on_block(node) task_definition?(node) do |task_method| return if task_name(task_method) == :default return if with_dependencies?(task_method) add_offense(task_method) end end |