Class: Ducalis::FacadePattern

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

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | There are too many instance variables for one controller action. It's beetter to refactor it with Facade pattern to simplify the controller.
MESSAGE
DETAILS =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Good article about [Facade](<https://medium.com/kkempin/facade-design-pattern-in-ruby-on-rails-710aa88326f>).
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_class, #on_module

Instance Method Details

#on_def(node) ⇒ Object



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

def on_def(node)
  return unless in_controller?
  return if non_public?(node)

  assigns = instance_variables_matches(node)
  return if assigns.count < max_instance_variables

  assigns.each { |assign| add_offense(assign, :expression, OFFENSE) }
end