Module: Inch::Language::Ruby::Provider::YARD::NodocHelper

Included in:
Object::Base
Defined in:
lib/inch/language/ruby/provider/yard/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>)

73
74
75
76
77
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 73

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

#explicit_doc_comment?Boolean

Returns:

  • (Boolean)

34
35
36
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 34

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

#explicit_nodoc_all_comment?Boolean

Returns:

  • (Boolean)

30
31
32
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 30

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

#explicit_nodoc_comment?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 26

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

#get_line_no(filename, line_number) ⇒ String

Returns a line_number from a file

Parameters:

  • filename (String)
  • line_number (Fixnum)

Returns:

  • (String)

84
85
86
87
88
89
90
91
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 84

def get_line_no(filename, line_number)
  f = File.open(filename)
  line_number.times { f.gets }
  result = $LAST_READ_LINE
  f.close
  result.encode('UTF-8', 'binary',
                invalid: :replace, undef: :replace, replace: '')
end

#implicit_nodoc_all_comment?Boolean

Returns:

  • (Boolean)

38
39
40
41
42
43
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 38

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)

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 45

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)

14
15
16
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 14

def nodoc?
  tagged_as_private? || nodoc_comment?
end

#nodoc_comment?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/inch/language/ruby/provider/yard/nodoc_helper.rb', line 22

def nodoc_comment?
  explicit_nodoc_comment? || implicit_nodoc_comment?
end