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
@@ -3,6 +3,6 @@ module Inch
3
3
  end
4
4
  end
5
5
 
6
- require 'inch/code_object/converter'
7
- require 'inch/code_object/provider'
8
- require 'inch/code_object/proxy'
6
+ require "inch/code_object/converter"
7
+ require "inch/code_object/provider"
8
+ require "inch/code_object/proxy"
@@ -52,7 +52,7 @@ module Inch
52
52
  unconsidered_tag_count
53
53
  undocumented?
54
54
  visibility
55
- ).map(&:to_sym)
55
+ ).map(&:to_sym)
56
56
 
57
57
  PARAMETER_ATTRIBUTES = %w(
58
58
  name
@@ -62,7 +62,7 @@ module Inch
62
62
  splat?
63
63
  typed?
64
64
  wrongly_mentioned?
65
- ).map(&:to_sym)
65
+ ).map(&:to_sym)
66
66
 
67
67
  # Returns an attributes Hash for a given code object
68
68
  #
@@ -71,16 +71,14 @@ module Inch
71
71
  def self.to_hash(o)
72
72
  attributes = {}
73
73
  OBJECT_ATTRIBUTES.each do |name|
74
- if o.respond_to?(name)
75
- attributes[name] = o.public_send(name)
76
- end
74
+ next unless o.respond_to?(name)
75
+ attributes[name] = o.public_send(name)
77
76
  end
78
77
  attributes[:parameters] = o.parameters.map do |parameter|
79
78
  hash = {}
80
79
  PARAMETER_ATTRIBUTES.each do |pname|
81
- if parameter.respond_to?(pname)
82
- hash[pname] = parameter.public_send(pname)
83
- end
80
+ next unless parameter.respond_to?(pname)
81
+ hash[pname] = parameter.public_send(pname)
84
82
  end
85
83
  hash
86
84
  end
@@ -9,7 +9,7 @@ module Inch
9
9
  # YARD's SourceParser returns ::YARD::CodeObject objects, which are
10
10
  # cast to Provider::YARD::Object::Base objects that can ensure naming
11
11
  # conventions et al. follow certain rules. These objects are then again
12
- # converted into CodeObject::Proxy::Base objects that form the codebase:
12
+ # converted into CodeObject::Proxy objects that form the codebase:
13
13
  #
14
14
  # ::YARD::CodeObject
15
15
  # ↓
@@ -17,20 +17,20 @@ module Inch
17
17
  # ↓
18
18
  # (Hash)
19
19
  # ↓
20
- # ::Inch::CodeObject::Proxy::Base
20
+ # ::Inch::CodeObject::Proxy
21
21
  #
22
22
  #
23
23
  module Provider
24
- def self.parse(dir, config = Inch::Config.codebase, type = :YARD)
25
- provider_for(type).parse(dir, config)
26
- end
27
-
28
- # @return [Module]
29
- def self.provider_for(type)
30
- const_get(type)
24
+ # Parses a codebase to provide objects
25
+ #
26
+ # @param dir [String] the directory to parse
27
+ # @param config [Inch::Config::Codebase]
28
+ # @return [#objects]
29
+ def self.parse(dir, config = Inch::Config.codebase)
30
+ Config.namespace(config.language, :Provider)
31
+ .const_get(config.object_provider)
32
+ .parse(dir, config)
31
33
  end
32
34
  end
33
35
  end
34
36
  end
35
-
36
- require 'inch/code_object/provider/yard'
@@ -3,37 +3,68 @@ module Inch
3
3
  # CodeObject::Proxy object represent code objects in the analaysed
4
4
  # codebase.
5
5
  #
