inch 0.2.3 → 0.3.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +7 -0
  3. data/TODOS.md +0 -5
  4. data/config/defaults.rb +26 -1
  5. data/inch.gemspec +1 -0
  6. data/lib/inch.rb +2 -1
  7. data/lib/inch/api.rb +34 -0
  8. data/lib/inch/api/filter.rb +17 -0
  9. data/lib/inch/api/get.rb +30 -0
  10. data/lib/inch/api/list.rb +10 -0
  11. data/lib/inch/api/options/base.rb +45 -0
  12. data/lib/inch/api/options/filter.rb +25 -0
  13. data/lib/inch/api/options/suggest.rb +36 -0
  14. data/lib/inch/api/stats.rb +7 -0
  15. data/lib/inch/api/suggest.rb +110 -0
  16. data/lib/inch/cli.rb +4 -1
  17. data/lib/inch/cli/command/base.rb +1 -17
  18. data/lib/inch/cli/command/base_list.rb +3 -63
  19. data/lib/inch/cli/command/base_object.rb +6 -28
  20. data/lib/inch/cli/command/list.rb +3 -2
  21. data/lib/inch/cli/command/options/base.rb +1 -1
  22. data/lib/inch/cli/command/options/base_list.rb +4 -2
  23. data/lib/inch/cli/command/options/suggest.rb +9 -8
  24. data/lib/inch/cli/command/output/base.rb +9 -11
  25. data/lib/inch/cli/command/output/list.rb +2 -2
  26. data/lib/inch/cli/command/output/show.rb +2 -10
  27. data/lib/inch/cli/command/output/stats.rb +4 -3
  28. data/lib/inch/cli/command/output/suggest.rb +5 -5
  29. data/lib/inch/cli/command/stats.rb +4 -3
  30. data/lib/inch/cli/command/suggest.rb +4 -94
  31. data/lib/inch/code_object.rb +2 -2
  32. data/lib/inch/code_object/converter.rb +89 -0
  33. data/lib/inch/code_object/provider.rb +36 -0
  34. data/lib/inch/code_object/provider/yard.rb +19 -0
  35. data/lib/inch/code_object/provider/yard/docstring.rb +106 -0
  36. data/lib/inch/code_object/provider/yard/nodoc_helper.rb +93 -0
  37. data/lib/inch/code_object/provider/yard/object.rb +55 -0
  38. data/lib/inch/code_object/provider/yard/object/base.rb +262 -0
  39. data/lib/inch/code_object/provider/yard/object/class_object.rb +12 -0
  40. data/lib/inch/code_object/provider/yard/object/constant_object.rb +12 -0
  41. data/lib/inch/code_object/provider/yard/object/method_object.rb +126 -0
  42. data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +88 -0
  43. data/lib/inch/code_object/provider/yard/object/module_object.rb +12 -0
  44. data/lib/inch/code_object/provider/yard/object/namespace_object.rb +47 -0
  45. data/lib/inch/code_object/provider/yard/parser.rb +54 -0
  46. data/lib/inch/code_object/proxy.rb +5 -3
  47. data/lib/inch/code_object/proxy/base.rb +103 -110
  48. data/lib/inch/code_object/proxy/class_object.rb +0 -1
  49. data/lib/inch/code_object/proxy/method_object.rb +20 -99
  50. data/lib/inch/code_object/proxy/method_parameter_object.rb +15 -39
  51. data/lib/inch/code_object/proxy/namespace_object.rb +7 -18
  52. data/lib/inch/codebase.rb +19 -0
  53. data/lib/inch/codebase/objects.rb +73 -0
  54. data/lib/inch/codebase/objects_filter.rb +61 -0
  55. data/lib/inch/codebase/proxy.rb +22 -0
  56. data/lib/inch/config.rb +8 -1
  57. data/lib/inch/evaluation.rb +5 -7
  58. data/lib/inch/evaluation/file.rb +1 -1
  59. data/lib/inch/evaluation/grade.rb +1 -1
  60. data/lib/inch/evaluation/object_schema.rb +3 -1
  61. data/lib/inch/evaluation/priority_range.rb +44 -0
  62. data/lib/inch/evaluation/proxy.rb +25 -0
  63. data/lib/inch/evaluation/proxy/base.rb +146 -0
  64. data/lib/inch/evaluation/proxy/class_object.rb +8 -0
  65. data/lib/inch/evaluation/proxy/constant_object.rb +19 -0
  66. data/lib/inch/evaluation/proxy/method_object.rb +65 -0
  67. data/lib/inch/evaluation/proxy/module_object.rb +8 -0
  68. data/lib/inch/evaluation/proxy/namespace_object.rb +27 -0
  69. data/lib/inch/evaluation/role/base.rb +19 -0
  70. data/lib/inch/evaluation/role/constant.rb +16 -0
  71. data/lib/inch/evaluation/role/method.rb +22 -0
  72. data/lib/inch/evaluation/role/method_parameter.rb +31 -1
  73. data/lib/inch/evaluation/role/namespace.rb +15 -0
  74. data/lib/inch/evaluation/role/object.rb +24 -0
  75. data/lib/inch/rake/suggest.rb +1 -0
  76. data/lib/inch/utils/read_write_methods.rb +44 -0
  77. data/lib/inch/{cli → utils}/weighted_list.rb +1 -1
  78. data/lib/inch/version.rb +1 -1
  79. data/test/fixtures/simple/lib/broken.rb +8 -0
  80. data/test/inch/api/filter_test.rb +51 -0
  81. data/test/inch/api/get_test.rb +22 -0
  82. data/test/inch/api/list_test.rb +15 -0
  83. data/test/inch/api/options/base_test.rb +30 -0
  84. data/test/inch/api/stats_test.rb +15 -0
  85. data/test/inch/api/suggest_test.rb +26 -0
  86. data/test/inch/cli/command/list_test.rb +2 -1
  87. data/test/inch/code_object/converter_test.rb +29 -0
  88. data/test/inch/code_object/{docstring_test.rb → provider/yard/docstring_test.rb} +13 -13
  89. data/test/inch/code_object/{nodoc_helper_test.rb → provider/yard/nodoc_helper_test.rb} +6 -6
  90. data/test/inch/code_object/provider/yard_test.rb +11 -0
  91. data/test/inch/code_object/provider_test.rb +9 -0
  92. data/test/inch/code_object/proxy/method_object_test.rb +22 -22
  93. data/test/inch/code_object/proxy_test.rb +10 -10
  94. data/test/inch/codebase/objects_test.rb +28 -0
  95. data/test/inch/codebase/proxy_test.rb +17 -0
  96. data/test/inch/evaluation/role/base_test.rb +71 -0
  97. data/test/inch/{cli → utils}/weighted_list_test.rb +2 -2
  98. data/test/shared/base_list.rb +73 -0
  99. data/test/test_helper.rb +0 -95
  100. metadata +89 -24
  101. data/lib/inch/code_object/docstring.rb +0 -102
  102. data/lib/inch/code_object/nodoc_helper.rb +0 -107
  103. data/lib/inch/evaluation/base.rb +0 -157
  104. data/lib/inch/evaluation/class_object.rb +0 -6
  105. data/lib/inch/evaluation/constant_object.rb +0 -33
  106. data/lib/inch/evaluation/method_object.rb +0 -105
  107. data/lib/inch/evaluation/module_object.rb +0 -6
  108. data/lib/inch/evaluation/namespace_object.rb +0 -52
  109. data/lib/inch/evaluation/read_write_methods.rb +0 -21
  110. data/lib/inch/source_parser.rb +0 -62
  111. data/test/inch/source_parser_test.rb +0 -23
