Class: Ducalis::StringsInActiverecords

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/ducalis/cops/strings_in_activerecords.rb

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Please, do not use strings as arguments for %<method_name>s argument. It's hard to test, grep sources, code highlighting and so on. Consider using of symbols or lambdas for complex expressions.
MESSAGE
VALIDATEBLE_METHODS =
::Ducalis::CallbacksActiverecord::METHODS_BLACK_LIST + %i[
  validates
  validate
]

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ducalis/cops/strings_in_activerecords.rb', line 18

def on_send(node)
  _, method_name, *args = *node
  return unless VALIDATEBLE_METHODS.include?(method_name)
  return if args.empty?

  node.to_a.last.each_child_node do |current_node|
    next if skip_node?(current_node)

    add_offense(node, :selector, format(OFFENSE, method_name: method_name))
  end
end