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
@@ -4,49 +4,28 @@ module Inch
4
4
  # @see config/defaults.rb
5
5
  class Config
6
6
  class Base
7
+ attr_reader :language
7
8
 
8
- def update(&block)
9
- instance_eval(&block)
10
- end
11
-
12
- def development?
13
- @development
9
+ def initialize(language)
10
+ @language = language.to_sym
14
11
  end
15
12
 
16
- def development!
17
- @development = true
13
+ def update(&block)
14
+ instance_eval(&block)
15
+ self
18
16
  end
19
17
 
20
18
  def codebase(&block)
21
- @codebase ||= Config::Codebase.new
19
+ @codebase ||= Config::Codebase.new(@language)
22
20
  @codebase.update(&block) if block
23
21
  @codebase
24
22
  end
25
23
 
26
24
  def evaluation(&block)
27
- @evaluation ||= Evaluation.new
25
+ @evaluation ||= Config::Evaluation.new(@language)
28
26
  @evaluation.update(&block) if block
29
27
  @evaluation
30
28
  end
31
-
32
- class Evaluation
33
- def update(&block)
34
- instance_eval(&block)
35
- end
36
-
37
- def grade(symbol, &block)
38
- ::Inch::Evaluation::Grade.grade(symbol, &block)
39
- end
40
-
41
- def priority(symbol, &block)
42
- ::Inch::Evaluation::PriorityRange.priority_range(symbol, &block)
43
- end
44
-
45
- def schema(constant_name, &block)
46
- constant = ::Inch::Evaluation::Proxy.const_get(constant_name)
47
- constant.criteria(&block)
48
- end
49
- end
50
29
  end
51
30
  end
52
31
  end
@@ -2,12 +2,15 @@ module Inch
2
2
  class Config
3
3
  # Stores the configuration for an individual single codebase
4
4
  class Codebase
5
- attr_reader :included_files
6
- attr_reader :excluded_files
5
+ attr_accessor :language
6
+ attr_accessor :included_files
7
+ attr_accessor :excluded_files
8
+ attr_accessor :read_dump_file
7
9
 
8
10
  YAML_FILE = ".inch.yml"
9
11
 
10
- def initialize(included = nil, excluded = nil)
12
+ def initialize(language = :ruby, included = nil, excluded = nil)
13
+ @language = language
11
14
  @included_files = included || []
12
15
  @excluded_files = excluded || []
13
16
  end
@@ -22,13 +25,21 @@ module Inch
22
25
  YAML.load(File.read(yaml_file)) if File.exist?(yaml_file)
23
26
  end
24
27
 
28
+ # Update this Codebase config with the given block.
29
+ # @return [void]
25
30
  def update(&block)
26
31
  instance_eval(&block)
27
32
  end
28
33
 
34
+ # Search the given +dir+ for YAML_FILE and
35
+ # update this Codebase config with the contents if the file is found.
36
+ #
37
+ # @param dir [String] directory to search for the file
38
+ # @return [void]
29
39
  def update_via_yaml(dir)
30
- if yaml = self.class.yaml(dir)
40
+ if (yaml = self.class.yaml(dir))
31
41
  Dir.chdir(dir) do
42
+ update_language yaml["language"]
32
43
  update_files yaml["files"]
33
44
  end
34
45
  end
@@ -42,6 +53,15 @@ module Inch
42
53
  @excluded_files.concat(files).flatten!
43
54
  end
44
55
 
56
+ # Sets the object provider (e.g. :YARD)
57
+ #
58
+ # @param sym [Symbol] the object provider
59
+ # @return [Symbol] the object provider
60
+ def object_provider(sym = nil)
61
+ return @object_provider if sym.nil?
62
+ @object_provider = sym
63
+ end
64
+
45
65
  private
46
66
 
47
67
  def expand_files(files)
@@ -57,9 +77,14 @@ module Inch
57
77
 
58
78
  def update_files(files)
59
79
  return if files.nil?
