Class: Skeptic::Rules::MethodsPerClass
- Inherits:
-
Object
- Object
- Skeptic::Rules::MethodsPerClass
- Includes:
- SexpVisitor
- Defined in:
- lib/skeptic/rules/methods_per_class.rb
Constant Summary collapse
- DESCRIPTION =
'Limit the number of methods per class'
Instance Method Summary collapse
- #apply_to(code, tokens, tree) ⇒ Object
-
#initialize(limit) ⇒ MethodsPerClass
constructor
A new instance of MethodsPerClass.
- #methods_in(class_name) ⇒ Object
- #name ⇒ Object
- #violations ⇒ Object
Methods included from SexpVisitor
Constructor Details
#initialize(limit) ⇒ MethodsPerClass
Returns a new instance of MethodsPerClass.
8 9 10 11 |
# File 'lib/skeptic/rules/methods_per_class.rb', line 8 def initialize(limit) @methods = Hash.new { |hash, key| hash[key] = [] } @limit = limit end |
Instance Method Details
#apply_to(code, tokens, tree) ⇒ Object
13 14 15 16 |
# File 'lib/skeptic/rules/methods_per_class.rb', line 13 def apply_to(code, tokens, tree) visit tree self end |
#methods_in(class_name) ⇒ Object
18 19 20 |
# File 'lib/skeptic/rules/methods_per_class.rb', line 18 def methods_in(class_name) @methods[class_name].length end |
#name ⇒ Object
33 34 35 |
# File 'lib/skeptic/rules/methods_per_class.rb', line 33 def name "Number of methods per class (#@limit)" end |
#violations ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/skeptic/rules/methods_per_class.rb', line 22 def violations violators = @methods.keys.select { |name| @methods[name].length > @limit } violators.map do |class_name| method_names = @methods[class_name].map { |name| "##{name}" } count = method_names.length "#{class_name} has #{count} methods: #{method_names.join(', ')}" end end |