Class: Ducalis::CallbacksActiverecord

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

Constant Summary collapse

OFFENSE =
"  | Please, avoid using of callbacks for models. It's better to keep models small (\"dumb\") and instead use \"builder\" classes/services: to construct new objects.\n".gsub(/^ +\|\s/, '').strip
DETAILS =
"  | You can read more [here](https://medium.com/planet-arkency/a61fd75ab2d3).\n".gsub(/^ +\|\s/, '').strip
METHODS_BLACK_LIST =
i[
  after_commit
  after_create
  after_destroy
  after_find
  after_initialize
  after_rollback
  after_save
  after_touch
  after_update
  after_validation
  around_create
  around_destroy
  around_save
  around_update
  before_create
  before_destroy
  before_save
  before_update
  before_validation
].freeze

Constants included from TypeResolving

TypeResolving::CONTROLLER_SUFFIXES, TypeResolving::MODELS_CLASS_NAMES, TypeResolving::SERVICES_PATH, TypeResolving::WORKERS_SUFFIXES

Instance Method Summary collapse

Methods included from TypeResolving

#on_class, #on_module

Instance Method Details

#on_send(node) ⇒ Object



40
41
42
43
44
45
# File 'lib/ducalis/cops/callbacks_activerecord.rb', line 40

def on_send(node)
  return unless in_model?
  return unless METHODS_BLACK_LIST.include?(node.method_name)

  add_offense(node, :selector, OFFENSE)
end