Class: Ducalis::DataAccessObjects

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

Constant Summary collapse

OFFENSE =
"  | It's a good practice to move code related to serialization/deserialization out of the controller. Consider of creating Data Access Object to separate the data access parts from the application logic. It will eliminate problems related to refactoring and testing.\n".gsub(/^ +\|\s/, '').strip
NODE_EXPRESSIONS =
[
  s(:send, nil, :session),
  s(:send, nil, :cookies),
  s(:gvar, :$redis),
  s(:send, s(:const, nil, :Redis), :current)
].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



22
23
24
25
26
27
# File 'lib/ducalis/cops/data_access_objects.rb', line 22

def on_send(node)
  return unless in_controller?
  return unless NODE_EXPRESSIONS.include?(node.to_a.first)

  add_offense(node, :expression, OFFENSE)
end