inch 0.5.0.rc3 → 0.5.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +94 -0
  4. data/CHANGELOG.md +26 -2
  5. data/Gemfile +5 -2
  6. data/README.md +3 -3
  7. data/Rakefile +6 -2
  8. data/bin/inch +3 -3
  9. data/config/{example.yml → .inch.yml.sample} +1 -0
  10. data/config/base.rb +53 -0
  11. data/config/elixir.rb +43 -0
  12. data/config/nodejs.rb +10 -0
  13. data/config/{defaults.rb → ruby.rb} +5 -54
  14. data/inch.gemspec +7 -7
  15. data/lib/inch.rb +14 -9
  16. data/lib/inch/api.rb +10 -10
  17. data/lib/inch/api/compare.rb +2 -2
  18. data/lib/inch/api/compare/code_objects.rb +2 -3
  19. data/lib/inch/api/compare/codebases.rb +1 -1
  20. data/lib/inch/api/diff.rb +13 -16
  21. data/lib/inch/api/filter.rb +1 -1
  22. data/lib/inch/api/get.rb +2 -2
  23. data/lib/inch/api/options/base.rb +4 -4
  24. data/lib/inch/api/options/filter.rb +0 -4
  25. data/lib/inch/api/options/suggest.rb +2 -6
  26. data/lib/inch/api/stats.rb +0 -1
  27. data/lib/inch/api/suggest.rb +9 -10
  28. data/lib/inch/cli.rb +6 -6
  29. data/lib/inch/cli/arguments.rb +2 -2
  30. data/lib/inch/cli/command.rb +15 -15
  31. data/lib/inch/cli/command/base.rb +30 -9
  32. data/lib/inch/cli/command/base_list.rb +2 -2
  33. data/lib/inch/cli/command/console.rb +5 -5
  34. data/lib/inch/cli/command/diff.rb +9 -9
  35. data/lib/inch/cli/command/inspect.rb +5 -4
  36. data/lib/inch/cli/command/list.rb +4 -4
  37. data/lib/inch/cli/command/options/base.rb +17 -16
  38. data/lib/inch/cli/command/options/base_list.rb +9 -5
  39. data/lib/inch/cli/command/options/console.rb +4 -3
  40. data/lib/inch/cli/command/options/diff.rb +8 -6
  41. data/lib/inch/cli/command/options/inspect.rb +2 -2
  42. data/lib/inch/cli/command/options/list.rb +3 -2
  43. data/lib/inch/cli/command/options/show.rb +2 -2
  44. data/lib/inch/cli/command/options/stats.rb +2 -1
  45. data/lib/inch/cli/command/options/suggest.rb +6 -3
  46. data/lib/inch/cli/command/output/base.rb +4 -6
  47. data/lib/inch/cli/command/output/console.rb +6 -7
  48. data/lib/inch/cli/command/output/diff.rb +6 -6
  49. data/lib/inch/cli/command/output/inspect.rb +6 -8
  50. data/lib/inch/cli/command/output/list.rb +0 -1
  51. data/lib/inch/cli/command/output/show.rb +4 -5
  52. data/lib/inch/cli/command/output/stats.rb +21 -21
  53. data/lib/inch/cli/command/output/suggest.rb +31 -28
  54. data/lib/inch/cli/command/show.rb +4 -4
  55. data/lib/inch/cli/command/stats.rb +4 -4
  56. data/lib/inch/cli/command/suggest.rb +6 -6
  57. data/lib/inch/cli/command_parser.rb +6 -5
  58. data/lib/inch/cli/sparkline_helper.rb +6 -6
  59. data/lib/inch/cli/trace_helper.rb +1 -1
  60. data/lib/inch/cli/yardopts_helper.rb +4 -3
  61. data/lib/inch/code_object.rb +3 -3
  62. data/lib/inch/code_object/converter.rb +6 -8
  63. data/lib/inch/code_object/provider.rb +11 -11
  64. data/lib/inch/code_object/proxy.rb +61 -30
  65. data/lib/inch/codebase.rb +7 -8
  66. data/lib/inch/codebase/object.rb +60 -0
  67. data/lib/inch/codebase/objects.rb +8 -10
  68. data/lib/inch/codebase/objects_filter.rb +7 -5
  69. data/lib/inch/codebase/proxy.rb +4 -4
  70. data/lib/inch/codebase/serializer.rb +3 -3
  71. data/lib/inch/config.rb +42 -11
  72. data/lib/inch/config/base.rb +8 -29
  73. data/lib/inch/config/codebase.rb +32 -7
  74. data/lib/inch/config/evaluation.rb +61 -0
  75. data/lib/inch/core_ext.rb +1 -1
  76. data/lib/inch/core_ext/string.rb +1 -1
  77. data/lib/inch/evaluation.rb +13 -21
  78. data/lib/inch/evaluation/file.rb +4 -2
  79. data/lib/inch/evaluation/grade_list.rb +4 -4
  80. data/lib/inch/evaluation/priority_range.rb +3 -0
  81. data/lib/inch/evaluation/proxy.rb +139 -14
  82. data/lib/inch/evaluation/role.rb +99 -0
  83. data/lib/inch/language.rb +3 -0
  84. data/lib/inch/language/elixir/code_object/base.rb +197 -0
  85. data/lib/inch/language/elixir/code_object/function_object.rb +74 -0
  86. data/lib/inch/language/elixir/code_object/module_object.rb +23 -0
  87. data/lib/inch/language/elixir/code_object/type_object.rb +11 -0
  88. data/lib/inch/language/elixir/evaluation/base.rb +28 -0
  89. data/lib/inch/language/elixir/evaluation/function_object.rb +31 -0
  90. data/lib/inch/language/elixir/evaluation/module_object.rb +27 -0
  91. data/lib/inch/language/elixir/evaluation/type_object.rb +11 -0
  92. data/lib/inch/language/elixir/import.rb +24 -0
  93. data/lib/inch/language/elixir/provider/reader.rb +19 -0
  94. data/lib/inch/language/elixir/provider/reader/object.rb +63 -0
  95. data/lib/inch/language/elixir/provider/reader/object/base.rb +191 -0
  96. data/lib/inch/language/elixir/provider/reader/object/function_object.rb +26 -0
  97. data/lib/inch/language/elixir/provider/reader/object/module_object.rb +22 -0
  98. data/lib/inch/language/elixir/provider/reader/object/type_object.rb +15 -0
  99. data/lib/inch/language/elixir/provider/reader/parser.rb +55 -0
  100. data/lib/inch/language/elixir/roles/base.rb +32 -0
  101. data/lib/inch/language/elixir/roles/function.rb +112 -0
  102. data/lib/inch/language/elixir/roles/module.rb +64 -0
  103. data/lib/inch/language/elixir/roles/object.rb +76 -0
  104. data/lib/inch/language/elixir/roles/type.rb +13 -0
  105. data/lib/inch/language/nodejs/import.rb +8 -0
  106. data/lib/inch/language/nodejs/provider/jsdoc.rb +19 -0
  107. data/lib/inch/language/nodejs/provider/jsdoc/object.rb +55 -0
  108. data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +191 -0
  109. data/lib/inch/language/nodejs/provider/jsdoc/parser.rb +59 -0
  110. data/lib/inch/language/ruby/code_object/base.rb +197 -0
  111. data/lib/inch/language/ruby/code_object/class_object.rb +10 -0
  112. data/lib/inch/language/ruby/code_object/class_variable_object.rb +10 -0
  113. data/lib/inch/language/ruby/code_object/constant_object.rb +10 -0
  114. data/lib/inch/language/ruby/code_object/method_object.rb +85 -0
  115. data/lib/inch/language/ruby/code_object/method_parameter_object.rb +64 -0
  116. data/lib/inch/language/ruby/code_object/module_object.rb +10 -0
  117. data/lib/inch/language/ruby/code_object/namespace_object.rb +35 -0
  118. data/lib/inch/language/ruby/evaluation/base.rb +45 -0
  119. data/lib/inch/language/ruby/evaluation/class_object.rb +10 -0
  120. data/lib/inch/language/ruby/evaluation/class_variable_object.rb +21 -0
  121. data/lib/inch/language/ruby/evaluation/constant_object.rb +21 -0
  122. data/lib/inch/language/ruby/evaluation/method_object.rb +74 -0
  123. data/lib/inch/language/ruby/evaluation/module_object.rb +10 -0
  124. data/lib/inch/language/ruby/evaluation/namespace_object.rb +30 -0
  125. data/lib/inch/language/ruby/import.rb +34 -0
  126. data/lib/inch/language/ruby/provider/yard.rb +58 -0
  127. data/lib/inch/language/ruby/provider/yard/docstring.rb +162 -0
  128. data/lib/inch/language/ruby/provider/yard/nodoc_helper.rb +97 -0
  129. data/lib/inch/language/ruby/provider/yard/object.rb +63 -0
  130. data/lib/inch/language/ruby/provider/yard/object/base.rb +325 -0
  131. data/lib/inch/language/ruby/provider/yard/object/class_object.rb +14 -0
  132. data/lib/inch/language/ruby/provider/yard/object/class_variable_object.rb +14 -0
  133. data/lib/inch/language/ruby/provider/yard/object/constant_object.rb +14 -0
  134. data/lib/inch/language/ruby/provider/yard/object/method_object.rb +170 -0
  135. data/lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb +94 -0
  136. data/lib/inch/language/ruby/provider/yard/object/method_signature.rb +120 -0
  137. data/lib/inch/language/ruby/provider/yard/object/module_object.rb +14 -0
  138. data/lib/inch/language/ruby/provider/yard/object/namespace_object.rb +46 -0
  139. data/lib/inch/language/ruby/provider/yard/object/root_object.rb +14 -0
  140. data/lib/inch/language/ruby/provider/yard/parser.rb +71 -0
  141. data/lib/inch/language/ruby/roles/base.rb +17 -0
  142. data/lib/inch/language/ruby/roles/class_variable.rb +53 -0
  143. data/lib/inch/language/ruby/roles/constant.rb +53 -0
  144. data/lib/inch/language/ruby/roles/method.rb +112 -0
  145. data/lib/inch/language/ruby/roles/method_parameter.rb +84 -0
  146. data/lib/inch/language/ruby/roles/missing.rb +24 -0
  147. data/lib/inch/language/ruby/roles/namespace.rb +89 -0
  148. data/lib/inch/language/ruby/roles/object.rb +120 -0
  149. data/lib/inch/rake.rb +2 -2
  150. data/lib/inch/rake/suggest.rb +7 -2
  151. data/lib/inch/utils/buffered_ui.rb +16 -0
  152. data/lib/inch/utils/shell_helper.rb +1 -1
  153. data/lib/inch/utils/ui.rb +5 -5
  154. data/lib/inch/utils/weighted_list.rb +2 -3
  155. data/lib/inch/version.rb +1 -1
  156. data/test/fixtures/{code_examples → ruby/code_examples}/lib/foo.rb +0 -0
  157. data/test/fixtures/{diff1 → ruby/diff1}/lib/diff1.rb +0 -0
  158. data/test/fixtures/{diff2 → ruby/diff2}/lib/diff2.rb +0 -0
  159. data/test/fixtures/{inch-yml → ruby/inch-yml}/.inch.yml +0 -0
  160. data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/bar.rb +0 -0
  161. data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/vendor/base.rb +0 -0
  162. data/test/fixtures/{parameters → ruby/parameters}/lib/foo.rb +0 -0
  163. data/test/fixtures/{readme → ruby/readme}/lib/foo.rb +0 -0
  164. data/test/fixtures/{really_good → ruby/really_good}/lib/foo.rb +0 -0
  165. data/test/fixtures/{really_good_pedantic → ruby/really_good_pedantic}/lib/foo.rb +0 -0
  166. data/test/fixtures/{simple → ruby/simple}/README +0 -0
  167. data/test/fixtures/{simple → ruby/simple}/lib/broken.rb +11 -19
  168. data/test/fixtures/ruby/simple/lib/broken_ruby_2_0_features.rb +7 -0
  169. data/test/fixtures/ruby/simple/lib/directives.rb +8 -0
  170. data/test/fixtures/{simple → ruby/simple}/lib/foo.rb +22 -1
  171. data/test/fixtures/{simple → ruby/simple}/lib/nodoc.rb +0 -0
  172. data/test/fixtures/{simple → ruby/simple}/lib/role_methods.rb +0 -0
  173. data/test/fixtures/{simple → ruby/simple}/lib/role_namespaces.rb +0 -0
  174. data/test/fixtures/{visibility → ruby/visibility}/lib/foo.rb +0 -0
  175. data/test/fixtures/{yardopts → ruby/yardopts}/.yardopts +0 -0
  176. data/test/fixtures/{yardopts → ruby/yardopts}/foo/bar.rb +0 -0
  177. data/test/integration/api/compare/codebases.rb +3 -3
  178. data/test/integration/cli/command/console_test.rb +6 -6
  179. data/test/integration/cli/command/diff_test.rb +62 -0
  180. data/test/integration/cli/command/inspect_test.rb +5 -6
  181. data/test/integration/cli/command/list_test.rb +4 -5
  182. data/test/integration/cli/command/show_test.rb +5 -5
  183. data/test/integration/cli/command/stats_test.rb +3 -3
  184. data/test/integration/cli/command/suggest_test.rb +13 -13
  185. data/test/integration/stats_options_test.rb +4 -4
  186. data/test/integration/visibility_options_test.rb +14 -14
  187. data/test/shared/base_list.rb +4 -3
  188. data/test/test_helper.rb +13 -13
  189. data/test/unit/api/filter_test.rb +7 -7
  190. data/test/unit/api/get_test.rb +1 -1
  191. data/test/unit/api/list_test.rb +1 -1
  192. data/test/unit/api/options/base_test.rb +3 -3
  193. data/test/unit/api/stats_test.rb +1 -1
  194. data/test/unit/api/suggest_test.rb +3 -3
  195. data/test/unit/cli/arguments_test.rb +2 -2
  196. data/test/unit/cli/command/base_test.rb +1 -1
  197. data/test/unit/cli/command/options/base_list_test.rb +2 -2
  198. data/test/unit/cli/command/options/base_object_test.rb +1 -1
  199. data/test/unit/cli/command/options/base_test.rb +1 -1
  200. data/test/unit/cli/command_parser_test.rb +3 -3
  201. data/test/unit/cli/trace_helper_test.rb +1 -1
  202. data/test/unit/cli/yardopts_helper_test.rb +6 -5
  203. data/test/unit/code_object/converter_test.rb +1 -1
  204. data/test/unit/code_object/provider_test.rb +2 -2
  205. data/test/unit/code_object/proxy_test.rb +2 -2
  206. data/test/unit/codebase/objects_test.rb +2 -2
  207. data/test/unit/codebase/proxy_test.rb +7 -5
  208. data/test/unit/config/codebase_test.rb +4 -4
  209. data/test/unit/config_test.rb +28 -0
  210. data/test/unit/evaluation/{role/base_test.rb → role_test.rb} +7 -7
  211. data/test/unit/{code_object/proxy → language/ruby/code_object}/method_object_test.rb +66 -21
  212. data/test/unit/{code_object → language/ruby}/provider/yard/docstring_test.rb +74 -38
  213. data/test/unit/{code_object → language/ruby}/provider/yard/nodoc_helper_test.rb +9 -7
  214. data/test/unit/{code_object → language/ruby}/provider/yard/object/method_object_test.rb +21 -11
  215. data/test/unit/language/ruby/provider/yard_test.rb +25 -0
  216. data/test/unit/utils/buffered_ui_test.rb +48 -0
  217. data/test/unit/utils/ui_test.rb +7 -7
  218. data/test/unit/utils/weighted_list_test.rb +7 -4
  219. metadata +139 -93
  220. data/lib/inch/code_object/provider/yard.rb +0 -57
  221. data/lib/inch/code_object/provider/yard/docstring.rb +0 -133
  222. data/lib/inch/code_object/provider/yard/nodoc_helper.rb +0 -93
  223. data/lib/inch/code_object/provider/yard/object.rb +0 -60
  224. data/lib/inch/code_object/provider/yard/object/base.rb +0 -302
  225. data/lib/inch/code_object/provider/yard/object/class_object.rb +0 -12
  226. data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +0 -12
  227. data/lib/inch/code_object/provider/yard/object/constant_object.rb +0 -12
  228. data/lib/inch/code_object/provider/yard/object/method_object.rb +0 -153
  229. data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +0 -88
  230. data/lib/inch/code_object/provider/yard/object/method_signature.rb +0 -114
  231. data/lib/inch/code_object/provider/yard/object/module_object.rb +0 -12
  232. data/lib/inch/code_object/provider/yard/object/namespace_object.rb +0 -47
  233. data/lib/inch/code_object/provider/yard/object/root_object.rb +0 -12
  234. data/lib/inch/code_object/provider/yard/parser.rb +0 -62
  235. data/lib/inch/code_object/proxy/base.rb +0 -241
  236. data/lib/inch/code_object/proxy/class_object.rb +0 -8
  237. data/lib/inch/code_object/proxy/class_variable_object.rb +0 -8
  238. data/lib/inch/code_object/proxy/constant_object.rb +0 -8
  239. data/lib/inch/code_object/proxy/method_object.rb +0 -82
  240. data/lib/inch/code_object/proxy/method_parameter_object.rb +0 -60
  241. data/lib/inch/code_object/proxy/module_object.rb +0 -8
  242. data/lib/inch/code_object/proxy/namespace_object.rb +0 -33
  243. data/lib/inch/evaluation/object_schema.rb +0 -30
  244. data/lib/inch/evaluation/proxy/base.rb +0 -164
  245. data/lib/inch/evaluation/proxy/class_object.rb +0 -8
  246. data/lib/inch/evaluation/proxy/class_variable_object.rb +0 -19
  247. data/lib/inch/evaluation/proxy/constant_object.rb +0 -19
  248. data/lib/inch/evaluation/proxy/method_object.rb +0 -65
  249. data/lib/inch/evaluation/proxy/module_object.rb +0 -8
  250. data/lib/inch/evaluation/proxy/namespace_object.rb +0 -27
  251. data/lib/inch/evaluation/role/base.rb +0 -92
  252. data/lib/inch/evaluation/role/class_variable.rb +0 -55
  253. data/lib/inch/evaluation/role/constant.rb +0 -55
  254. data/lib/inch/evaluation/role/method.rb +0 -126
  255. data/lib/inch/evaluation/role/method_parameter.rb +0 -91
  256. data/lib/inch/evaluation/role/missing.rb +0 -20
  257. data/lib/inch/evaluation/role/namespace.rb +0 -85
  258. data/lib/inch/evaluation/role/object.rb +0 -143
  259. data/test/unit/code_object/provider/yard_test.rb +0 -25