6
- module Proxy
7
- class << self
8
- # Returns a Proxy object for the given +code_object+
9
- #
10
- # @param code_object [YARD::Object::Base]
11
- # @return [CodeObject::Proxy::Base]
12
- def for(code_object)
13
- attributes = Converter.to_hash(code_object)
14
- proxy_object = class_for(code_object).new(attributes)
15
- end
16
-
17
- private
18
-
19
- # Returns a Proxy class for the given +code_object+
20
- #
21
- # @param code_object [YARD::CodeObject]
22
- # @return [Class]
23
- def class_for(code_object)
24
- class_name = code_object.class.to_s.split('::').last
25
- const_get(class_name)
26
- end
6
+ class Proxy
7
+ # Returns a Proxy object for the given +code_object+
8
+ #
9
+ # @param language [String,Symbol]
10
+ # @param code_object [YARD::Object::Base]
11
+ # @param object_lookup [Codebase::Objects]
12
+ # @return [CodeObject::Proxy]
13
+ def self.for(language, code_object, object_lookup)
14
+ attributes = Converter.to_hash(code_object)
15
+ class_for(language, code_object).new(attributes, object_lookup)
16
+ end
17
+
18
+ extend Forwardable
19
+
20
+ # @return [#find]
21
+ # an object that responds to #find to look up objects by their
22
+ # full name
23
+ attr_accessor :object_lookup
24
+
25
+ # @param object_lookup [Codebase::Objects]
26
+ def initialize(attributes = {}, object_lookup = nil)
27
+ @attributes = attributes
28
+ @object_lookup = object_lookup
29
+ end
30
+
31
+ # Returns the attribute for the given +key+
32
+ #
33
+ # @param key [Symbol]
34
+ def [](key)
35
+ @attributes[key]
36
+ end
37
+
38
+ # @return [Symbol] the programming language of the code object
39
+ def language
40
+ raise NotImplementedError
41
+ end
42
+
43
+ # Used to persist the code object
44
+ def marshal_dump
45
+ @attributes
46
+ end
47
+
48
+ # Used to load a persisted code object
49
+ def marshal_load(attributes)
50
+ @attributes = attributes
51
+ end
52
+
53
+ def inspect
54
+ "#<#{self.class}: #{fullname}>"
55
+ end
56
+
57
+ private
58
+
59
+ # Returns a Proxy class for the given +code_object+
60
+ #
61
+ # @param language [String,Symbol]
62
+ # @param code_object [YARD::CodeObject]
63
+ # @return [Class]
64
+ def self.class_for(language, code_object)
65
+ class_name = code_object.class.to_s.split("::").last
66
+ Config.namespace(language, :CodeObject).const_get(class_name)
27
67
  end
28
68
  end
29
69
  end
30
70
  end
31
-
32
- require 'inch/code_object/proxy/base'
33
- require 'inch/code_object/proxy/namespace_object'
34
- require 'inch/code_object/proxy/class_object'
35
- require 'inch/code_object/proxy/class_variable_object'
36
- require 'inch/code_object/proxy/constant_object'
37
- require 'inch/code_object/proxy/method_object'
38
- require 'inch/code_object/proxy/method_parameter_object'
39
- require 'inch/code_object/proxy/module_object'
@@ -5,18 +5,17 @@ module Inch
5
5
  # Parses a codebase
6
6
  #
7
7
  # @param dir [String]
8
- # @param config [Inch::Config::Codebase,nil]
8
+ # @param config [Inch::Config::Codebase]
9
9
  # @return [Codebase::Proxy]
10
- def self.parse(dir, config = nil)
11
- config ||= Config.codebase.clone
10
+ def self.parse(dir, config)
12
11
  config.update_via_yaml(dir)
13
12
  Proxy.parse(dir, config)
14
13
  end
15
14
  end
16
15
  end
17
16
 