60
- include_files expand_files(files["included"]) if files["included"]
61
- exclude_files expand_files(files["excluded"]) if files["excluded"]
80
+ @included_files = expand_files(files["included"]) if files["included"]
81
+ @excluded_files = expand_files(files["excluded"]) if files["excluded"]
82
+ end
83
+
84
+ def update_language(language)
85
+ return if language.nil?
86
+ @language = language
62
87
  end
63
88
  end
64
89
  end
65
- end
90
+ end
@@ -0,0 +1,61 @@
1
+ module Inch
2
+ class Config
3
+ class Evaluation
4
+ def initialize(language)
5
+ @language = language
6
+ @criteria_blocks = {}
7
+ end
8
+
9
+ def update(&block)
10
+ instance_eval(&block)
11
+ end
12
+
13
+ def grade(symbol, &block)
14
+ ::Inch::Evaluation::Grade.grade(symbol, &block)
15
+ end
16
+
17
+ def priority(symbol, &block)
18
+ ::Inch::Evaluation::PriorityRange.priority_range(symbol, &block)
19
+ end
20
+
21
+ def schema(constant_name, &block)
22
+ @criteria_blocks[constant_name.to_s] = Criteria.new(&block)
23
+ end
24
+
25
+ def criteria_for(constant_name)
26
+ @criteria_blocks[constant_name.to_s]
27
+ end
28
+
29
+ # An Criteria describes how important certain parts of the docs are
30
+ # for the associated Object
31
+ class Criteria
32
+ extend Utils::ReadWriteMethods
33
+
34
+ rw_methods %w(
35
+ docstring
36
+ parameters
37
+ return_type
38
+ return_description
39
+ code_example_single
40
+ code_example_multi
41
+ unconsidered_tag
42
+ )
43
+
44
+ attr_reader :object
45
+
46
+ def initialize(&block)
47
+ @block = block
48
+ end
49
+
50
+ def evaluate(object)
51
+ @object = object
52
+ instance_eval(&@block)
53
+ # we are "deleting" the block/Proc here because it can't be
54
+ # serialized by Marshal
55
+ # TODO: find a nicer way to achieve this
56
+ @block = nil
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1 +1 @@
1
- require 'inch/core_ext/string'
1
+ require "inch/core_ext/string"
@@ -1,3 +1,3 @@
1
- require 'term/ansicolor'
1
+ require "term/ansicolor"
2
2
 
3
3
  String.send(:include, Term::ANSIColor)
@@ -2,34 +2,26 @@ module Inch
2
2
  # The Evaluation module concerns itself with the evaluation of code objects
3
3
  # with regard to their inline code documentation
4
4
  module Evaluation
5
- def self.for(code_object)
6
- class_for(code_object).new(code_object)
5
+ def self.for(language, code_object)
6
+ class_for(language, code_object).new(code_object)
7
7
  end
8
8
 
9
9
  private
10
10
 
11
- def self.class_for(code_object)
12
- class_name = code_object.class.to_s.split('::').last
13
- const_get(class_name)
11
+ def self.class_for(language, code_object)
12
+ class_name = code_object.class.to_s.split("::").last
13
+ language_namespace = Evaluation::Ruby
14
+ language_namespace.const_get(class_name)
14
15
  end
15
16
  end
16
17
  end
17
18
 
18
- require 'inch/utils/read_write_methods'
19
+ require "inch/utils/read_write_methods"
19
20
 
20
- require 'inch/evaluation/file'
21
- require 'inch/evaluation/grade'
22
- require 'inch/evaluation/grade_list'
23
- require 'inch/evaluation/object_schema'
24
- require 'inch/evaluation/priority_range'
21
+ require "inch/evaluation/file"
22
+ require "inch/evaluation/grade"
23
+ require "inch/evaluation/grade_list"
24
+ require "inch/evaluation/priority_range"
25
25
 
