Class: RuboCop::Cop::Lint::PathInHelpers

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/path_in_helpers.rb

Constant Summary collapse

MSG =
"Don't use _path URL helpers in helper methods; use _url instead.".freeze
PATH_HELPER =
/^[\da-zA-z_]+_path$/.freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rubocop/path_in_helpers.rb', line 10

def on_send(node)
  method_call(node) do |name|
    next unless name.to_s.match?(PATH_HELPER)

    add_offense(node) do |corrector|
      corrected_call = name.to_s.gsub(/_path$/, '_url')
      corrector.replace(node, node.source.sub(name.to_s, corrected_call))
    end
  end
end