18
- require 'inch/codebase/proxy'
19
- require 'inch/codebase/objects'
20
- require 'inch/codebase/objects_filter'
21
- require 'inch/codebase/serializer'
22
-
17
+ require "inch/codebase/proxy"
18
+ require "inch/codebase/object"
19
+ require "inch/codebase/objects"
20
+ require "inch/codebase/objects_filter"
21
+ require "inch/codebase/serializer"
@@ -0,0 +1,60 @@
1
+ require 'inch/code_object/converter'
2
+
3
+ module Inch
4
+ module Codebase
5
+ # An object that holds a code_object as well as it's evaluation
6
+ # and exposes shortcut methods to the commonly asked members of
7
+ # both.
8
+ class Object
9
+ extend Forwardable
10
+
11
+ attr_reader :code_object
12
+
13
+ # @return [String]
14
+ attr_reader :language
15
+
16
+ # @return [Grade]
17
+ # when objects are assigned to GradeLists, this grade is set to
18
+ # enable easier querying for objects of a certain grade
19
+ attr_writer :grade
20
+
21
+ # convenient shortcuts to evalution object
22
+ def_delegators :evaluation, :score, :roles, :priority
23
+
24
+ # convenient shortcuts to code object
25
+ def_delegators :code_object, :object_lookup=
26
+
27
+ # @param language [String,Symbol]
28
+ # @param code_object [YARD::Object::Base]
29
+ # @param object_lookup [Codebase::Objects]
30
+ def initialize(language, code_object, object_lookup)
31
+ @language = language
32
+ @code_object = CodeObject::Proxy.for(language, code_object, object_lookup)
33
+ end
34
+
35
+ def evaluation
36
+ @evaluation ||= Evaluation::Proxy.for(@language, self)
37
+ end
38
+
39
+ # @return [Grade]
40
+ def grade
41
+ @grade ||= Evaluation.new_grade_lists.find do |range|
42
+ range.scores.include?(score)
43
+ end.grade
44
+ end
45
+
46
+ def method_missing(name, *args, &block)
47
+ if code_object.respond_to?(name)
48
+ self.class.class_eval <<-RUBY
49
+ def #{name}(*args, &block)
50
+ code_object.#{name}(*args, &block)
51
+ end
52
+ RUBY
53
+ code_object.send(name, *args, &block)
54
+ else
55
+ super
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -6,19 +6,17 @@ module Inch
6
6
 
7
7
  def_delegators :@list, :each, :empty?, :size
8
8
 
9
- # @param objects [Array<CodeObject::Proxy::Base>]
10
- # @return [Array<CodeObject::Proxy::Base>]
9
+ # @param objects [Array<CodeObject::Proxy>]
10
+ # @return [Array<CodeObject::Proxy>]
11
11
  def self.sort_by_priority(objects)
12
12
  objects.sort_by do |o|
13
13
  [o.priority, o.score, o.fullname.size]
14
14
  end.reverse
15
15
  end
16
16
 
17
- def initialize(objects)
18
- list = objects.map do |o|
19
- proxy = CodeObject::Proxy.for(o)
20
- proxy.object_lookup = self
21
- proxy
17
+ def initialize(language, objects)
18
+ list = objects.map do |code_object|
19
+ Codebase::Object.new(language, code_object, self)
22
20
  end
23
21
  @list = list
24
22
  index_by_fullname
@@ -31,7 +29,7 @@ module Inch
31
29
  # Returns all parsed objects as code object proxies
32
30
  #
33
31
  # @see CodeObject::Proxy.for
34
- # @return [Array<CodeObject::Proxy::Base>]
32
+ # @return [Array<CodeObject::Proxy>]
35
33
  def all
36
34
  @list
37
35
  end
@@ -44,7 +42,7 @@ module Inch
44
42
  # # => returns the code object proxy for Foo#bar
45
43
  #
46
44
  # @param fullname [String] partial fullname/name of an object
47
- # @return [CodeObject::Proxy::Base]
45
+ # @return [CodeObject::Proxy]
48
46
  def find(fullname)
49
47
  @by_fullname[fullname]
50
48
  end
@@ -58,7 +56,7 @@ module Inch
58
56
  # # => returns the code object proxies for all instance methods of Foo
59
57
  #
60
58
  # @param partial_name [String] partial name of an object
61
- # @return [Array<CodeObject::Proxy::Base>]
59
+ # @return [Array<CodeObject::Proxy>]
62
60
  def starting_with(partial_name)
63
61
  all.select { |o| o.fullname.start_with?(partial_name) }
64
62
  end
@@ -1,16 +1,20 @@
1
1
  module Inch
2
2
  module Codebase
3
- # ObjectsFilter can be used to filter a list of objects by given a set of
3
+ # ObjectsFilter can be used to filter a list of objects by a given set of
4
4
  # given +options+
5
5
  class ObjectsFilter
6
+ # @return [API::Options::Base] the filter options
6
7
  attr_reader :options
7
8
 
9
+ # @param list [Array<CodeObject::Proxy>] the unfiltered list
10
+ # @param options [API::Options::Base] the filter options
8
11
  def initialize(list, options)
9
12
  @list = list
10
13
  @options = options
11
14
  filter
12
15
  end
13
16
 
17
+ # @return [Array<CodeObject::Proxy>] the filtered list
14
18
  def objects
15
19
  @list
16
20
  end