@@ -1,133 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- class Docstring
6
- def initialize(text)
7
- @text = text.to_s
8
- end
9
-
10
- def describes_internal_api?
11
- first_line =~ /^Internal\:\ .+/
12
- end
13
-
14
- def describes_private_object?
15
- first_line =~ /^Private\:\ .+/
16
- end
17
-
18
- def empty?
19
- @text.strip.empty?
20
- end
21
-
22
- def contains_code_example?
23
- !code_examples.empty?
24
- end
25
-
26
- def code_examples
27
- @code_examples ||= parse_code_examples
28
- end
29
-
30
- def describes_parameter?(name)
31
- return false if name.nil?
32
- describe_parameter_regexps(name).any? do |pattern|
33
- @text.index(pattern)
34
- end
35
- end
36
-
37
- def mentions_parameter?(name)
38
- return false if name.nil?
39
- mention_parameter_regexps(name).any? do |pattern|
40
- @text.index(pattern)
41
- end
42
- end
43
-
44
- def mentions_return?
45
- last_line =~ /^#{tomdoc_modifiers}Returns\ /
46
- end
47
-
48
- def describes_return?
49
- last_line =~ /^#{tomdoc_modifiers}Returns\ (\w+\s){2,}/i ||
50
- last_line =~ /^#{tomdoc_modifiers}Returns\ (nil|nothing)\.*/i
51
- end
52
-
53
- def to_s
54
- @text
55
- end
56
-
57
- private
58
-
59
- def first_line
60
- @first_line ||= @text.lines.to_a.first
61
- end
62
-
63
- def last_line
64
- @last_line ||= @text.lines.to_a.last
65
- end
66
-
67
- def parse_code_examples
68
- code_examples = []
69
- example = nil
70
- @text.lines.each_with_index do |line, index|
71
- if line =~/^\s*+$/
72
- code_examples << example if example
73
- example = []
74
- elsif line =~/^\ {2,}\S+/
75
- example << line if example
76
- else
77
- code_examples << example if example
78
- example = nil
79
- end
80
- end
81
- code_examples << example if example
82
- code_examples.delete_if(&:empty?).map(&:join)
83
- end
84
-
85
- def mention_parameter_patterns(name)
86
- [
87
- "+#{name}+",
88
- "+#{name}+::",
89
- "<tt>#{name}</tt>",
90
- "<tt>#{name}</tt>::",
91
- "#{name}::",
92
- /^#{Regexp.escape(name)}\ \-\ /
93
- ]
94
- end
95
-
96
- def describe_parameter_extra_regexps(name)
97
- [
98
- "#{name}::",
99
- "+#{name}+::",
100
- "<tt>#{name}</tt>::",
101
- ].map do |pattern|
102
- r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
103
- /#{r}\n\ {2,}.+/m
104
- end
105
- end
106
-
107
- def describe_parameter_regexps(name)
108
- same_line_regexps = mention_parameter_patterns(name).map do |pattern|
109
- r = pattern.is_a?(Regexp) ? pattern : Regexp.escape(pattern)
110
- /^#{r}\s?\S+/
111
- end
112
- same_line_regexps + describe_parameter_extra_regexps(name)
113
- end
114
-
115
- def mention_parameter_regexps(name)
116
- mention_parameter_patterns(name).map do |pattern|
117
- if pattern.is_a?(Regexp)
118
- pattern
119
- else
120
- r = Regexp.escape(pattern)
121
- /\W#{r}\W/
122
- end
123
- end
124
- end
125
-
126
- def tomdoc_modifiers
127
- /((Public|Private|Internal)\:\ )*/
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
@@ -1,93 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- module NodocHelper
6
-
7
- # Returns true if the code object is somehow marked not to be
8
- # documented.
9
- #
10
- # @note Doesnot recognize ":startdoc:" and ":stopdoc:"
11
- #
12
- def nodoc?
13
- tagged_as_private? || nodoc_comment?
14
- end
15
-
16
- NO_DOC_REGEX = /#\s*\:nodoc\:/
17
- NO_DOC_ALL_REGEX = /#\s*\:nodoc\:\s*all/
18
- DOC_REGEX = /#\s*\:doc\:/
19
-
20
- def nodoc_comment?
21
- explicit_nodoc_comment? || implicit_nodoc_comment?
22
- end
23
-
24
- def explicit_nodoc_comment?
25
- declarations.any? { |str| str =~ NO_DOC_REGEX }
26
- end
27
-
28
- def explicit_nodoc_all_comment?
29
- declarations.any? { |str| str =~ NO_DOC_ALL_REGEX }
30
- end
31
-
32
- def explicit_doc_comment?
33
- declarations.any? { |str| str =~ DOC_REGEX }
34
- end
35
-
36
- def implicit_nodoc_all_comment?
37
- if parent
38
- parent.explicit_nodoc_all_comment? ||
39
- parent.implicit_nodoc_all_comment?
40
- end
41
- end
42
-
43
- def implicit_nodoc_comment?
44
- return false if explicit_doc_comment?
45
-
46
- if parent
47
- return false if parent.explicit_doc_comment?
48
-
49
- if namespace?
50
- if parent.explicit_nodoc_all_comment?
51
- return true
52
- else
53
- return parent.implicit_nodoc_all_comment?
54
- end
55
- else
56
- if parent.explicit_nodoc_comment?
57
- return true
58
- else
59
- return parent.implicit_nodoc_all_comment?
60
- end
61
- end
62
- end
63
- end
64
-
65
- # Returns all lines in all files declaring the object
66
- #
67
- # @example
68
- # declarations # => ["class Base # :nodoc:", "class Foo < Base"]
69
- #
70
- # @return [Array<String>]
71
- def declarations
72
- @declarations ||= files.map do |f|
73
- get_line_no(f.filename, f.line_no)
74
- end
75
- end
76
-
77
- # Returns a +line_number+ from a file
78
- #
79
- # @param filename [String]
80
- # @param line_number [Fixnum]
81
- # @return [String]
82
- def get_line_no(filename, line_number)
83
- f = File.open(filename)
84
- line_number.times{f.gets}
85
- result = $_
86
- f.close
87
- result.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
88
- end
89
- end
90
- end
91
- end
92
- end
93
- end
@@ -1,60 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Provider
4
- module YARD
5
- # CodeObject::Provider::YARD::Object object represent code objects.
6
- #
7
- module Object
8
- class << self
9
- def clear_cache
10
- @cache = {}
11
- end
12
-
13
- # Returns a Proxy object for the given +yard_object+
14
- #
15
- # @param yard_object [YARD::CodeObject]
16
- # @return [Provider::YARD::Object]
17
- def for(yard_object)
18
- @cache ||= {}
19
- if proxy_object = @cache[cache_key(yard_object)]
20
- proxy_object
21
- else
22
- @cache[cache_key(yard_object)] = class_for(yard_object).new(yard_object)
23
- end
24
- end
25
-
26
- private
27
-
28
- # Returns a Proxy class for the given +yard_object+
29
- #
30
- # @param yard_object [YARD::CodeObject]
31
- # @return [Class]
32
- def class_for(yard_object)
33
- class_name = yard_object.class.to_s.split('::').last
34
- const_get(class_name)
35
- rescue NameError
36
- Base
37
- end
38
-
39
- # Returns a cache key for the given +yard_object+
40
- #
41
- # @param yard_object [YARD::CodeObject]
42
- # @return [String]
43
- def cache_key(yard_object)
44
- yard_object.path
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
52
-
53
- require 'inch/code_object/provider/yard/object/base'
54
- require 'inch/code_object/provider/yard/object/namespace_object'
55
- require 'inch/code_object/provider/yard/object/class_object'
56
- require 'inch/code_object/provider/yard/object/class_variable_object'
57
- require 'inch/code_object/provider/yard/object/constant_object'
58
- require 'inch/code_object/provider/yard/object/method_object'
59
- require 'inch/code_object/provider/yard/object/method_parameter_object'
60
- require 'inch/code_object/provider/yard/object/module_object'
@@ -1,302 +0,0 @@
1
- require 'forwardable'
2
-
3
- module Inch
4
- module CodeObject
5
- module Provider
6
- module YARD
7
- module Object
8
- # @abstract
9
- class Base
10
- extend Forwardable
11
- include YARD::NodocHelper
12
-
13
- # @return [YARD::CodeObjects::Base] the actual (YARD) code object
14
- attr_reader :object
15
-
16
- # @return [String] the codebase's directory
17
- attr_accessor :base_dir
18
-
19
- # Tags considered by wrapper methods like {#has_code_example?}
20
- CONSIDERED_YARD_TAGS = %w(api example param private return since)
21
- AUTO_GENERATED_TAG_NAMES = %w(raise yield)
22
-
23
- # convenient shortcuts to (YARD) code object
24
- def_delegators :object, :type, :namespace, :source, :source_type, :group, :dynamic, :visibility
25
-
26
- # @param object [YARD::CodeObjects::Base] the actual (YARD) code object
27
- def initialize(object)
28
- @object = object
29
- @__api_tag = __api_tag
30
- @__parent = __parent
31
- @__private_tag = __private_tag
32
- end
33
-
34
- # Returns the fullname of the object that the current object
35
- # is an alias for
36
- attr_accessor :aliased_object_fullname
37
-
38
- # Returns the fullnames of the objects that are aliases
39
- # for the current object
40
- def aliases_fullnames
41
- []
42
- end
43
-
44
- def api_tag?
45
- !api_tag.nil?
46
- end
47
-
48
- def api_tag
49
- @__api_tag
50
- end
51
-
52
- # To be overridden
53
- # @see Proxy::NamespaceObject
54
- # @return [CodeObject::Proxy::Base,nil] the child inside the current object or +nil+
55
- def child(name)
56
- nil
57
- end
58
-
59
- # @return [Array,nil] the full names of the children of the current object
60
- def children_fullnames
61
- []
62
- end
63
-
64
- # To be overridden
65
- # @see Proxy::NamespaceObject
66
- def children
67
- []
68
- end
69
-
70
- RUBY_CORE = %w(Array Bignum BasicObject Object Module Class Complex NilClass Numeric String Float Fiber FiberError Continuation Dir File Encoding Enumerator StopIteration Enumerator::Generator Enumerator::Yielder Exception SystemExit SignalException Interrupt StandardError TypeError ArgumentError IndexError KeyError RangeError ScriptError SyntaxError LoadError NotImplementedError NameError NoMethodError RuntimeError SecurityError NoMemoryError EncodingError SystemCallError Encoding::CompatibilityError File::Stat IO Hash ENV IOError EOFError ARGF RubyVM RubyVM::InstructionSequence Math::DomainError ZeroDivisionError FloatDomainError Integer Fixnum Data TrueClass FalseClass Mutex Thread Proc LocalJumpError SystemStackError Method UnboundMethod Binding Process::Status Random Range Rational RegexpError Regexp MatchData Symbol Struct ThreadGroup ThreadError Time Encoding::UndefinedConversionError Encoding::InvalidByteSequenceError Encoding::ConverterNotFoundError Encoding::Converter RubyVM::Env) +
71
- %w(Comparable Kernel File::Constants Enumerable Errno FileTest GC ObjectSpace GC::Profiler IO::WaitReadable IO::WaitWritable Marshal Math Process Process::UID Process::GID Process::Sys Signal)
72
- def core?
73
- RUBY_CORE.include?(name.to_s)
74
- end
75
-
76
- # @return [Docstring]
77
- def docstring
78
- @docstring ||= Docstring.new(object.docstring)
79
- end
80
-
81
- # Returns all files declaring the object in the form of an Array of
82
- # Arrays containing the location of their declaration.
83
- #
84
- # @return [Array<CodeLocation>]
85
- def files
86
- object.files.map do |(filename, line_no)|
87
- CodeLocation.new(base_dir, filename, line_no)
88
- end
89
- rescue ::YARD::CodeObjects::ProxyMethodError
90
- # this error is raised by YARD
91
- # see broken.rb in test fixtures
92
- []
93
- end
94
-
95
- # CodeLocation is a utility class to find declarations of objects in files
96
- class CodeLocation < Struct.new(:base_dir, :relative_path, :line_no)
97
- def filename
98
- File.join(base_dir, relative_path)
99
- end
100
- end
101
-
102
- # Returns the name of the file where the object is declared first
103
- # @return [String] a filename
104
- def filename
105
- # just checking the first file (which is the file where an object
106
- # is first declared)
107
- files.first && files.first.filename
108
- end
109
-
110
- def fullname
111
- @fullname ||= object.path
112
- end
113
-
114
- def name
115
- @name ||= object.name
116
- end
117
-
118
- def has_children?
119
- !children.empty?
120
- end
121
-
122
- def has_code_example?
123
- !tags(:example).empty? ||
124
- docstring.contains_code_example?
125
- end
126
-
127
- def has_doc?
128
- !docstring.empty?
129
- end
130
-
131
- def has_multiple_code_examples?
132
- if tags(:example).size > 1 || docstring.code_examples.size > 1
133
- true
134
- else
135
- if tag = tag(:example)
136
- multi_code_examples?(tag.text)
137
- elsif text = docstring.code_examples.first
138
- multi_code_examples?(text)
139
- else
140
- false
141
- end
142
- end
143
- end
144
-
145
- def has_unconsidered_tags?
146
- !unconsidered_tags.empty?
147
- end
148
-
149
- def in_in_root?
150
- depth == 1
151
- end
152
-
153
- # The depth of the following is 4:
154
- #
155
- # Foo::Bar::Baz#initialize
156
- # ^ ^ ^ ^
157
- # 1 << 2 << 3 << 4
158
- #
159
- # +depth+ answers the question "how many layers of code objects are
160
- # above this one?"
161
- #
162
- # @note top-level counts, that's why Foo has depth 1!
163
- #
164
- # @return [Fixnum] the depth of the object in terms of namespace
165
- def depth
166
- @__depth ||= __depth
167
- end
168
-
169
- # @return [Boolean] +true+ if the object represents a method
170
- def method?
171
- false
172
- end
173
-
174
- # @return [Boolean] +true+ if the object represents a namespace
175
- def namespace?
176
- false
177
- end
178
-
179
- # @return [String] the documentation comments
180
- def original_docstring
181
- object.docstring.all.to_s
182
- end
183
-
184
- def parameters
185
- []
186
- end
187
-
188
- # @return [Array,nil] the parent of the current object or +nil+
189
- def parent
190
- @__parent
191
- end
192
-
193
- def __parent
194
- YARD::Object.for(object.parent) if object.parent
195
- end
196
-
197
- def private?
198
- visibility == :private
199
- end
200
-
201
- def tagged_as_internal_api?
202
- private_api_tag? || docstring.describes_internal_api?
203
- end
204
-
205
- def tagged_as_private?
206
- private_tag? || docstring.describes_private_object?
207
- end
208
-
209
- def protected?
210
- visibility == :protected
211
- end
212
-
213
- def public?
214
- visibility == :public
215
- end
216
-
217
- def in_root?
218
- depth == 1
219
- end
220
-
221
- # @return [Boolean] +true+ if the object has no documentation at all
222
- def undocumented?
223
- original_docstring.empty?
224
- end
225
-
226
- def unconsidered_tag_count
227
- unconsidered_tags.size
228
- end
229
-
230
- def inspect
231
- "#<#{self.class.to_s}: #{fullname}>"
232
- end
233
-
234
- protected
235
-
236
- def multi_code_examples?(text)
237
- text.scan(/\b(#{Regexp.escape(name)})[^_0-9\!\?]/m).size > 1
238
- end
239
-
240
- # @return [Boolean]
241
- # +true+ if the object or its parent is tagged as @private
242
- def private_tag?
243
- !private_tag.nil?
244
- end
245
-
246
- def private_tag
247
- @__private_tag
248
- end
249
-
250
- def private_api_tag?
251
- api_tag && api_tag.text == 'private'
252
- end
253
-
254
- def tag(name)
255
- tags(name).first
256
- end
257
-
258
- def tags(name = nil)
259
- object.tags(name)
260
- rescue ::YARD::CodeObjects::ProxyMethodError
261
- # this error is raised by YARD
262
- # see broken.rb in test fixtures
263
- []
264
- end
265
-
266
- # @return [Array]
267
- # YARD tags that are not already covered by other wrapper methods
268
- def unconsidered_tags
269
- @unconsidered_tags ||= tags.reject do |tag|
270
- auto_generated_tag?(tag) ||
271
- CONSIDERED_YARD_TAGS.include?(tag.tag_name)
272
- end
273
- end
274
-
275
- def __depth(i = 0)
276
- if parent
277
- parent.__depth(i+1)
278
- else
279
- i
280
- end
281
- end
282
-
283
- private
284
-
285
- def __api_tag
286
- tag(:api) || (parent && parent.api_tag)
287
- end
288
-
289
- def __private_tag
290
- tag(:private) || (parent && parent.private_tag)
291
- end
292
-
293
- def auto_generated_tag?(tag)
294
- tag.text.to_s.empty? &&
295
- AUTO_GENERATED_TAG_NAMES.include?(tag.tag_name)
296
- end
297
- end
298
- end
299
- end
300
- end
301
- end
302
- end