class RuboCop::Cop::Style::OnlyOneMethodPerClass
Require that classes implement exactly one method
Public Instance Methods
investigate(processed_source)
click to toggle source
# File lib/rubo_cop/single_responsibility_principle.rb, line 9 def investigate(processed_source) ast = processed_source.ast return unless ast ast.each_node(:class) do |node| # TODO: consider attr_accessors as well # TODO: distinguish between public and private _, _, body = *node count = body.each_child_node.count(&:def_type?) next if count == 1 # TODO: what should the second thing be...? msg = "Detected #{count} methods; only one is allowed." add_offense(node, :expression, msg) end end