@@ -41,16 +45,14 @@ module Inch
41
45
  end
42
46
 
43
47
  def filter_depth
44
- if options.depth
45
- @list = @list.select { |o| o.depth <= options.depth }
46
- end
48
+ @list = @list.select { |o| o.depth <= options.depth } if options.depth
47
49
  end
48
50
 
49
51
  def filter_visibility
50
52
  @list = @list.select do |o|
51
53
  options.visibility.include?(o.visibility)
52
54
  end
53
- if !options.visibility.include?(:private)
55
+ unless options.visibility.include?(:private)
54
56
  @list = @list.reject do |o|
55
57
  o.tagged_as_private?
56
58
  end
@@ -3,8 +3,8 @@ module Inch
3
3
  class Proxy
4
4
  attr_reader :objects
5
5
 
6
- def initialize(provider)
7
- @objects = Codebase::Objects.new(provider.objects)
6
+ def initialize(language, provider)
7
+ @objects = Codebase::Objects.new(language, provider.objects)
8
8
  end
9
9
 
10
10
  def grade_lists
@@ -16,9 +16,9 @@ module Inch
16
16
  lists
17
17
  end
18
18
 
19
- def self.parse(dir = Dir.pwd, config = Inch::Config.codebase)
19
+ def self.parse(dir, config)
20
20
  provider = CodeObject::Provider.parse(dir, config)
21
- new(provider)
21
+ new(config.language, provider)
22
22
  end
23
23
  end
24
24
  end
@@ -9,12 +9,12 @@ module Inch
9
9
 
10
10
  def self.save(codebase, filename)
11
11
  content = Marshal.dump(codebase)
12
- FileUtils.mkdir_p( File.dirname(filename) )
13
- File.open(filename, 'wb') { |file| file.write(content) }
12
+ FileUtils.mkdir_p(File.dirname(filename))
13
+ File.open(filename, "wb") { |file| file.write(content) }
14
14
  end
15
15
 
16
16
  def self.load(filename)
17
- codebase = Marshal.load( File.binread(filename) )
17
+ codebase = Marshal.load(File.binread(filename))
18
18
  codebase.objects.each do |object|
19
19
  object.object_lookup = codebase.objects
20
20
  end
@@ -1,24 +1,55 @@
1
1
  module Inch
2
2
  # Stores the configuration for Inch
3
3
  #
4
- # @see config/defaults.rb
4
+ # @see config/base.rb
5
5
  class Config
6
6
  class << self
7
- attr_accessor :instance
7
+ def instance(language = :ruby)
8
+ if block = @blocks[language.to_s]
9
+ config = Config::Base.new(language)
10
+ config = config.update(&block)
11
+ config
12
+ else
13
+ raise "Language not registered: #{language}"
14
+ end
15
+ end
16
+
17
+ # Registers a configuration block for a given language.
18
+ #
19
+ # @return [void]
20
+ def register(language, &block)
21
+ @blocks ||= {}
22
+ @blocks[language.to_s] = block
23
+ end
24
+
25
+ def codebase(language = :ruby)
26
+ instance(language).codebase
27
+ end
28
+
29
+ def base(&block)
30
+ Config::Base.new(:__base__).update(&block)
31
+ end
8
32
 
9
- def codebase
10
- self.instance ||= Config::Base.new
11
- instance.codebase
33
+ # Returns the Config object for a given +language+.
34
+ # Optionally parses a given +path+ for inch.yml
35
+ #
36
+ # @return [Config::Base]
37
+ def for(language, path = nil)
38
+ config = instance(language)
39
+ config.codebase.update_via_yaml(path) if path
40
+ config
12
41
  end
13
42
 
14
- def run(&block)
15
- self.instance ||= Config::Base.new
16
- instance.update(&block)
17
- instance
43
+ def namespace(language, submodule = nil)
44
+ name = language.to_s.split('_').collect { |w| w.capitalize }.join
45
+ const = ::Inch::Language.const_get(name)
46
+ const = const.const_get(submodule) unless submodule.nil?
47
+ const
18
48
  end
19
49
  end
20
50
  end
21
51
  end
22
52
 
23
- require 'inch/config/base'
24
- require 'inch/config/codebase'
53
+ require "inch/config/base"
54
+ require "inch/config/evaluation"
55
+ require "inch/config/codebase"