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.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +94 -0
- data/CHANGELOG.md +26 -2
- data/Gemfile +5 -2
- data/README.md +3 -3
- data/Rakefile +6 -2
- data/bin/inch +3 -3
- data/config/{example.yml → .inch.yml.sample} +1 -0
- data/config/base.rb +53 -0
- data/config/elixir.rb +43 -0
- data/config/nodejs.rb +10 -0
- data/config/{defaults.rb → ruby.rb} +5 -54
- data/inch.gemspec +7 -7
- data/lib/inch.rb +14 -9
- data/lib/inch/api.rb +10 -10
- data/lib/inch/api/compare.rb +2 -2
- data/lib/inch/api/compare/code_objects.rb +2 -3
- data/lib/inch/api/compare/codebases.rb +1 -1
- data/lib/inch/api/diff.rb +13 -16
- data/lib/inch/api/filter.rb +1 -1
- data/lib/inch/api/get.rb +2 -2
- data/lib/inch/api/options/base.rb +4 -4
- data/lib/inch/api/options/filter.rb +0 -4
- data/lib/inch/api/options/suggest.rb +2 -6
- data/lib/inch/api/stats.rb +0 -1
- data/lib/inch/api/suggest.rb +9 -10
- data/lib/inch/cli.rb +6 -6
- data/lib/inch/cli/arguments.rb +2 -2
- data/lib/inch/cli/command.rb +15 -15
- data/lib/inch/cli/command/base.rb +30 -9
- data/lib/inch/cli/command/base_list.rb +2 -2
- data/lib/inch/cli/command/console.rb +5 -5
- data/lib/inch/cli/command/diff.rb +9 -9
- data/lib/inch/cli/command/inspect.rb +5 -4
- data/lib/inch/cli/command/list.rb +4 -4
- data/lib/inch/cli/command/options/base.rb +17 -16
- data/lib/inch/cli/command/options/base_list.rb +9 -5
- data/lib/inch/cli/command/options/console.rb +4 -3
- data/lib/inch/cli/command/options/diff.rb +8 -6
- data/lib/inch/cli/command/options/inspect.rb +2 -2
- data/lib/inch/cli/command/options/list.rb +3 -2
- data/lib/inch/cli/command/options/show.rb +2 -2
- data/lib/inch/cli/command/options/stats.rb +2 -1
- data/lib/inch/cli/command/options/suggest.rb +6 -3
- data/lib/inch/cli/command/output/base.rb +4 -6
- data/lib/inch/cli/command/output/console.rb +6 -7
- data/lib/inch/cli/command/output/diff.rb +6 -6
- data/lib/inch/cli/command/output/inspect.rb +6 -8
- data/lib/inch/cli/command/output/list.rb +0 -1
- data/lib/inch/cli/command/output/show.rb +4 -5
- data/lib/inch/cli/command/output/stats.rb +21 -21
- data/lib/inch/cli/command/output/suggest.rb +31 -28
- data/lib/inch/cli/command/show.rb +4 -4
- data/lib/inch/cli/command/stats.rb +4 -4
- data/lib/inch/cli/command/suggest.rb +6 -6
- data/lib/inch/cli/command_parser.rb +6 -5
- data/lib/inch/cli/sparkline_helper.rb +6 -6
- data/lib/inch/cli/trace_helper.rb +1 -1
- data/lib/inch/cli/yardopts_helper.rb +4 -3
- data/lib/inch/code_object.rb +3 -3
- data/lib/inch/code_object/converter.rb +6 -8
- data/lib/inch/code_object/provider.rb +11 -11
- data/lib/inch/code_object/proxy.rb +61 -30
- data/lib/inch/codebase.rb +7 -8
- data/lib/inch/codebase/object.rb +60 -0
- data/lib/inch/codebase/objects.rb +8 -10
- data/lib/inch/codebase/objects_filter.rb +7 -5
- data/lib/inch/codebase/proxy.rb +4 -4
- data/lib/inch/codebase/serializer.rb +3 -3
- data/lib/inch/config.rb +42 -11
- data/lib/inch/config/base.rb +8 -29
- data/lib/inch/config/codebase.rb +32 -7
- data/lib/inch/config/evaluation.rb +61 -0
- data/lib/inch/core_ext.rb +1 -1
- data/lib/inch/core_ext/string.rb +1 -1
- data/lib/inch/evaluation.rb +13 -21
- data/lib/inch/evaluation/file.rb +4 -2
- data/lib/inch/evaluation/grade_list.rb +4 -4
- data/lib/inch/evaluation/priority_range.rb +3 -0
- data/lib/inch/evaluation/proxy.rb +139 -14
- data/lib/inch/evaluation/role.rb +99 -0
- data/lib/inch/language.rb +3 -0
- data/lib/inch/language/elixir/code_object/base.rb +197 -0
- data/lib/inch/language/elixir/code_object/function_object.rb +74 -0
- data/lib/inch/language/elixir/code_object/module_object.rb +23 -0
- data/lib/inch/language/elixir/code_object/type_object.rb +11 -0
- data/lib/inch/language/elixir/evaluation/base.rb +28 -0
- data/lib/inch/language/elixir/evaluation/function_object.rb +31 -0
- data/lib/inch/language/elixir/evaluation/module_object.rb +27 -0
- data/lib/inch/language/elixir/evaluation/type_object.rb +11 -0
- data/lib/inch/language/elixir/import.rb +24 -0
- data/lib/inch/language/elixir/provider/reader.rb +19 -0
- data/lib/inch/language/elixir/provider/reader/object.rb +63 -0
- data/lib/inch/language/elixir/provider/reader/object/base.rb +191 -0
- data/lib/inch/language/elixir/provider/reader/object/function_object.rb +26 -0
- data/lib/inch/language/elixir/provider/reader/object/module_object.rb +22 -0
- data/lib/inch/language/elixir/provider/reader/object/type_object.rb +15 -0
- data/lib/inch/language/elixir/provider/reader/parser.rb +55 -0
- data/lib/inch/language/elixir/roles/base.rb +32 -0
- data/lib/inch/language/elixir/roles/function.rb +112 -0
- data/lib/inch/language/elixir/roles/module.rb +64 -0
- data/lib/inch/language/elixir/roles/object.rb +76 -0
- data/lib/inch/language/elixir/roles/type.rb +13 -0
- data/lib/inch/language/nodejs/import.rb +8 -0
- data/lib/inch/language/nodejs/provider/jsdoc.rb +19 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object.rb +55 -0
- data/lib/inch/language/nodejs/provider/jsdoc/object/base.rb +191 -0
- data/lib/inch/language/nodejs/provider/jsdoc/parser.rb +59 -0
- data/lib/inch/language/ruby/code_object/base.rb +197 -0
- data/lib/inch/language/ruby/code_object/class_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/class_variable_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/constant_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/method_object.rb +85 -0
- data/lib/inch/language/ruby/code_object/method_parameter_object.rb +64 -0
- data/lib/inch/language/ruby/code_object/module_object.rb +10 -0
- data/lib/inch/language/ruby/code_object/namespace_object.rb +35 -0
- data/lib/inch/language/ruby/evaluation/base.rb +45 -0
- data/lib/inch/language/ruby/evaluation/class_object.rb +10 -0
- data/lib/inch/language/ruby/evaluation/class_variable_object.rb +21 -0
- data/lib/inch/language/ruby/evaluation/constant_object.rb +21 -0
- data/lib/inch/language/ruby/evaluation/method_object.rb +74 -0
- data/lib/inch/language/ruby/evaluation/module_object.rb +10 -0
- data/lib/inch/language/ruby/evaluation/namespace_object.rb +30 -0
- data/lib/inch/language/ruby/import.rb +34 -0
- data/lib/inch/language/ruby/provider/yard.rb +58 -0
- data/lib/inch/language/ruby/provider/yard/docstring.rb +162 -0
- data/lib/inch/language/ruby/provider/yard/nodoc_helper.rb +97 -0
- data/lib/inch/language/ruby/provider/yard/object.rb +63 -0
- data/lib/inch/language/ruby/provider/yard/object/base.rb +325 -0
- data/lib/inch/language/ruby/provider/yard/object/class_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/class_variable_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/constant_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/method_object.rb +170 -0
- data/lib/inch/language/ruby/provider/yard/object/method_parameter_object.rb +94 -0
- data/lib/inch/language/ruby/provider/yard/object/method_signature.rb +120 -0
- data/lib/inch/language/ruby/provider/yard/object/module_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/object/namespace_object.rb +46 -0
- data/lib/inch/language/ruby/provider/yard/object/root_object.rb +14 -0
- data/lib/inch/language/ruby/provider/yard/parser.rb +71 -0
- data/lib/inch/language/ruby/roles/base.rb +17 -0
- data/lib/inch/language/ruby/roles/class_variable.rb +53 -0
- data/lib/inch/language/ruby/roles/constant.rb +53 -0
- data/lib/inch/language/ruby/roles/method.rb +112 -0
- data/lib/inch/language/ruby/roles/method_parameter.rb +84 -0
- data/lib/inch/language/ruby/roles/missing.rb +24 -0
- data/lib/inch/language/ruby/roles/namespace.rb +89 -0
- data/lib/inch/language/ruby/roles/object.rb +120 -0
- data/lib/inch/rake.rb +2 -2
- data/lib/inch/rake/suggest.rb +7 -2
- data/lib/inch/utils/buffered_ui.rb +16 -0
- data/lib/inch/utils/shell_helper.rb +1 -1
- data/lib/inch/utils/ui.rb +5 -5
- data/lib/inch/utils/weighted_list.rb +2 -3
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/{code_examples → ruby/code_examples}/lib/foo.rb +0 -0
- data/test/fixtures/{diff1 → ruby/diff1}/lib/diff1.rb +0 -0
- data/test/fixtures/{diff2 → ruby/diff2}/lib/diff2.rb +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/.inch.yml +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/bar.rb +0 -0
- data/test/fixtures/{inch-yml → ruby/inch-yml}/foo/vendor/base.rb +0 -0
- data/test/fixtures/{parameters → ruby/parameters}/lib/foo.rb +0 -0
- data/test/fixtures/{readme → ruby/readme}/lib/foo.rb +0 -0
- data/test/fixtures/{really_good → ruby/really_good}/lib/foo.rb +0 -0
- data/test/fixtures/{really_good_pedantic → ruby/really_good_pedantic}/lib/foo.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/README +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/broken.rb +11 -19
- data/test/fixtures/ruby/simple/lib/broken_ruby_2_0_features.rb +7 -0
- data/test/fixtures/ruby/simple/lib/directives.rb +8 -0
- data/test/fixtures/{simple → ruby/simple}/lib/foo.rb +22 -1
- data/test/fixtures/{simple → ruby/simple}/lib/nodoc.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/role_methods.rb +0 -0
- data/test/fixtures/{simple → ruby/simple}/lib/role_namespaces.rb +0 -0
- data/test/fixtures/{visibility → ruby/visibility}/lib/foo.rb +0 -0
- data/test/fixtures/{yardopts → ruby/yardopts}/.yardopts +0 -0
- data/test/fixtures/{yardopts → ruby/yardopts}/foo/bar.rb +0 -0
- data/test/integration/api/compare/codebases.rb +3 -3
- data/test/integration/cli/command/console_test.rb +6 -6
- data/test/integration/cli/command/diff_test.rb +62 -0
- data/test/integration/cli/command/inspect_test.rb +5 -6
- data/test/integration/cli/command/list_test.rb +4 -5
- data/test/integration/cli/command/show_test.rb +5 -5
- data/test/integration/cli/command/stats_test.rb +3 -3
- data/test/integration/cli/command/suggest_test.rb +13 -13
- data/test/integration/stats_options_test.rb +4 -4
- data/test/integration/visibility_options_test.rb +14 -14
- data/test/shared/base_list.rb +4 -3
- data/test/test_helper.rb +13 -13
- data/test/unit/api/filter_test.rb +7 -7
- data/test/unit/api/get_test.rb +1 -1
- data/test/unit/api/list_test.rb +1 -1
- data/test/unit/api/options/base_test.rb +3 -3
- data/test/unit/api/stats_test.rb +1 -1
- data/test/unit/api/suggest_test.rb +3 -3
- data/test/unit/cli/arguments_test.rb +2 -2
- data/test/unit/cli/command/base_test.rb +1 -1
- data/test/unit/cli/command/options/base_list_test.rb +2 -2
- data/test/unit/cli/command/options/base_object_test.rb +1 -1
- data/test/unit/cli/command/options/base_test.rb +1 -1
- data/test/unit/cli/command_parser_test.rb +3 -3
- data/test/unit/cli/trace_helper_test.rb +1 -1
- data/test/unit/cli/yardopts_helper_test.rb +6 -5
- data/test/unit/code_object/converter_test.rb +1 -1
- data/test/unit/code_object/provider_test.rb +2 -2
- data/test/unit/code_object/proxy_test.rb +2 -2
- data/test/unit/codebase/objects_test.rb +2 -2
- data/test/unit/codebase/proxy_test.rb +7 -5
- data/test/unit/config/codebase_test.rb +4 -4
- data/test/unit/config_test.rb +28 -0
- data/test/unit/evaluation/{role/base_test.rb → role_test.rb} +7 -7
- data/test/unit/{code_object/proxy → language/ruby/code_object}/method_object_test.rb +66 -21
- data/test/unit/{code_object → language/ruby}/provider/yard/docstring_test.rb +74 -38
- data/test/unit/{code_object → language/ruby}/provider/yard/nodoc_helper_test.rb +9 -7
- data/test/unit/{code_object → language/ruby}/provider/yard/object/method_object_test.rb +21 -11
- data/test/unit/language/ruby/provider/yard_test.rb +25 -0
- data/test/unit/utils/buffered_ui_test.rb +48 -0
- data/test/unit/utils/ui_test.rb +7 -7
- data/test/unit/utils/weighted_list_test.rb +7 -4
- metadata +139 -93
- data/lib/inch/code_object/provider/yard.rb +0 -57
- data/lib/inch/code_object/provider/yard/docstring.rb +0 -133
- data/lib/inch/code_object/provider/yard/nodoc_helper.rb +0 -93
- data/lib/inch/code_object/provider/yard/object.rb +0 -60
- data/lib/inch/code_object/provider/yard/object/base.rb +0 -302
- data/lib/inch/code_object/provider/yard/object/class_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/class_variable_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/constant_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/method_object.rb +0 -153
- data/lib/inch/code_object/provider/yard/object/method_parameter_object.rb +0 -88
- data/lib/inch/code_object/provider/yard/object/method_signature.rb +0 -114
- data/lib/inch/code_object/provider/yard/object/module_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/object/namespace_object.rb +0 -47
- data/lib/inch/code_object/provider/yard/object/root_object.rb +0 -12
- data/lib/inch/code_object/provider/yard/parser.rb +0 -62
- data/lib/inch/code_object/proxy/base.rb +0 -241
- data/lib/inch/code_object/proxy/class_object.rb +0 -8
- data/lib/inch/code_object/proxy/class_variable_object.rb +0 -8
- data/lib/inch/code_object/proxy/constant_object.rb +0 -8
- data/lib/inch/code_object/proxy/method_object.rb +0 -82
- data/lib/inch/code_object/proxy/method_parameter_object.rb +0 -60
- data/lib/inch/code_object/proxy/module_object.rb +0 -8
- data/lib/inch/code_object/proxy/namespace_object.rb +0 -33
- data/lib/inch/evaluation/object_schema.rb +0 -30
- data/lib/inch/evaluation/proxy/base.rb +0 -164
- data/lib/inch/evaluation/proxy/class_object.rb +0 -8
- data/lib/inch/evaluation/proxy/class_variable_object.rb +0 -19
- data/lib/inch/evaluation/proxy/constant_object.rb +0 -19
- data/lib/inch/evaluation/proxy/method_object.rb +0 -65
- data/lib/inch/evaluation/proxy/module_object.rb +0 -8
- data/lib/inch/evaluation/proxy/namespace_object.rb +0 -27
- data/lib/inch/evaluation/role/base.rb +0 -92
- data/lib/inch/evaluation/role/class_variable.rb +0 -55
- data/lib/inch/evaluation/role/constant.rb +0 -55
- data/lib/inch/evaluation/role/method.rb +0 -126
- data/lib/inch/evaluation/role/method_parameter.rb +0 -91
- data/lib/inch/evaluation/role/missing.rb +0 -20
- data/lib/inch/evaluation/role/namespace.rb +0 -85
- data/lib/inch/evaluation/role/object.rb +0 -143
- data/test/unit/code_object/provider/yard_test.rb +0 -25
data/lib/inch/code_object.rb
CHANGED
@@ -52,7 +52,7 @@ module Inch
|
|
52
52
|
unconsidered_tag_count
|
53
53
|
undocumented?
|
54
54
|
visibility
|
55
|
-
|
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
|
-
|
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
|
-
|
75
|
-
|
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
|
-
|
82
|
-
|
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
|
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
|
20
|
+
# ::Inch::CodeObject::Proxy
|
21
21
|
#
|
22
22
|
#
|
23
23
|
module Provider
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# @return [
|
29
|
-
def self.
|
30
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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'
|
data/lib/inch/codebase.rb
CHANGED
@@ -5,18 +5,17 @@ module Inch
|
|
5
5
|
# Parses a codebase
|
6
6
|
#
|
7
7
|
# @param dir [String]
|
8
|
-
# @param config [Inch::Config::Codebase
|
8
|
+
# @param config [Inch::Config::Codebase]
|
9
9
|
# @return [Codebase::Proxy]
|
10
|
-
def self.parse(dir, config
|
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
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
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
|
10
|
-
# @return [Array<CodeObject::Proxy
|
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 |
|
19
|
-
|
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
|
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
|
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
|
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
|
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
|
-
|
55
|
+
unless options.visibility.include?(:private)
|
54
56
|
@list = @list.reject do |o|
|
55
57
|
o.tagged_as_private?
|
56
58
|
end
|
data/lib/inch/codebase/proxy.rb
CHANGED
@@ -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
|
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(
|
13
|
-
File.open(filename,
|
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(
|
17
|
+
codebase = Marshal.load(File.binread(filename))
|
18
18
|
codebase.objects.each do |object|
|
19
19
|
object.object_lookup = codebase.objects
|
20
20
|
end
|
data/lib/inch/config.rb
CHANGED
@@ -1,24 +1,55 @@
|
|
1
1
|
module Inch
|
2
2
|
# Stores the configuration for Inch
|
3
3
|
#
|
4
|
-
# @see config/
|
4
|
+
# @see config/base.rb
|
5
5
|
class Config
|
6
6
|
class << self
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
24
|
-
require
|
53
|
+
require "inch/config/base"
|
54
|
+
require "inch/config/evaluation"
|
55
|
+
require "inch/config/codebase"
|