@@ -0,0 +1,12 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ class ClassObject < NamespaceObject
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ class ConstantObject < Base
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,126 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ # Proxy class for methods
7
+ class MethodObject < Base
8
+
9
+ def constructor?
10
+ name == :initialize
11
+ end
12
+
13
+ def bang_name?
14
+ name =~ /\!$/
15
+ end
16
+
17
+ def getter?
18
+ attr_info = object.attr_info || {}
19
+ read_info = attr_info[:read]
20
+ if read_info
21
+ read_info.path == fullname
22
+ else
23
+ parent.child(:"#{name}=")
24
+ end
25
+ end
26
+
27
+ def has_doc?
28
+ super && !implicit_docstring?
29
+ end
30
+
31
+ def has_alias?
32
+ !object.aliases.empty?
33
+ end
34
+
35
+ def method?
36
+ true
37
+ end
38
+
39
+ def parameters
40
+ @parameters ||= all_parameter_names.map do |name|
41
+ in_signature = signature_parameter_names.include?(name)
42
+ tag = parameter_tag(name)
43
+ MethodParameterObject.new(self, name, tag, in_signature)
44
+ end
45
+ end
46
+
47
+ def parameter(name)
48
+ parameters.detect { |p| p.name == name.to_s }
49
+ end
50
+
51
+ def overridden?
52
+ !!object.overridden_method
53
+ end
54
+
55
+ def overridden_method
56
+ return unless overridden?
57
+ @overridden_method ||= YARD::Object.for(object.overridden_method)
58
+ end
59
+
60
+ def overridden_method_fullname
61
+ return unless overridden?
62
+ overridden_method.fullname
63
+ end
64
+
65
+ def return_mentioned?
66
+ !!return_tag || docstring.mentions_return?
67
+ end
68
+
69
+ def return_described?
70
+ (return_tag && !return_tag.text.empty?) || docstring.describes_return?
71
+ end
72
+
73
+ def return_typed?
74
+ return_mentioned?
75
+ end
76
+
77
+ def setter?
78
+ name =~ /\=$/ && parameters.size == 1
79
+ end
80
+
81
+ def questioning_name?
82
+ name =~ /\?$/
83
+ end
84
+
85
+ private
86
+
87
+ def all_parameter_names
88
+ names = signature_parameter_names
89
+ names.concat parameter_tags.map(&:name)
90
+ names.compact.uniq
91
+ end
92
+
93
+ def implicit_docstring?
94
+ if getter?
95
+ docstring == "Returns the value of attribute #{name}"
96
+ elsif setter?
97
+ basename = name.to_s.gsub(/(\=)$/, '')
98
+ docstring == "Sets the attribute #{basename}"
99
+ else
100
+ false
101
+ end
102
+ end
103
+
104
+ def signature_parameter_names
105
+ object.parameters.map(&:first)
106
+ end
107
+
108
+ def parameter_tag(param_name)
109
+ parameter_tags.detect do |tag|
110
+ tag.name == param_name
111
+ end
112
+ end
113
+
114
+ def parameter_tags
115
+ object.tags(:param)
116
+ end
117
+
118
+ def return_tag
119
+ object.tags(:return).first
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,88 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ # Proxy class for method parameters
7
+ class MethodParameterObject
8
+ attr_reader :name # @return [String]
9
+
10
+ # @param method [YARD::Object::MethodObject] the method the parameter belongs to
11
+ # @param name [String] the name of the parameter
12
+ # @param tag [YARD::Tags::Tag] the Tag object for the parameter
13
+ # @param in_signature [Boolean] +true+ if the method's signature contains the parameter
14
+ def initialize(method, name, tag, in_signature)
15
+ @method = method
16
+ @name = name
17
+ @tag = tag
18
+ @in_signature = in_signature
19
+ end
20
+
21
+ BAD_NAME_EXCEPTIONS = %w(id)
22
+ BAD_NAME_THRESHOLD = 3
23
+
24
+ # @return [Boolean] +true+ if the name of the parameter is uncommunicative
25
+ def bad_name?
26
+ return false if BAD_NAME_EXCEPTIONS.include?(name)
27
+ name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
28
+ end
29
+
30
+ # @return [Boolean] +true+ if the parameter is a block
31
+ def block?
32
+ name =~ /^\&/
33
+ end
34
+
35
+ # @return [Boolean] +true+ if an additional description given?
36
+ def described?
37
+ described_by_tag? || described_by_docstring?
38
+ end
39
+
40
+ # @return [Boolean] +true+ if the parameter is mentioned in the docs
41
+ def mentioned?
42
+ !!@tag || mentioned_by_docstring?
43
+ end
44
+
45
+ # @return [Boolean] +true+ if the parameter is a splat argument
46
+ def splat?
47
+ name =~ /^\*/
48
+ end
49
+
50
+ # @return [Boolean] +true+ if the type of the parameter is defined
51
+ def typed?
52
+ @tag && @tag.types && !@tag.types.empty?
53
+ end
54
+
55
+ # @return [Boolean] +true+ if the parameter is mentioned in the docs, but not present in the method's signature
56
+ def wrongly_mentioned?
57
+ mentioned? && !@in_signature
58
+ end
59
+
60
+ private
61
+
62
+ def described_by_tag?
63
+ @tag && @tag.text && !@tag.text.empty?
64
+ end
65
+
66
+ def described_by_docstring?
67
+ if @method.docstring.describes_parameter?(name)
68
+ true
69
+ else
70
+ unsplatted = name.gsub(/^[\&\*]/, '')
71
+ @method.docstring.describes_parameter?(unsplatted)
72
+ end
73
+ end
74
+
75
+ def mentioned_by_docstring?
76
+ if @method.docstring.mentions_parameter?(name)
77
+ true
78
+ else
79
+ unsplatted = name.gsub(/^[\&\*]/, '')
80
+ @method.docstring.mentions_parameter?(unsplatted)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,12 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ class ModuleObject < NamespaceObject
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ module Object
6
+ # a namespace object can have methods and other namespace objects
7
+ # inside itself (e.g. classes and modules)
8
+ class NamespaceObject < Base
9
+ def attributes
10
+ object.class_attributes.values + object.instance_attributes.values
11
+ end
12
+
13
+ def children_fullnames
14
+ children.map(&:fullname)
15
+ end
16
+
17
+ def namespace?
18
+ true
19
+ end
20
+
21
+ def has_methods?
22
+ children.any?(&:method?)
23
+ end
24
+
25
+ def pure_namespace?
26
+ children.all?(&:namespace?)
27
+ end
28
+
29
+ # called by MethodObject#getter?
30
+ def child(name)
31
+ if children
32
+ children.detect { |child| child.name == name }
33
+ end
34
+ end
35
+
36
+ def children
37
+ object.children.map do |o|
38
+ YARD::Object.for(o)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ module Inch
2
+ module CodeObject
3
+ module Provider
4
+ module YARD
5
+ # Parses the source tree (using YARD)
6
+ class Parser
7
+ DEFAULT_PATHS = ["app/**/*.rb", "lib/**/*.rb"]
8
+ DEFAULT_EXCLUDED = []
9
+
10
+ # Helper method to parse an instance with the given +args+
11
+ #
12
+ # @see #parse
13
+ # @return [CodeObject::Provider::YARD] the instance that ran
14
+ def self.parse(*args)
15
+ parser = self.new
16
+ parser.parse(*args)
17
+ parser
18
+ end
19
+
20
+ def parse(dir, paths, excluded)
21
+ old_dir = Dir.pwd
22
+ Dir.chdir dir
23
+ parse_yard_objects(paths, excluded)
24
+ inject_base_dir(dir)
25
+ Dir.chdir old_dir
26
+ end
27
+
28
+ def objects
29
+ @objects ||= parsed_objects.map do |o|
30
+ YARD::Object.for(o)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def parse_yard_objects(paths, excluded)
37
+ ::YARD::Registry.clear
38
+ ::YARD.parse(paths || DEFAULT_PATHS, excluded || DEFAULT_EXCLUDED)
39
+ end
40
+
41
+ def inject_base_dir(dir)
42
+ objects.each do |object|
43
+ object.base_dir = dir
44
+ end
45
+ end
46
+
47
+ def parsed_objects
48
+ ::YARD::Registry.all
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -7,14 +7,16 @@ module Inch
7
7
  class << self
