Class: RuboCop::Cop::Style::OnlyOneMethodPerClass
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Style::OnlyOneMethodPerClass
- Defined in:
- lib/rubo_cop/single_responsibility_principle.rb
Overview
Require that classes implement exactly one method
Instance Method Summary collapse
Instance Method Details
#investigate(processed_source) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# 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 |