26
- require 'inch/evaluation/role/base'
27
- require 'inch/evaluation/role/missing'
28
- require 'inch/evaluation/role/object'
29
- require 'inch/evaluation/role/method'
30
- require 'inch/evaluation/role/method_parameter'
31
- require 'inch/evaluation/role/namespace'
32
- require 'inch/evaluation/role/constant'
33
- require 'inch/evaluation/role/class_variable'
34
-
35
- require 'inch/evaluation/proxy'
26
+ require "inch/evaluation/proxy"
27
+ require "inch/evaluation/role"
@@ -1,5 +1,7 @@
1
1
  module Inch
2
2
  module Evaluation
3
+ # Evaluation::File is used in the Suggest API/CLI to determine
4
+ # the importance of files
3
5
  class File
4
6
  attr_accessor :filename, :objects
5
7
 
@@ -16,7 +18,7 @@ module Inch
16
18
  end
17
19
 
18
20
  #
19
- # grade, priority, and score are not meant to be displayed in the CLI
21
+ # grade, priority and score are not meant to be displayed in the CLI
20
22
  # they are just for internal evaluation purposes
21
23
  #
22
24
 
@@ -50,7 +52,7 @@ module Inch
50
52
  class << self
51
53
  def for(filename, objects)
52
54
  @cache ||= {}
53
- if file = @cache[filename]
55
+ if (file = @cache[filename])
54
56
  file
55
57
  else
56
58
  @cache[filename] = new(filename, objects)
@@ -6,16 +6,16 @@ module Inch
6
6
  class GradeList < Struct.new(:grade)
7
7
  extend Forwardable
8
8
 
9
- def_delegators :grade, :scores, :label, :color, :bg_color,
10
- :to_s, :to_sym
9
+ def_delegators :grade,
10
+ :scores, :label, :color, :bg_color, :to_s, :to_sym
11
11
 
12
12
  # Returns code_objects that received a score with the defined +scores+
13
13
  attr_reader :objects
14
14
 
15
15
  # Assigns code_objects that received a score with the defined +scores+
16
16
  #
17
- # @param arr [Array<CodeObject::Proxy::Base>]
18
- # @return [Array<CodeObject::Proxy::Base>]
17
+ # @param arr [Array<CodeObject::Proxy>]
18
+ # @return [Array<CodeObject::Proxy>]
19
19
  def objects=(arr)
20
20
  arr.each { |o| o.grade = grade }
21
21
  @objects = arr
@@ -1,5 +1,8 @@
1
1
  module Inch
2
2
  module Evaluation
3
+ # PriorityRange objects are used to associate a given
4
+ # range of priorities with a symbol and an arrow.
5
+ #
3
6
  class PriorityRange
4
7
  extend Utils::ReadWriteMethods
5
8
  extend Forwardable
@@ -2,25 +2,150 @@ module Inch
2
2
  # The Evaluation module concerns itself with the evaluation of code objects
3
3
  # with regard to their inline code documentation
4
4
  module Evaluation
