Module: Inch::CodeObject::NodocHelper

Included in:
Proxy::Base
Defined in:
lib/inch/code_object/nodoc_helper.rb

Constant Summary collapse

NO_DOC_REGEX =
/#\s*\:nodoc\:/
NO_DOC_ALL_REGEX =
/#\s*\:nodoc\:\s*all/
DOC_REGEX =
/#\s*\:doc\:/

Instance Method Summary collapse

Instance Method Details

#declarationsArray<String>

Returns all lines in all files declaring the object

Examples:

declarations # => ["class Base # :nodoc:", "class Foo < Base"]

Returns:

  • (Array<String>)


69
70
71
72
73
# File 'lib/inch/code_object/nodoc_helper.rb', line 69

def declarations
  @declarations ||= files.map do |(filename, line_no)|
    get_line_no(filename, line_no)
  end
end

#explicit_doc_comment?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/inch/code_object/nodoc_helper.rb', line 30

def explicit_doc_comment?
  declarations.any? { |str| str =~ DOC_REGEX }
end

#explicit_nodoc_all_comment?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/inch/code_object/nodoc_helper.rb', line 26

def explicit_nodoc_all_comment?
  declarations.any? { |str| str =~ NO_DOC_ALL_REGEX }
end

#explicit_nodoc_comment?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/inch/code_object/nodoc_helper.rb', line 22

def explicit_nodoc_comment?
  declarations.any? { |str| str =~ NO_DOC_REGEX }
end

#filesArray<Array(String, Fixnum)>

Returns all files declaring the object in the form of an Array of Arrays containing the filename and the line number of their declaration.

Examples:

files # => [["lib/inch.rb", 3],
             ["lib/inch/cli.rb", 1],
              ["lib/inch/version.rb", 1],

Returns:

  • (Array<Array(String, Fixnum)>)


85
86
87
88
89
# File 'lib/inch/code_object/nodoc_helper.rb', line 85

def files
  object.files
rescue YARD::CodeObjects::ProxyMethodError
  []
end

#get_line_no(filename, line_number) ⇒ String

Returns a line_number from a file

Parameters:

  • filename (String)
  • line_number (Fixnum)

Returns:

  • (String)


96
97
98
99
100
101
102
# File 'lib/inch/code_object/nodoc_helper.rb', line 96

def get_line_no(filename, line_number)
  f = File.open(filename)
  line_number.times{f.gets}
  result = $_
  f.close
  result
end

#implicit_nodoc_all_comment?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/inch/code_object/nodoc_helper.rb', line 34

def implicit_nodoc_all_comment?
  if parent
    parent.explicit_nodoc_all_comment? ||
      parent.implicit_nodoc_all_comment?
  end
end

#implicit_nodoc_comment?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/inch/code_object/nodoc_helper.rb', line 41

def implicit_nodoc_comment?
  return false if explicit_doc_comment?

  if parent
    return false if parent.explicit_doc_comment?

    if namespace?
      if parent.explicit_nodoc_all_comment?
        return true
      else
        return parent.implicit_nodoc_all_comment?
      end
    else
      if parent.explicit_nodoc_comment?
        return true
      else
        return parent.implicit_nodoc_all_comment?
      end
    end
  end
end

#nodoc?Boolean

Note:

Doesnot recognize “:startdoc:” and “:stopdoc:”

Returns true if the code object is somehow marked not to be documented.

Returns:

  • (Boolean)


10
11
12
# File 'lib/inch/code_object/nodoc_helper.rb', line 10

def nodoc?
  object.tag(:private) || nodoc_comment?
end

#nodoc_comment?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/inch/code_object/nodoc_helper.rb', line 18

def nodoc_comment?
  explicit_nodoc_comment? || implicit_nodoc_comment?
end