Class: Cane::DocCheck

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



5
6
7
# File 'lib/cane/doc_check.rb', line 5

def opts
  @opts
end

Instance Method Details

#class_definition?(line) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


31
32
33
# File 'lib/cane/doc_check.rb', line 31

def comment?(line)
  line =~ /^\s*#/
end

#file_namesObject



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

#violationsObject



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