5
- module Proxy
6
- def self.for(code_object)
7
- class_for(code_object).new(code_object)
5
+ # Base class for evaluations. This class provides the evaluation's
6
+ # process structure.
7
+ #
8
+ # @abstract
9
+ class Proxy
10
+ # Returns a Proxy object for the given +code_object+
11
+ #
12
+ # @param language [String,Symbol]
13
+ # @param object [Codebase::Object]
14
+ # @return [Evaluation::Proxy]
15
+ def self.for(language, object)
16
+ class_for(language, object.code_object).new(object)
17
+ end
18
+
19
+ extend Forwardable
20
+
21
+ MIN_SCORE = 0
22
+ MAX_SCORE = 100
23
+
24
+ # @return [Codebase::Object]
25
+ attr_reader :object
26
+
27
+ # @return [Array<Evaluation::Role::Base>]
28
+ attr_reader :roles
29
+
30
+ # @param object [Codebase::Object]
31
+ def initialize(object)
32
+ @object = object
33
+ evaluation_config = Config.for(object.language).evaluation
34
+ @criteria = eval_criteria(evaluation_config)
35
+ @roles = []
36
+ evaluate
37
+ end
38
+
39
+ # Evaluates the objects and assigns roles
40
+ # @note This is its own method so it can be overridden.
41
+ # @return [void]
42
+ def evaluate
43
+ __evaluate(object, relevant_roles)
44
+ end
45
+
46
+ # @return [Float] the max score that is assignable to +object+
47
+ def max_score
48
+ @__max_score = __max_score
49
+ end
50
+
51
+ # @return [Float] the min score that is assignable to +object+
52
+ def min_score
53
+ @__min_score = __min_score
54
+ end
55
+
56
+ # @return [Fixnum] the final score for +object+
57
+ def score
58
+ @__score ||= __score
59
+ end
60
+
61
+ # @return [Fixnum] the priority for +object+
62
+ def priority
63
+ @__priority ||= __priority
64
+ end
65
+
66
+ protected
67
+
68
+ def add_role(role)
69
+ @roles << role
70
+ end
71
+
72
+ # Evaluates a Criteria object with the object so that it can
73
+ # give us scores for docstring, return_type, etc.
74
+ #
75
+ # @param config [Config::Evaluation]
76
+ # @return [Evaluation::Criteria]
77
+ def eval_criteria(config)
78
+ object_type = self.class.to_s.split('::').last
79
+ c = config.criteria_for(object_type)
80
+ c.evaluate(object)
81
+ c
82
+ end
83
+
84
+ # Returns a key-value pair of Role classes and potential scores for
85
+ # each role (can be nil)
86
+ #
87
+ # @see #evaluate
88
+ # @return [Hash]
89
+ def relevant_roles
90
+ {}
91
+ end
92
+
93
+ # Returns a score for a given criterion.
94
+ #
95
+ # @param criterion_name [String] e.g. 'docstring' or 'return_type'
96
+ # @return [Float]
97
+ def score_for(criterion_name)
98
+ @criteria.send(criterion_name) * MAX_SCORE
99
+ end
100
+
101
+ # Iterates over the given +role_classes+ and assigns the individual
102
+ # roles, if applicable.
103
+ #
104
+ # @param object [Codebase::Object]
105
+ # @param role_classes [Hash]
106
+ # @return [void]
107
+ def __evaluate(object, role_classes)
108
+ role_classes.each do |role_class, score|
109
+ next unless role_class.applicable?(object)
110
+ add_role role_class.new(object, score)
111
+ end
112
+ end
113
+
114
+ # @return [Float] the max score that is assignable to +object+
115
+ def __max_score
116
+ arr = @roles.map(&:max_score).compact
117
+ [MAX_SCORE].concat(arr).min
118
+ end
119
+
120
+ # @return [Float] the max score that is assignable to +object+
121
+ def __min_score
122
+ arr = @roles.map(&:min_score).compact
123
+ [MIN_SCORE].concat(arr).max
124
+ end
125
+
126
+ # @return [Float]
127
+ def __score
128
+ value = @roles.reduce(0) { |sum, r| sum + r.score.to_f }.to_i
129
+ if value < min_score
130
+ min_score
131
+ elsif value > max_score
132
+ max_score
133
+ else
134
+ value
135
+ end
136
+ end
137
+
138
+ # @return [Fixnum]
139
+ def __priority
140
+ @roles.reduce(0) { |sum, r| sum + r.priority.to_i }
8
141
  end
9
142
 
10
143
  private
11
144
 
12
- def self.class_for(code_object)
13
- class_name = code_object.class.to_s.split('::').last
14
- const_get(class_name)
145
+ def self.class_for(language, code_object)
146
+ class_name = code_object.class.to_s.split("::").last
147
+ Config.namespace(language, :Evaluation).const_get(class_name)
15
148
  end
16
149
  end
17
150
  end
18
151
  end
19
-
20
- require 'inch/evaluation/proxy/base'
21
- require 'inch/evaluation/proxy/namespace_object'
22
- require 'inch/evaluation/proxy/class_object'
23
- require 'inch/evaluation/proxy/class_variable_object'
24
- require 'inch/evaluation/proxy/constant_object'
25
- require 'inch/evaluation/proxy/method_object'
26
- require 'inch/evaluation/proxy/module_object'