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,15 +1,20 @@
1
- require 'inch/version'
1
+ require "inch/version"
2
2
 
3
3
  module Inch
4
4
  end
5
5
 
6
- require 'forwardable'
6
+ require "forwardable"
7
7
 
8
- require 'inch/api'
9
- require 'inch/core_ext'
10
- require 'inch/codebase'
11
- require 'inch/code_object'
12
- require 'inch/evaluation'
8
+ require "inch/api"
9
+ require "inch/core_ext"
10
+ require "inch/codebase"
11
+ require "inch/code_object"
12
+ require "inch/evaluation"
13
13
 
14
- require 'inch/config'
15
- require File.join(File.dirname(__FILE__), '..', 'config', 'defaults.rb')
14
+ require "inch/language"
15
+
16
+ require "inch/config"
17
+ require File.join(File.dirname(__FILE__), "..", "config", "base.rb")
18
+ require File.join(File.dirname(__FILE__), "..", "config", "ruby.rb")
19
+ require File.join(File.dirname(__FILE__), "..", "config", "nodejs.rb")
20
+ require File.join(File.dirname(__FILE__), "..", "config", "elixir.rb")
@@ -23,14 +23,14 @@ module Inch
23
23
  end
24
24
  end
25
25
 
26
- require 'inch/api/options/base'
27
- require 'inch/api/options/filter'
28
- require 'inch/api/options/suggest'
26
+ require "inch/api/options/base"
27
+ require "inch/api/options/filter"
28
+ require "inch/api/options/suggest"
29
29
 
30
- require 'inch/api/compare'
31
- require 'inch/api/filter'
32
- require 'inch/api/get'
33
- require 'inch/api/list'
34
- require 'inch/api/suggest'
35
- require 'inch/api/stats'
36
- require 'inch/api/diff'
30
+ require "inch/api/compare"
31
+ require "inch/api/filter"
32
+ require "inch/api/get"
33
+ require "inch/api/list"
34
+ require "inch/api/suggest"
35
+ require "inch/api/stats"
36
+ require "inch/api/diff"
@@ -1,2 +1,2 @@
1
- require 'inch/api/compare/code_objects'
2
- require 'inch/api/compare/codebases'
1
+ require "inch/api/compare/code_objects"
2
+ require "inch/api/compare/codebases"
@@ -3,11 +3,11 @@ module Inch
3
3
  module Compare
4
4
  class CodeObjects
5
5
  attr_reader :before, :after
6
-
6
+
7
7
  def initialize(object1, object2)
8
8
  @before, @after = object1, object2
9
9
  if @before.object_id == @after.object_id
10
- raise "@before and @after are identical ruby objects. this is bad."
10
+ fail "@before and @after are identical ruby objects. this is bad."
11
11
  end
12
12
  end
13
13
 
@@ -23,7 +23,6 @@ module Inch
23
23
  @after.grade
24
24
  end
25
25
 
26
-
27
26
  def added?
28
27
  @before.nil? && !@after.nil?
29
28
  end
@@ -31,7 +31,7 @@ module Inch
31
31
  end
32
32
 
33
33
  def find(fullname)
34
- comparisons.detect do |comparison|
34
+ comparisons.find do |comparison|
35
35
  comparison.fullname == fullname
36
36
  end
37
37
  end
@@ -1,4 +1,4 @@
1
- require 'inch/utils/shell_helper'
1
+ require "inch/utils/shell_helper"
2
2
 
3
3
  module Inch
4
4
  module API
@@ -16,24 +16,24 @@ module Inch
16
16
  # @param before_rev [String] the 'before' revision
17
17
  # @param after_rev [String,nil] the 'after' revision that the 'before'
18
18
  # one is compared against
19
- def initialize(dir, before_rev, after_rev = nil)
19
+ def initialize(dir, config, before_rev, after_rev = nil)
20
20
  @work_dir = dir
21
- @codebase_old = codebase_for(before_rev)
21
+ @codebase_old = codebase_for(before_rev, config)
22
22
  @codebase_new = if after_rev.nil?
23
- Codebase.parse(work_dir)
24
- else
25
- codebase_for(after_rev)
26
- end
23
+ Codebase.parse(work_dir, config)
24
+ else
25
+ codebase_for(after_rev, config)
26
+ end
27
27
  @comparer = API::Compare::Codebases.new(@codebase_old, @codebase_new)
