Class: RuboCop::Cop::Standard::RailsControllerRenderLiteral

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/standard/rails/rails_controller_render_literal.rb

Constant Summary collapse

MSG =
'render must be used with a string literal or an instance of a Class'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/rubocop/cop/standard/rails/rails_controller_render_literal.rb', line 71

def on_send(node)
  return unless render?(node)

  if render_literal?(node) || render_inst?(node) || render_const?(node)
  elsif (option_pairs = render_with_options?(node))
    option_pairs = option_pairs.reject { |pair| options_key?(pair) }

    return if option_pairs.any? { |pair| ignore_key?(pair) }

    if (template_node = option_pairs.map { |pair| template_key?(pair) }.compact.first)
      add_offense(node, location: :expression) unless literal?(template_node)
    else
      add_offense(node, location: :expression)
    end

    if (layout_node = option_pairs.map { |pair| layout_key?(pair) }.compact.first)
      add_offense(node, location: :expression) unless literal?(layout_node)
    end
  else
    add_offense(node, location: :expression)
  end
end