Class: Cane::DocCheck
- Inherits:
-
Struct
- Object
- Struct
- Cane::DocCheck
- Defined in:
- lib/cane/doc_check.rb
Overview
Creates violations for class definitions that do not have an explantory comment immediately preceeding.
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #class_definition?(line) ⇒ Boolean
- #comment?(line) ⇒ Boolean
- #file_names ⇒ Object
- #find_violations(file_name) ⇒ Object
- #violations ⇒ Object
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts
5 6 7 |
# File 'lib/cane/doc_check.rb', line 5 def opts @opts end |
Instance Method Details
#class_definition?(line) ⇒ Boolean
27 28 29 |
# File 'lib/cane/doc_check.rb', line 27 def class_definition?(line) line =~ /^\s*class\s+/ and $'.index('<<') != 0 end |
#comment?(line) ⇒ Boolean
31 32 33 |
# File 'lib/cane/doc_check.rb', line 31 def comment?(line) line =~ /^\s*#/ end |
#file_names ⇒ Object
23 24 25 |
# File 'lib/cane/doc_check.rb', line 23 def file_names Dir[opts.fetch(:files)] end |
#find_violations(file_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cane/doc_check.rb', line 12 def find_violations(file_name) last_line = "" File.open(file_name, 'r:utf-8').lines.map.with_index do |line, number| result = if class_definition?(line) && !comment?(last_line) UndocumentedClassViolation.new(file_name, number + 1, line) end last_line = line result end.compact end |
#violations ⇒ Object
6 7 8 9 10 |
# File 'lib/cane/doc_check.rb', line 6 def violations file_names.map { |file_name| find_violations(file_name) }.flatten end |