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,8 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Proxy
4
- class ModuleObject < NamespaceObject
5
- end
6
- end
7
- end
8
- end
@@ -1,33 +0,0 @@
1
- module Inch
2
- module CodeObject
3
- module Proxy
4
- # a namespace object can have methods and other namespace objects
5
- # inside itself (e.g. classes and modules)
6
- class NamespaceObject < Base
7
- # The wording is a bit redundant, but this means the class and
8
- # instance attributes of the namespace
9
- def attributes
10
- self[:attributes]
11
- end
12
-
13
- MANY_ATTRIBUTES_THRESHOLD = 5
14
- def has_many_attributes?
15
- attributes.size > MANY_ATTRIBUTES_THRESHOLD
16
- end
17
-
18
- MANY_CHILDREN_THRESHOLD = 20
19
- def has_many_children?
20
- children.size > MANY_CHILDREN_THRESHOLD
21
- end
22
-
23
- def has_methods?
24
- children.any?(&:method?)
25
- end
26
-
27
- def pure_namespace?
28
- children.all?(&:namespace?)
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,30 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- # An ObjectSchema describes how important certain parts of the docs are
4
- # for the associated Object
5
- class ObjectSchema
6
- extend Utils::ReadWriteMethods
7
-
8
- rw_methods %w(
9
- docstring
10
- parameters
11
- return_type
12
- return_description
13
- code_example_single
14
- code_example_multi
15
- unconsidered_tag
16
- )
17
-
18
- attr_reader :object
19
-
20
- def initialize(&block)
21
- @block = block
22
- end
23
-
24
- def evaluate(object)
25
- @object = object
26
- instance_eval(&@block)
27
- end
28
- end
29
- end
30
- end
@@ -1,164 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- # @abstract
5
- class Base
6
- extend Forwardable
7
-
8
- MIN_SCORE = 0
9
- MAX_SCORE = 100
10
-
11
- # @return [CodeObject::Proxy::Base]
12
- attr_accessor :object
13
-
14
- class << self
15
- attr_reader :criteria_map
16
-
17
- # Defines the weights during evaluation for different criteria
18
- #
19
- # MethodObject.criteria do
20
- # docstring 0.5
21
- # parameters 0.4
22
- # return_type 0.1
23
- #
24
- # if object.constructor?
25
- # parameters 0.5
26
- # return_type 0.0
27
- # end
28
- # end
29
- #
30
- # @return [void]
31
- def criteria(&block)
32
- @criteria_map ||= {}
33
- @criteria_map[to_s] ||= ObjectSchema.new(&block)
34
- end
35
- end
36
-
37
- # @param object [CodeObject::Proxy::Base]
38
- def initialize(object)
39
- self.object = object
40
- @roles = []
41
- evaluate
42
- end
43
-
44
- # Evaluates the objects and assigns roles
45
- def evaluate
46
- __evaluate(object, relevant_roles)
47
- end
48
-
49
- # @return [Float] the max score that is assignable to +object+
50
- def max_score
51
- @__max_score = __max_score
52
- end
53
-
54
- # @return [Float] the min score that is assignable to +object+
55
- def min_score
56
- @__min_score = __min_score
57
- end
58
-
59
- # @return [Fixnum] the final score for +object+
60
- def score
61
- @__score ||= __score
62
- end
63
-
64
- # @return [Fixnum] the priority for +object+
65
- def priority
66
- @__priority ||= __priority
67
- end
68
-
69
- # @return [Array<Evaluation::Role::Base>]
70
- def roles
71
- @roles
72
- end
73
-
74
- protected
75
-
76
- def add_role(role)
77
- @roles << role
78
- end
79
-
80
- def criteria
81
- @criteria ||= begin
82
- c = self.class.criteria_map[self.class.to_s]
83
- c.evaluate(object)
84
- c
85
- end
86
- end
87
-
88
- def relevant_base_roles
89
- {
90
- Role::Object::InRoot => nil,
91
- Role::Object::Public => nil,
92
- Role::Object::Protected => nil,
93
- Role::Object::Private => nil,
94
- Role::Object::TaggedAsNodoc => nil,
95
- Role::Object::WithDoc => score_for(:docstring),
96
- Role::Object::WithoutDoc => score_for(:docstring),
97
- Role::Object::WithCodeExample => score_for(:code_example_single),
98
- Role::Object::WithMultipleCodeExamples => score_for(:code_example_multi),
99
- Role::Object::WithoutCodeExample => score_for(:code_example_single),
100
- Role::Object::Tagged => score_for_unconsidered_tags,
101
- Role::Object::TaggedAsAPI => nil,
102
- Role::Object::TaggedAsInternalAPI => nil,
103
- Role::Object::TaggedAsPrivate => nil,
104
- Role::Object::Alias => object.alias? ? object.aliased_object.score : nil,
105
- }
106
- end
107
-
108
- def score_for_unconsidered_tags
109
- count = object.unconsidered_tag_count
110
- score_for(:unconsidered_tag) * count
111
- end
112
-
113
- # Returns a key-value pair of Role classes and potential scores for
114
- # each role (can be nil)
115
- #
116
- # @return [Hash]
117
- def relevant_roles
118
- {}
119
- end
120
-
121
- def score_for(criteria_name)
122
- criteria.send(criteria_name) * MAX_SCORE
123
- end
124
-
125
- def __evaluate(object, role_classes)
126
- role_classes.each do |role_class, score|
127
- if role_class.applicable?(object)
128
- add_role role_class.new(object, score)
129
- end
130
- end
131
- end
132
-
133
- # @return [Float] the max score that is assignable to +object+
134
- def __max_score
135
- arr = @roles.map(&:max_score).compact
136
- [MAX_SCORE].concat(arr).min
137
- end
138
-
139
- # @return [Float] the max score that is assignable to +object+
140
- def __min_score
141
- arr = @roles.map(&:min_score).compact
142
- [MIN_SCORE].concat(arr).max
143
- end
144
-
145
- # @return [Float]
146
- def __score
147
- value = @roles.inject(0) { |sum,r| sum + r.score.to_f }.to_i
148
- if value < min_score
149
- min_score
150
- elsif value > max_score
151
- max_score
152
- else
153
- value
154
- end
155
- end
156
-
157
- # @return [Fixnum]
158
- def __priority
159
- @roles.inject(0) { |sum,r| sum + r.priority.to_i }
160
- end
161
- end
162
- end
163
- end
164
- end
@@ -1,8 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- class ClassObject < NamespaceObject
5
- end
6
- end
7
- end
8
- end
@@ -1,19 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- class ClassVariableObject < Base
5
- protected
6
-
7
- def relevant_roles
8
- {
9
- Role::ClassVariable::WithDoc => score_for(:docstring),
10
- Role::ClassVariable::WithoutDoc => score_for(:docstring),
11
- Role::ClassVariable::TaggedAsNodoc => nil,
12
- Role::ClassVariable::Public => nil,
13
- Role::ClassVariable::Private => nil,
14
- }
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- class ConstantObject < Base
5
- protected
6
-
7
- def relevant_roles
8
- {
9
- Role::Constant::WithDoc => score_for(:docstring),
10
- Role::Constant::WithoutDoc => score_for(:docstring),
11
- Role::Constant::TaggedAsNodoc => nil,
12
- Role::Constant::Public => nil,
13
- Role::Constant::Private => nil,
14
- }
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,65 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- class MethodObject < Base
5
- def evaluate
6
- super
7
- evaluate_parameters
8
- end
9
-
10
- protected
11
-
12
- def relevant_roles
13
- relevant_base_roles.merge(relevant_method_roles)
14
- end
15
-
16
- private
17
-
18
- def evaluate_parameters
19
- params = object.parameters
20
- per_param = score_for_single_parameter
21
- params.each do |param|
22
- role_classes = relevant_parameter_roles(param, per_param)
23
- __evaluate(param, role_classes)
24
- end
25
- end
26
-
27
- def relevant_method_roles
28
- {
29
- Role::Method::Constructor => nil,
30
- Role::Method::Getter => nil,
31
- Role::Method::Setter => nil,
32
- Role::Method::Overridden => object.overridden? ? object.overridden_method.score : nil,
33
- Role::Method::WithManyLines => nil,
34
- Role::Method::WithBangName => nil,
35
- Role::Method::WithQuestioningName => nil,
36
- Role::Method::HasAlias => nil,
37
- Role::Method::WithReturnType => score_for(:return_type),
38
- Role::Method::WithoutReturnType => score_for(:return_type),
39
- Role::Method::WithReturnDescription => score_for(:return_description),
40
- Role::Method::WithoutReturnDescription => score_for(:return_description),
41
- Role::Method::WithoutParameters => score_for(:parameters),
42
- Role::Method::WithManyParameters => nil,
43
- }
44
- end
45
-
46
- def relevant_parameter_roles(param, per_param)
47
- {
48
- Role::MethodParameter::WithWrongMention => -score_for(:parameters),
49
- Role::MethodParameter::WithMention => per_param * 0.5,
50
- Role::MethodParameter::WithoutMention => per_param * 0.5,
51
- Role::MethodParameter::WithType => per_param * 0.5,
52
- Role::MethodParameter::WithoutType => per_param * 0.5,
53
- Role::MethodParameter::WithBadName => nil,
54
- Role::MethodParameter::Block => nil,
55
- Role::MethodParameter::Splat => nil,
56
- }
57
- end
58
-
59
- def score_for_single_parameter
60
- @param_score ||= score_for(:parameters) / object.parameters.size
61
- end
62
- end
63
- end
64
- end
65
- end
@@ -1,8 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- class ModuleObject < NamespaceObject
5
- end
6
- end
7
- end
8
- end
@@ -1,27 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- module Proxy
4
- # a namespace object can have methods and other namespace objects
5
- # inside itself (e.g. classes and modules)
6
- class NamespaceObject < Base
7
- protected
8
-
9
- def relevant_roles
10
- relevant_base_roles.merge(relevant_namespace_roles)
11
- end
12
-
13
- def relevant_namespace_roles
14
- {
15
- Role::Namespace::Core => nil,
16
- Role::Namespace::WithManyAttributes => nil,
17
- Role::Namespace::WithoutChildren => nil,
18
- Role::Namespace::WithChildren => nil,
19
- Role::Namespace::WithManyChildren => nil,
20
- Role::Namespace::WithoutMethods => nil,
21
- Role::Namespace::Pure => nil,
22
- }
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,92 +0,0 @@
1
- module Inch
2
- module Evaluation
3
- # Role objects are assigned to evaluations of code objects. They describe
4
- # the object they are attached to.
5
- module Role
6
- # @abstract
7
- class Base
8
- attr_reader :object
9
-
10
- class << self
11
- def applicable_if(symbol = nil, &block)
12
- @applicable_procs ||= {}
13
- @applicable_procs[to_s] = block || symbol.to_proc
14
- end
15
-
16
- def applicable_unless(symbol = nil, &block)
17
- @applicable_procs ||= {}
18
- @applicable_procs[to_s] = proc do |object|
19
- !(block || symbol.to_proc).call(object)
20
- end
21
- end
22
-
23
- def applicable?(object)
24
- @applicable_procs ||= {}
25
- @applicable_procs[to_s].call(object)
26
- end
27
- end
28
-
29
- def initialize(object, value = nil)
30
- @object = object
31
- @value = value
32
- end
33
-
34
- # Returns a maximal score for the object.
35
- # The final score can not be higher than this.
36
- # @note Override this method to that a max_score for the evaluation.
37
- # @return [Float]
38
- def max_score
39
- end
40
-
41
- # Returns a minimal score for the object.
42
- # The final score can not be lower than this.
43
- # @note Override this method to that a min_score for the evaluation.
44
- # @return [Float]
45
- def min_score
46
- end
47
-
48
- # Returns a score that will be added to the associated object's
49
- # overall score.
50
- #
51
- # @note Override this method to assign a score for the role
52
- # @return [Float]
53
- def score
54
- @value.to_f
55
- end
56
-
57
- # Returns a potential score that would be added to the overall score
58
- # if the object had implemented the Role's subject.
59
- #
60
- # @see Role::Missing
61
- # @note Override this method to assign a potential score for the role
62
- # @return [Float]
63
- def potential_score
64
- nil
65
- end
66
-
67
- # Returns a priority that will be added to the associated object's
68
- # overall priority.
69
- #
70
- # @note Override this method to assign a priority for the role
71
- # @return [Fixnum]
72
- def priority
73
- 0
74
- end
75
-
76
- # Returns a suggestion to achieve the potential score that would be
77
- # added to the overall score if the object had implemented the Role's
78
- # subject.
79
- #
80
- # @see Role::Missing
81
- # @return [Float]
82
- def suggestion
83
- nil
84
- end
85
-
86
- def object_type
87
- object.class.to_s.split('::').last.gsub(/Object$/, '').downcase
88
- end
89
- end
90
- end
91
- end
92
- end