Class: RuboCop::Cop::Cobra::MailerFilePlacement

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
FilePlacementHelp
Defined in:
lib/rubocop/cop/cobra/mailer_file_placement.rb

Overview

This cop disallows adding global helpers to the ‘app/mailers` directory.

The goal is to encourage developers to put new mailer files inside the correct namespace, where they can be more modularly isolated and ownership is clear.

Examples:

# bad
# path: components/my_component/app/mailers/foo.rb
class Foo
  # ...
end

# good
# path: components/my_component/app/mailers/my_component/foo.rb
module MyComponent
  class Foo
    # ...
  end
end

Constant Summary

Constants included from FilePlacementHelp

FilePlacementHelp::FILE_PLACEMENT_MSG

Instance Method Summary collapse

Methods included from FilePlacementHelp

#applicable_component_path?, #file_placement_msg, #namespaced_correctly?

Instance Method Details

#investigate(processed_source) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/cobra/mailer_file_placement.rb', line 29

def investigate(processed_source)
  return if processed_source.blank?

  path = processed_source.file_path
  return unless applicable_component_path?(path, mailers_path)
  return if namespaced_correctly?(path, mailers_path)

  add_offense(processed_source.ast,
              message: file_placement_msg(path, mailers_path))
end