28
28
  end
29
29
 
30
30
  private
31
31
 
32
- def codebase_for(revision)
33
- if cached = codebase_from_cache(revision)
32
+ def codebase_for(revision, config)
33
+ if (cached = codebase_from_cache(revision))
34
34
  cached
35
35
  else
36
- codebase = codebase_from_copy(work_dir, revision)
36
+ codebase = codebase_from_copy(work_dir, config, revision)
37
37
  filename = Codebase::Serializer.filename(revision)
38
38
  Codebase::Serializer.save(codebase, filename)
39
39
  codebase
@@ -42,17 +42,15 @@ module Inch
42
42
 
43
43
  def codebase_from_cache(revision)
44
44
  filename = Codebase::Serializer.filename(revision)
45
- if File.exist?(filename)
46
- Codebase::Serializer.load(filename)
47
- end
45
+ Codebase::Serializer.load(filename) if File.exist?(filename)
48
46
  end
49
47
 
50
- def codebase_from_copy(original_dir, revision)
48
+ def codebase_from_copy(original_dir, config, revision)
51
49
  codebase = nil
52
50
  Dir.mktmpdir do |tmp_dir|
53
51
  new_dir = copy_work_dir(original_dir, tmp_dir)
54
52
  git_reset(new_dir, revision)
55
- codebase = Codebase.parse(new_dir)
53
+ codebase = Codebase.parse(new_dir, config)
56
54
  end
57
55
  codebase
58
56
  end
@@ -65,7 +63,6 @@ module Inch
65
63
  def git_reset(dir, revision = nil)
66
64
  git dir, "reset --hard #{revision}"
67
65
  end
68
-
69
66
  end
70
67
  end
71
68
  end
@@ -8,7 +8,7 @@ module Inch
8
8
 
9
9
  def initialize(codebase, options)
10
10
  @codebase = codebase
11
- codebase.objects.filter! Options::Filter(options)
11
+ codebase.objects.filter! Options::Filter.new(options)
12
12
  @objects = codebase.objects.to_a
13
13
  @grade_lists = @codebase.grade_lists
14
14
  end
@@ -15,10 +15,10 @@ module Inch
15
15
  # Returns all objects matching the given +object_names+
16
16
  #
17
17
  # @param object_names [Array<String>]
18
- # @return [Array<CodeObject::Proxy::Base>]
18
+ # @return [Array<CodeObject::Proxy>]
19
19
  def find_objects_with_names(object_names)
20
20
  object_names.map do |object_name|
21
- if object = codebase.objects.find(object_name)
21
+ if (object = codebase.objects.find(object_name))
22
22
  object
23
23
  else
24
24
  codebase.objects.starting_with(object_name)
@@ -33,10 +33,10 @@ module Inch
33
33
 
34
34
  def read(options_or_hash, name)
35
35
  value = if options_or_hash.is_a?(Hash)
36
- options_or_hash[name]
37
- else
38
- options_or_hash.send(name)
39
- end
36
+ options_or_hash[name]
37
+ else
38
+ options_or_hash.send(name)
39
+ end
40
40
  instance_variable_set("@#{name}", value)
41
41
  end
42
42
  end
@@ -16,10 +16,6 @@ module Inch
16
16
  attribute :undocumented
17
17
  attribute :depth
18
18
  end
19
-
20
- def self.Filter(options_or_hash)
21
- Filter.new(options_or_hash)
22
- end
23
19
  end
24
20
  end
25
21
  end
@@ -1,4 +1,4 @@
1
- require 'inch/evaluation/proxy/base'
1
+ require "inch/evaluation/proxy"
2
2
 
3
3
  module Inch
4
4
  module API
@@ -14,7 +14,7 @@ module Inch
14
14
  DEFAULT_GRADES_TO_DISPLAY = [:B, :C, :U]
15
15
  DEFAULT_GRADE_WEIGHTS = [0.2, 0.4, 0.4]
16
16
  DEFAULT_OBJECT_MIN_PRIORITY = 0
17
- DEFAULT_OBJECT_MAX_SCORE = ::Inch::Evaluation::Proxy::Base::MAX_SCORE
17
+ DEFAULT_OBJECT_MAX_SCORE = ::Inch::Evaluation::Proxy::MAX_SCORE
18
18
  end
19
19
 
20
20
  include DefaultAttributeValues