8
8
  # Returns a Proxy object for the given +code_object+
9
9
  #
10
- # @param code_object [YARD::CodeObject]
10
+ # @param code_object [YARD::Object::Base]
11
11
  # @return [CodeObject::Proxy::Base]
12
12
  def for(code_object)
13
13
  @cache ||= {}
14
14
  if proxy_object = @cache[cache_key(code_object)]
15
15
  proxy_object
16
16
  else
17
- @cache[cache_key(code_object)] = class_for(code_object).new(code_object)
17
+ attributes = Converter.to_hash(code_object)
18
+ proxy_object = class_for(code_object).new(attributes)
19
+ @cache[cache_key(code_object)] = proxy_object
18
20
  end
19
21
  end
20
22
 
@@ -35,7 +37,7 @@ module Inch
35
37
  #
36
38
  # @return [String]
37
39
  def cache_key(code_object)
38
- code_object.path
40
+ code_object.fullname
39
41
  end
40
42
  end
41
43
  end
@@ -6,60 +6,88 @@ module Inch
6
6
  # @abstract
7
7
  class Base
8
8
  extend Forwardable
9
- include NodocHelper
10
-
11
- # @return [YARD::CodeObjects::Base] the actual (YARD) code object
12
- attr_reader :object
13
9
 
14
10
  # @return [Symbol]
