Module: RuboCop::Cop::Helpers

Constant Summary collapse

VERBS =
File.read("#{__dir__}/files/verbs.txt").split

Instance Method Summary collapse

Instance Method Details

#rails_callback?(callback) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rubocop/cop/mixin/helpers.rb', line 8

def rails_callback?(callback)
  return true if callback == 'validate'

  callback.match?(
    /
  ^(before|after|around)
  _.*
  (action|validation|create|update|save|destroy|commit|rollback)$
  /x
  )
end

#verb?(string) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/rubocop/cop/mixin/helpers.rb', line 20

def verb?(string)
  short_string = string[2..] if string.start_with?('re')

  VERBS.include?(string) || VERBS.include?(short_string)
end