@@ -27,10 +27,6 @@ module Inch
27
27
  attribute :object_min_priority, DEFAULT_OBJECT_MIN_PRIORITY
28
28
  attribute :object_max_score, DEFAULT_OBJECT_MAX_SCORE
29
29
  end
30
-
31
- def self.Suggest(options_or_hash)
32
- Suggest.new(options_or_hash)
33
- end
34
30
  end
35
31
  end
36
32
  end
@@ -1,7 +1,6 @@
1
1
  module Inch
2
2
  module API
3
3
  class Stats < Filter
4
-
5
4
  end
6
5
  end
7
6
  end
@@ -1,11 +1,11 @@
1
- require 'inch/utils/weighted_list'
1
+ require "inch/utils/weighted_list"
2
2
 
3
3
  module Inch
4
4
  module API
5
5
  class Suggest < Filter
6
6
  def initialize(codebase, options)
7
7
  super
8
- @options = Options::Suggest(options)
8
+ @options = Options::Suggest.new(options)
9
9
  end
10
10
 
11
11
  def files
@@ -19,7 +19,6 @@ module Inch
19
19
  filter_objects_to_display
20
20
  end
21
21
 
22
-
23
22
  # @return [Array] all the objects that match +@options+
24
23
  def all_objects
25
24
  relevant_objects
@@ -52,15 +51,13 @@ module Inch
52
51
 
53
52
  list = Codebase::Objects.sort_by_priority(weighted_list.to_a.flatten)
54
53
 
55
- if list.size > object_count
56
- list = list[0...object_count]
57
- end
54
+ list = list[0...object_count] if list.size > object_count
58
55
  list
59
56
  end
60
57
 
61
58
  def files_sorted_by_importance
62
59
  list = all_filenames(relevant_objects).uniq.map do |filename|
63
- f = Evaluation::File.for(filename, relevant_objects)
60
+ Evaluation::File.for(filename, relevant_objects)
64
61
  end
65
62
 
66
63
  priority_list = list.select do |f|
@@ -68,7 +65,8 @@ module Inch
68
65
  relevant_priorities.include?(f.priority)
69
66
  end
70
67
 
71
- Codebase::Objects.sort_by_priority(priority_list.empty? ? list : priority_list)
68
+ Codebase::Objects.sort_by_priority(
69
+ priority_list.empty? ? list : priority_list)
72
70
  end
73
71
 
74
72
  def all_filenames(objects)
@@ -87,7 +85,7 @@ module Inch
87
85
  end
88
86
 
89
87
  def grade_list(grade_symbol)
90
- grade_lists.detect { |r| r.grade.to_sym == grade_symbol }
88
+ grade_lists.find { |r| r.grade.to_sym == grade_symbol }
91
89
  end
92
90
 
93
91
  def select_by_priority(list, min_priority)
@@ -99,7 +97,8 @@ module Inch
99
97
  end
100
98
 
101
99
  def relevant_objects
102
- @relevant_objects ||= select_by_priority(codebase.objects, @options.object_min_priority)
100
+ @relevant_objects ||= select_by_priority(codebase.objects,
101
+ @options.object_min_priority)
103
102
  end
104
103
 
105
104
  def relevant_priorities
@@ -11,7 +11,7 @@ module Inch
11
11
  # @return [Fixnum]
12
12
  def get_term_columns(default = 80)
13
13
  str = `stty size`
14
- rows_cols = str.split(' ').map(&:to_i)
14
+ rows_cols = str.split(" ").map(&:to_i)
15
15
  rows_cols[1] || default
16
16
  rescue
17
17
  default
@@ -21,9 +21,9 @@ module Inch
21
21
  end
22
22
  end
23
23
 
24
- require 'inch/cli/arguments'
25
- require 'inch/cli/sparkline_helper'
26
- require 'inch/cli/trace_helper'
27
- require 'inch/cli/yardopts_helper'
24
+ require "inch/cli/arguments"
25
+ require "inch/cli/sparkline_helper"
26
+ require "inch/cli/trace_helper"
27
+ require "inch/cli/yardopts_helper"
28
28
 
29
- require 'inch/cli/command'
29
+ require "inch/cli/command"
@@ -28,10 +28,10 @@ module Inch
28
28
  # @param args [Array<String>]
29
29
  # @return [void]
30
30
  def parse(args)