15
11
  # when objects are assigned to GradeLists, this grade is set to
16
12
  # enable easier querying for objects of a certain grade
17
13
  attr_writer :grade
18
14
 
19
- # Tags considered by wrapper methods like {#has_code_example?}
20
- CONSIDERED_YARD_TAGS = %w(api example param private return)
21
-
22
- # convenient shortcuts to (YARD) code object
23
- def_delegators :object, :type, :path, :name, :namespace, :source, :source_type, :signature, :group, :dynamic, :visibility, :docstring
15
+ # @return [#find]
16
+ # an object that responds to #find to look up objects by their
17
+ # full name
18
+ attr_accessor :object_lookup
24
19
 
25
20
  # convenient shortcuts to evalution object
26
21
  def_delegators :evaluation, :score, :roles, :priority
27
22
 
28
- # @param object [YARD::CodeObjects::Base] the actual (YARD) code object
29
- def initialize(object)
30
- @object = object
23
+ def initialize(attributes)
24
+ @attributes = attributes
31
25
  end
32
26
 
33
- def api_tag?
34
- !api_tag.nil?
27
+ # Returns the attribute for the given +key+
28
+ #
29
+ # @param key [Symbol]
30
+ def [](key)
31
+ @attributes[key]
35
32
  end
36
33
 
