Class: Ducalis::PrivateInstanceAssign

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

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Don't use controller's filter methods for setting instance variables, use them only for changing application flow, such as redirecting if a user is not authenticated. Controller instance variables are forming contract between controller and view. Keeping instance variables defined in one place makes it easier to: reason, refactor and remove old views, test controllers and views, extract actions to new controllers, etc.
MESSAGE
ADD_OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  If you want to memoize variable, please, add underscore to the variable name start: `@_name`.
MESSAGE
DETAILS =
ADD_OFFENSE

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_ivasgn(node) ⇒ Object



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

def on_ivasgn(node)
  return unless in_controller?
  return unless non_public?(node)
  return check_memo(node) if node.parent.type == :or_asgn

  add_offense(node, :expression, OFFENSE)
end