31
- if first_non_file = args.find_index { |e| !glob_or_file?(e) }
31
+ if (first_non_file = args.find_index { |e| !glob_or_file?(e) })
32
32
  @files = args[0...first_non_file]
33
33
  rest = args[first_non_file..-1]
34
- if first_switch = rest.find_index { |e| switch?(e) }
34
+ if (first_switch = rest.find_index { |e| switch?(e) })
35
35
  @object_names = rest[0...first_switch]
36
36
  @switches = rest[first_switch..-1]
37
37
  else
@@ -1,19 +1,19 @@
1
- require 'inch/cli/command/base'
2
- require 'inch/cli/command/base_list'
3
- require 'inch/cli/command/base_object'
1
+ require "inch/cli/command/base"
2
+ require "inch/cli/command/base_list"
3
+ require "inch/cli/command/base_object"
4
4
 
5
- require 'inch/cli/command/options/base'
6
- require 'inch/cli/command/options/base_list'
7
- require 'inch/cli/command/options/base_object'
5
+ require "inch/cli/command/options/base"
6
+ require "inch/cli/command/options/base_list"
7
+ require "inch/cli/command/options/base_object"
8
8
 
9
- require 'inch/cli/command/output/base'
9
+ require "inch/cli/command/output/base"
10
10
 
11
- require 'inch/cli/command_parser'
11
+ require "inch/cli/command_parser"
12
12
 
13
- require 'inch/cli/command/list'
14
- require 'inch/cli/command/show'
15
- require 'inch/cli/command/stats'
16
- require 'inch/cli/command/suggest'
17
- require 'inch/cli/command/console'
18
- require 'inch/cli/command/inspect'
19
- require 'inch/cli/command/diff'
13
+ require "inch/cli/command/list"
14
+ require "inch/cli/command/show"
15
+ require "inch/cli/command/stats"
16
+ require "inch/cli/command/suggest"
17
+ require "inch/cli/command/console"
18
+ require "inch/cli/command/inspect"
19
+ require "inch/cli/command/diff"
@@ -45,7 +45,8 @@ module Inch
45
45
  # @see #run
46
46
  # @return [Command::Base] the instance that ran
47
47
  def self.run(*args)
48
- command = new
48
+ kwargs = args.last.is_a?(Hash) ? args.pop : {}
49
+ command = new(kwargs)
49
50
  command.run(*args)
50
51
  command
51
52
  end
@@ -59,11 +60,9 @@ module Inch
59
60
  CLI::CommandParser.commands[name] = self
60
61
  end
61
62
 
62
- def initialize
63
- name = self.class.to_s.split('::').last
64
- options_class = Command::Options.const_get(name)
65
- @options = options_class.new
66
- @options.usage = usage
63
+ def initialize(kwargs = {})
64
+ @ui = kwargs[:ui] if kwargs[:ui]
65
+ initialize_cli_options
67
66
  end
68
67
 
69
68
  # Returns a description of the command
@@ -87,9 +86,9 @@ module Inch
87
86
  #
88
87
  # @abstract
89
88
  # @note Override with implementation
90
- # @param *args [Array<String>]
91
- def run(*args)
92
- raise NotImplementedError
89
+ # @param *_args [Array<String>]
90
+ def run(*_args)
91
+ fail NotImplementedError
93
92
  end
94
93
 
95
94
  # Returns a description of the command's usage pattern
@@ -98,6 +97,28 @@ module Inch
98
97
  def usage
99
98
  "Usage: inch #{name} [options]"
100
99
  end
100
+
101
+ protected
102
+
103
+ def initialize_cli_options
104
+ name = self.class.to_s.split("::").last
105
+ options_class = Command::Options.const_get(name)
106
+ @options = options_class.new
107
+ @options.usage = usage
108
+ end
109
+
110
+ # Creates a Config::Codebase object and returns it
111
+ # (merges relevant values of a given +options+ object before).
112
+ #
113
+ # @param options [Options::Base]
114
+ # @return [Config::Codebase]
115
+ def to_config(options)
116
+ config = Config.for(@options.language, Dir.pwd).codebase
117
+ config.included_files = options.paths unless options.paths.empty?
118
+ config.excluded_files = options.excluded unless options.excluded.empty?
119
+ config.read_dump_file = options.read_dump_file
120
+ config
121
+ end
101
122
  end
102
123
  end
103
124
  end