37
- def api_tag
38
- tag(:api) || (parent && parent.api_tag)
34
+ # @return [Evaluation::Base]
35
+ def evaluation
36
+ @evaluation ||= Evaluation::Proxy.for(self)
39
37
  end
40
38
 
41
- # To be overridden
42
- # @see Proxy::NamespaceObject
43
- # @return [CodeObject::Proxy::Base,nil] the child inside the current object or +nil+
44
- def child(name)
45
- nil
39
+ # @return [Symbol]
40
+ def grade
41
+ @grade ||= Evaluation.new_grade_lists.detect { |range|
42
+ range.scores.include?(score)
43
+ }.grade
46
44
  end
47
45
 
48
- # To be overridden
49
- # @see Proxy::NamespaceObject
50
- # @return [Array,nil] the children of the current object or +nil+
46
+ # @return [Boolean] +true+ if the object has an @api tag
47
+ def api_tag?
48
+ self[:api_tag?]
49
+ end
50
+
51
+ # @return [Array] the children of the current object
51
52
  def children
52
- nil
53
+ @children ||= self[:children_fullnames].map do |fullname|
54
+ object_lookup.find(fullname)
55
+ end
56
+ end
57
+
58
+ # @return [Boolean] +true+ if the object represents a constant
59
+ def constant?
60
+ self[:constant?]
61
+ end
62
+
63
+ def core?
64
+ self[:api_tag?]
65
+ end
66
+
67
+ # The depth of the following is 4:
68
+ #
69
+ # Foo::Bar::Baz#initialize
70
+ # ^ ^ ^ ^
71
+ # 1 << 2 << 3 << 4
72
+ #
73
+ # +depth+ answers the question "how many layers of code objects are
74
+ # above this one?"
75
+ #
76
+ # @note top-level counts, that's why Foo has depth 1!
77
+ #
78
+ # @param i [Fixnum] a counter for recursive method calls
79
+ # @return [Fixnum] the depth of the object in terms of namespace
80
+ def depth
81
+ self[:depth]
53
82
  end
