Class: Ducalis::TooLongWorkers

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

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Seems like your worker is doing too much work, consider of moving business logic to service object. As rule, workers should have only two responsibilities:
  | - __Model materialization__: As async jobs working with serialized attributes it's nescessary to cast them into actual objects.
  | - __Errors handling__: Rescue errors and figure out what to do with them.
MESSAGE

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_module

Instance Method Details

#on_class(node) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/ducalis/cops/too_long_workers.rb', line 17

def on_class(node)
  return unless in_worker?

  length = code_length(node)
  return unless length > max_length

  add_offense(node, :expression, "#{OFFENSE} [#{length}/#{max_length}]")
end