54
83
 
55
84
  # @return [Docstring]
56
85
  def docstring
57
- @docstring ||= Docstring.new(object.docstring)
86
+ self[:docstring]
58
87
  end
59
88
 
60
- # @return [Evaluation::Base]
61
- def evaluation
62
- @evaluation ||= Evaluation.for(self)
89
+ def files
90
+ self[:files]
63
91
  end
64
92
 
65
93
  # Returns the name of the file where the object is declared first
@@ -67,146 +95,111 @@ module Inch
67
95
  def filename
68
96
  # just checking the first file (which is the file where an object
69
97
  # is first declared)
70
- files.size > 0 ? files[0][0] : nil
98
+ files.first
71
99
  end
72
100
 
73
- # @return [Symbol]
74
- def grade
75
- @grade ||= Evaluation.new_grade_lists.detect { |range|
76
- range.scores.include?(score)
77
- }.grade
101
+ # @return [String] the name of an object, e.g.
102
+ # "Docstring"
103
+ def name
104
+ self[:name]
105
+ end
106
+
107
+ # @return [String] the fully qualified name of an object, e.g.
108
+ # "Inch::CodeObject::Provider::YARD::Docstring"
109
+ def fullname
110
+ self[:fullname]
78
111
  end
79
112
 
80
113
  def has_alias?
81
- !object.aliases.empty?
114
+ self[:has_alias?]
115
+ end
116
+
117
+ def has_children?
118
+ self[:has_children?]
82
119
  end
83
120
 
84
121
  def has_code_example?
85
- !tags(:example).empty? ||
86
- docstring.contains_code_example?
122
+ self[:has_code_example?]
87
123
  end
88
124
 
89
125
  def has_doc?
90
- !docstring.empty?
126
+ self[:has_doc?]
91
127
  end
92
128
 
93
129
  def has_multiple_code_examples?
94
- if tags(:example).size > 1 || docstring.code_examples.size > 1
95
- true
96
- else
97
- if tag = tag(:example)
98
- multi_code_examples?(tag.text)
99
- elsif text = docstring.code_examples.first
100
- multi_code_examples?(text)
101
- else
102
- false
103
- end
104
- end
130
+ self[:has_multiple_code_examples?]
105
131
  end
106
132
 
107
133
  def has_unconsidered_tags?
108
- !unconsidered_tags.empty?
134
+ self[:has_unconsidered_tags?]
109
135
  end
110
136
 
111
137
  def in_root?
112
- depth == 1
113
- end
114
-
115
- # The depth of the following is 4:
116
- #
117
- # Foo::Bar::Baz#initialize
118
- # ^ ^ ^ ^
119
- # 1 << 2 << 3 << 4
120
- #
121
- # +depth+ answers the question "how many layers of code objects are
122
- # above this one?"
123
- #
124
- # @note top-level counts, that's why Foo has depth 1!
125
- #
126
- # @param i [Fixnum] a counter for recursive method calls
127
- # @return [Fixnum] the depth of the object in terms of namespace
128
- def depth(i = 0)
129
- if parent
130
- parent.depth(i+1)
131
- else
132
- i
133
- end
138
+ self[:in_root?]
134
139
  end
135
140
 
136
141
  # @return [Boolean] +true+ if the object represents a method
137
142
  def method?
138
- false
143
+ self[:method?]
139
144
  end
140
145
 
141
146
  # @return [Boolean] +true+ if the object represents a namespace
142
147
  def namespace?
143
- false
148
+ self[:namespace?]
149
+ end
150
+
151
+ # @return [Boolean] +true+ if the object was tagged not to be documented
152
+ def nodoc?
153
+ self[:nodoc?]
144
154
  end
145
155
 
146
156
  # @return [Array,nil] the parent of the current object or +nil+
147
157
  def parent
148
- Proxy.for(object.parent) if object.parent
158
+ object_lookup.find( self[:parent_fullname] )
149
159
  end
150
160
 
151
161
  def private?
152
- visibility == :private
162
+ self[:private?]
153
163
  end
154
164
 
155
165
  # @return [Boolean]
156
166
  # +true+ if the object or its parent is tagged as @private
157
167
  def private_tag?
158
- !private_tag.nil?
159
- end
160
-
161
- def private_tag
162
- tag(:private) || (parent && parent.private_tag)
168
+ self[:private_tag?]
163
169
  end
164
170
 
165
171
  def private_api_tag?
166
- api_tag && api_tag.text == 'private'
172
+ self[:private_api_tag?]
167
173
  end
168
174
 
169
175
  def protected?
170
- visibility == :protected
176
+ self[:protected?]
171
177
  end
172
178
 
173
179
  def public?
174
- visibility == :public
180
+ self[:public?]
175
181
  end
176
182
 
177
- # @return [Boolean] +true+ if the object has no documentation at all
178
- def undocumented?
179
- docstring.empty? && tags.empty?
183
+ def source
184
+ self[:source]
180
185
  end
181
186
 
182
- # @return [Array]
183
- # YARD tags that are not already covered by other wrapper methods
184
- def unconsidered_tags
185
- @unconsidered_tags ||= tags.reject do |tag|
186
- CONSIDERED_YARD_TAGS.include?(tag.tag_name)
187
- end
188
- end
189
-
190
- def inspect
191
- "#<#{self.class.to_s}: #{path}>"
187
+ # @return [Boolean] +true+ if the object has no documentation at all
188
+ def undocumented?
189
+ self[:undocumented?]
192
190
  end
193
191
 
194
- protected
195
-
196
- def multi_code_examples?(text)
197
- text.scan(/\b(#{Regexp.escape(name)})[^_0-9\!\?]/m).size > 1
192
+ # @return [Fixnum] the amount of tags not considered for this object
193
+ def unconsidered_tag_count
194
+ self[:unconsidered_tag_count]
198
195
  end
199
196
 
200
- def tag(name)
201
- tags(name).first
197
+ def visibility
198
+ self[:visibility]
202
199
  end
203
200
 
204
- def tags(name = nil)
205
- object.tags(name)
206
- rescue YARD::CodeObjects::ProxyMethodError
207
- # this error is raised by YARD
208
- # see broken.rb in test fixtures
209
- []
201
+ def inspect
202
+ "#<#{self.class.to_s}: #{fullname}>"
210
203
  end
211
204
  end
212
205
  end