inch 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -6
- data/TODOS.md +7 -0
- data/lib/inch/cli/arguments.rb +36 -2
- data/lib/inch/cli/command/base.rb +56 -8
- data/lib/inch/cli/command/base_list.rb +17 -3
- data/lib/inch/cli/command/base_object.rb +17 -4
- data/lib/inch/cli/command/options/base.rb +55 -10
- data/lib/inch/cli/command/options/base_list.rb +25 -5
- data/lib/inch/cli/command/options/base_object.rb +0 -2
- data/lib/inch/cli/command/options/list.rb +2 -2
- data/lib/inch/cli/command/options/show.rb +2 -2
- data/lib/inch/cli/command/options/suggest.rb +2 -2
- data/lib/inch/cli/command/output/base.rb +9 -0
- data/lib/inch/cli/command/output/console.rb +4 -0
- data/lib/inch/cli/command/output/inspect.rb +2 -2
- data/lib/inch/cli/command/output/list.rb +1 -1
- data/lib/inch/cli/command_parser.rb +30 -9
- data/lib/inch/code_object/nodoc_helper.rb +23 -2
- data/lib/inch/code_object/proxy.rb +16 -2
- data/lib/inch/code_object/proxy/base.rb +2 -23
- data/lib/inch/code_object/proxy/method_object.rb +1 -0
- data/lib/inch/code_object/proxy/method_parameter_object.rb +4 -1
- data/lib/inch/evaluation.rb +0 -2
- data/lib/inch/evaluation/base.rb +1 -0
- data/lib/inch/evaluation/constant_object.rb +0 -3
- data/lib/inch/evaluation/file.rb +0 -4
- data/lib/inch/evaluation/namespace_object.rb +1 -7
- data/lib/inch/evaluation/role/base.rb +29 -5
- data/lib/inch/evaluation/role/constant.rb +0 -5
- data/lib/inch/evaluation/role/object.rb +1 -5
- data/lib/inch/evaluation/score_range.rb +12 -0
- data/lib/inch/rake/suggest.rb +3 -0
- data/lib/inch/source_parser.rb +27 -1
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/simple/lib/foo.rb +6 -0
- data/test/fixtures/simple/lib/role_namespaces.rb +15 -3
- data/test/inch/cli/command/base_test.rb +15 -0
- data/test/inch/cli/command/inspect_test.rb +9 -0
- data/test/inch/cli/command/list_test.rb +3 -0
- data/test/inch/cli/command/options/base_list_test.rb +50 -0
- data/test/inch/cli/command/options/base_object_test.rb +14 -0
- data/test/inch/cli/command/options/base_test.rb +8 -0
- data/test/inch/cli/command/suggest_test.rb +11 -0
- data/test/inch/cli/trace_helper_test.rb +47 -0
- data/test/inch/code_object/proxy_test.rb +10 -0
- data/test/integration/visibility_options_test.rb +24 -17
- data/test/test_helper.rb +80 -0
- metadata +13 -3
@@ -1,6 +1,9 @@
|
|
1
1
|
module Inch
|
2
2
|
module Evaluation
|
3
|
+
# Role objects are assigned to evaluations of code objects. They describe
|
4
|
+
# the object they are attached to.
|
3
5
|
module Role
|
6
|
+
# @abstract
|
4
7
|
class Base
|
5
8
|
attr_reader :object
|
6
9
|
|
@@ -9,33 +12,54 @@ module Inch
|
|
9
12
|
@value = value
|
10
13
|
end
|
11
14
|
|
12
|
-
#
|
15
|
+
# Returns a maximal score for the object.
|
16
|
+
# The final score can not be higher than this.
|
17
|
+
# @note Override this method to that a max_score for the evaluation.
|
18
|
+
# @return [Float]
|
13
19
|
def max_score
|
14
20
|
end
|
15
21
|
|
16
|
-
#
|
22
|
+
# Returns a minimal score for the object.
|
23
|
+
# The final score can not be lower than this.
|
24
|
+
# @note Override this method to that a min_score for the evaluation.
|
25
|
+
# @return [Float]
|
17
26
|
def min_score
|
18
27
|
end
|
19
28
|
|
20
29
|
# Returns a score that will be added to the associated object's
|
21
30
|
# overall score.
|
22
31
|
#
|
23
|
-
# Override this method to
|
32
|
+
# @note Override this method to assign a score for the role
|
33
|
+
# @return [Float]
|
24
34
|
def score
|
25
35
|
@value.to_f
|
26
36
|
end
|
27
37
|
|
38
|
+
# Returns a potential score that would be added to the overall score
|
39
|
+
# if the object had implemented the Role's subject.
|
40
|
+
#
|
41
|
+
# @see Role::Missing
|
42
|
+
# @note Override this method to assign a potential score for the role
|
28
43
|
# @return [Float]
|
29
|
-
# a score that can be achieved by adding the missing thing mentioned
|
30
|
-
# by the role
|
31
44
|
def potential_score
|
32
45
|
nil
|
33
46
|
end
|
34
47
|
|
48
|
+
# Returns a priority that will be added to the associated object's
|
49
|
+
# overall priority.
|
50
|
+
#
|
51
|
+
# @note Override this method to assign a priority for the role
|
52
|
+
# @return [Fixnum]
|
35
53
|
def priority
|
36
54
|
0
|
37
55
|
end
|
38
56
|
|
57
|
+
# Returns a suggestion to achieve the potential score that would be
|
58
|
+
# added to the overall score if the object had implemented the Role's
|
59
|
+
# subject.
|
60
|
+
#
|
61
|
+
# @see Role::Missing
|
62
|
+
# @return [Float]
|
39
63
|
def suggestion
|
40
64
|
nil
|
41
65
|
end
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module Inch
|
2
2
|
module Evaluation
|
3
|
+
# ScoreRange objects associate a range of scores with a grade,
|
4
|
+
# description, color etc.
|
5
|
+
#
|
6
|
+
# @see .new_score_ranges
|
3
7
|
class ScoreRange < Struct.new(:range, :grade, :description, :color, :bg_color)
|
4
8
|
# Returns code_objects that received a score with the defined +range+
|
5
9
|
attr_reader :objects
|
6
10
|
|
11
|
+
# Assigns code_objects that received a score with the defined +range+
|
12
|
+
#
|
13
|
+
# @param arr [Array<CodeObject::Proxy::Base>]
|
14
|
+
# @return [Array<CodeObject::Proxy::Base>]
|
7
15
|
def objects=(arr)
|
8
16
|
arr.each { |o| o.grade = grade }
|
9
17
|
@objects = arr
|
@@ -17,6 +25,10 @@ module Inch
|
|
17
25
|
[0..0, :U, "Undocumented", :color141, :color105],
|
18
26
|
]
|
19
27
|
|
28
|
+
# Returns newly instanciated score range objects based on
|
29
|
+
# {SCORE_RANGE_ARGS}
|
30
|
+
#
|
31
|
+
# @return [Array<ScoreRange>]
|
20
32
|
def self.new_score_ranges
|
21
33
|
SCORE_RANGE_ARGS.map do |args|
|
22
34
|
ScoreRange.new(*args)
|
data/lib/inch/rake/suggest.rb
CHANGED
@@ -9,6 +9,9 @@ module Inch
|
|
9
9
|
attr_accessor :name
|
10
10
|
attr_accessor :args
|
11
11
|
|
12
|
+
# @param name [String] name of the Rake task
|
13
|
+
# @param *args [Array] arguments to be passed to Suggest.run
|
14
|
+
# @param &block [Proc] optional, evaluated inside the task definition
|
12
15
|
def initialize(name = "inch", *args, &block)
|
13
16
|
@name = name
|
14
17
|
@args = args
|
data/lib/inch/source_parser.rb
CHANGED
@@ -1,23 +1,49 @@
|
|
1
1
|
module Inch
|
2
|
-
# Parses the source tree
|
2
|
+
# Parses the source tree (using YARD)
|
3
3
|
class SourceParser
|
4
|
+
# Helper method to run an instance with the given +args+
|
5
|
+
#
|
6
|
+
# @see #run
|
7
|
+
# @return [SourceParser] the instance that ran
|
4
8
|
def self.run(*args)
|
5
9
|
parser = self.new
|
6
10
|
parser.run(*args)
|
7
11
|
parser
|
8
12
|
end
|
9
13
|
|
14
|
+
# Returns all parsed objects as code object proxies
|
15
|
+
#
|
16
|
+
# @see CodeObject::Proxy.for
|
17
|
+
# @return [Array<CodeObject::Proxy::Base>]
|
10
18
|
def all_objects
|
11
19
|
@all_objects ||= all_parsed_objects.map do |o|
|
12
20
|
CodeObject::Proxy.for(o)
|
13
21
|
end.sort_by(&:path)
|
14
22
|
end
|
15
23
|
|
24
|
+
# Returns the object with the given +path+
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
#
|
28
|
+
# SourceParser.find_objects("Foo#bar")
|
29
|
+
# # => returns code object proxy for Foo#bar
|
30
|
+
#
|
31
|
+
# @param path [String] partial path/name of an object
|
32
|
+
# @return [CodeObject::Proxy::Base]
|
16
33
|
def find_object(path)
|
17
34
|
all_objects.detect { |o| o.path == path }
|
18
35
|
end
|
19
36
|
alias :[] :find_object
|
20
37
|
|
38
|
+
# Returns all objects where the +path+ starts_with the given +path+
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
#
|
42
|
+
# SourceParser.find_objects("Foo#")
|
43
|
+
# # => returns code object proxies for all instance methods of Foo
|
44
|
+
#
|
45
|
+
# @param path [String] partial path/name of an object
|
46
|
+
# @return [Array<CodeObject::Proxy::Base>]
|
21
47
|
def find_objects(path)
|
22
48
|
all_objects.select { |o| o.path.start_with?(path) }
|
23
49
|
end
|
data/lib/inch/version.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
# @see PureNamespace
|
4
4
|
PUBLIC_ROOT_CONSTANT = :foo
|
5
5
|
|
6
|
+
PRIVATE_ROOT_CONSTANT = :foo
|
7
|
+
private_constant :PRIVATE_ROOT_CONSTANT
|
8
|
+
|
6
9
|
class String
|
7
10
|
def foobar
|
8
11
|
self + 'foobar!'
|
@@ -12,20 +15,29 @@ end
|
|
12
15
|
module InchTest
|
13
16
|
# You would want to use it like this:
|
14
17
|
#
|
15
|
-
#
|
18
|
+
# CodeExample.new
|
16
19
|
#
|
17
20
|
class CodeExample
|
18
21
|
end
|
19
22
|
|
20
23
|
# You would want to use it like this:
|
21
24
|
#
|
22
|
-
#
|
25
|
+
# MultipleCodeExamples.new
|
23
26
|
#
|
24
|
-
#
|
27
|
+
# MultipleCodeExamples.new # => something
|
25
28
|
#
|
26
29
|
class MultipleCodeExamples
|
27
30
|
end
|
28
31
|
|
32
|
+
# You would want to use it like this:
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# MultipleCodeExamples2.new
|
36
|
+
# MultipleCodeExamples2.new # => something
|
37
|
+
#
|
38
|
+
class MultipleCodeExamples2
|
39
|
+
end
|
40
|
+
|
29
41
|
module PureNamespace
|
30
42
|
end
|
31
43
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
2
|
+
|
3
|
+
describe ::Inch::CLI::Command::Console do
|
4
|
+
before do
|
5
|
+
@command = ::Inch::CLI::Command::Base.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should implement some defaults" do
|
9
|
+
assert @command.name
|
10
|
+
assert @command.usage
|
11
|
+
assert @command.description
|
12
|
+
|
13
|
+
assert_raises(NotImplementedError) { @command.run("something") }
|
14
|
+
end
|
15
|
+
end
|
@@ -33,6 +33,15 @@ describe ::Inch::CLI::Command::Inspect do
|
|
33
33
|
assert err.empty?, "there should be no errors"
|
34
34
|
end
|
35
35
|
|
36
|
+
|
37
|
+
it "should output some info when run with a definitive object name" do
|
38
|
+
out, err = capture_io do
|
39
|
+
@command.run("Foo::Qux")
|
40
|
+
end
|
41
|
+
refute out.empty?, "there should be some output"
|
42
|
+
assert err.empty?, "there should be no errors"
|
43
|
+
end
|
44
|
+
|
36
45
|
it "should output all children info when run with a partial name" do
|
37
46
|
out, err = capture_io do
|
38
47
|
@command.run("Foo::Bar#", "--no-color")
|
@@ -6,6 +6,8 @@ describe ::Inch::CLI::Command::List do
|
|
6
6
|
@command = ::Inch::CLI::Command::List
|
7
7
|
end
|
8
8
|
|
9
|
+
include BaseListTests
|
10
|
+
|
9
11
|
it "should run without args" do
|
10
12
|
out, err = capture_io do
|
11
13
|
@command.run()
|
@@ -59,3 +61,4 @@ describe ::Inch::CLI::Command::List do
|
|
59
61
|
assert err.empty?, "there should be no errors"
|
60
62
|
end
|
61
63
|
end
|
64
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../test_helper')
|
2
|
+
|
3
|
+
describe ::Inch::CLI::Command::Options::BaseList do
|
4
|
+
it "should run parse without errors" do
|
5
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
6
|
+
@options.parse(["--no-color"])
|
7
|
+
assert_equal false, @options.show_all?
|
8
|
+
assert_equal [:public, :protected], @options.visibility
|
9
|
+
assert @options.namespaces.nil?
|
10
|
+
assert @options.undocumented.nil?
|
11
|
+
assert @options.depth.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should run parse twice without affecting the second run" do
|
15
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
16
|
+
@options.parse(["--no-public", "--no-protected", "--private"])
|
17
|
+
assert_equal [:private], @options.visibility
|
18
|
+
|
19
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
20
|
+
@options.parse(["--no-color"])
|
21
|
+
assert_equal [:public, :protected], @options.visibility
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should interpret --all options" do
|
25
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
26
|
+
@options.parse(["--all"])
|
27
|
+
assert_equal true, @options.show_all?
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should interpret visibility options" do
|
31
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
32
|
+
@options.parse(["--no-public", "--no-protected", "--private"])
|
33
|
+
assert_equal [:private], @options.visibility
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should interpret options" do
|
37
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
38
|
+
@options.parse(["--no-namespaces", "--no-undocumented", "--depth=2"])
|
39
|
+
assert_equal :none, @options.namespaces
|
40
|
+
assert_equal :none, @options.undocumented
|
41
|
+
assert_equal 2, @options.depth
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should interpret other options" do
|
45
|
+
@options = ::Inch::CLI::Command::Options::BaseList.new
|
46
|
+
@options.parse(["--only-namespaces", "--only-undocumented"])
|
47
|
+
assert_equal :only, @options.namespaces
|
48
|
+
assert_equal :only, @options.undocumented
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../test_helper')
|
2
|
+
|
3
|
+
describe ::Inch::CLI::Command::Options::BaseObject do
|
4
|
+
it "should run parse without errors" do
|
5
|
+
@options = ::Inch::CLI::Command::Options::BaseObject.new
|
6
|
+
@options.parse(["--no-color"])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should interpret options" do
|
10
|
+
@options = ::Inch::CLI::Command::Options::BaseObject.new
|
11
|
+
@options.parse(["Foo", "Foo::Bar", "--no-color"])
|
12
|
+
assert_equal ["Foo", "Foo::Bar"], @options.object_names
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../../test_helper')
|
2
|
+
|
3
|
+
describe ::Inch::CLI::Command::Options::Base do
|
4
|
+
it "should run parse without errors" do
|
5
|
+
@options = ::Inch::CLI::Command::Options::Base.new
|
6
|
+
@options.parse(["--no-color"])
|
7
|
+
end
|
8
|
+
end
|
@@ -46,6 +46,17 @@ describe ::Inch::CLI::Command::Suggest do
|
|
46
46
|
#assert err.empty?, "there should be no errors"
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should run with --objects switch" do
|
50
|
+
out, err = capture_io do
|
51
|
+
@command.run("lib/**/*.rb", "app/**/*.rb", "--objects=30")
|
52
|
+
end
|
53
|
+
refute out.empty?, "there should be some output"
|
54
|
+
assert err.empty?, "there should be no errors"
|
55
|
+
assert_match /\bFoo::Bar#method_with_wrong_doc\b/, out
|
56
|
+
assert_match /\bFoo::Bar#method_without_docstring\b/, out
|
57
|
+
assert_match /\bFoo::Bar#method_with_unstructured_doc\b/, out
|
58
|
+
end
|
59
|
+
|
49
60
|
it "should give error when run with --unknown-switch" do
|
50
61
|
out, err = capture_io do
|
51
62
|
assert_raises(SystemExit) { @command.run("--unknown-switch") }
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class Tracer
|
4
|
+
include ::Inch::CLI::TraceHelper
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ::Inch::CLI::TraceHelper do
|
8
|
+
before do
|
9
|
+
@instance = Tracer.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should trace" do
|
13
|
+
out, err = capture_io do
|
14
|
+
@instance.trace("Test")
|
15
|
+
end
|
16
|
+
refute out.empty?, "there should be no output"
|
17
|
+
assert err.empty?, "there should be no errors"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should trace header" do
|
21
|
+
out, err = capture_io do
|
22
|
+
@instance.trace_header("Test", :red)
|
23
|
+
end
|
24
|
+
refute out.empty?, "there should be no output"
|
25
|
+
assert err.empty?, "there should be no errors"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should trace debug if ENV variable is set" do
|
29
|
+
ENV['DEBUG'] = "1"
|
30
|
+
out, err = capture_io do
|
31
|
+
@instance.debug("Test")
|
32
|
+
end
|
33
|
+
ENV['DEBUG'] = nil
|
34
|
+
refute out.empty?, "there should be no output"
|
35
|
+
assert err.empty?, "there should be no errors"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not trace debug if ENV variable is set" do
|
39
|
+
refute ENV['DEBUG']
|
40
|
+
out, err = capture_io do
|
41
|
+
@instance.debug("Test")
|
42
|
+
end
|
43
|
+
assert out.empty?, "there should be no output"
|
44
|
+
assert err.empty?, "there should be no errors"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -6,6 +6,16 @@ describe ::Inch::CodeObject::Proxy::Base do
|
|
6
6
|
@source_parser = Inch::SourceParser.run(["lib/**/*.rb"])
|
7
7
|
end
|
8
8
|
|
9
|
+
def test_inspect_gives_original_name
|
10
|
+
m = @source_parser.find_object("Foo::Bar#method_with_code_example")
|
11
|
+
assert_match /Foo::Bar#method_with_code_example/, m.inspect
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_grade_is_not_nil
|
15
|
+
m = @source_parser.find_object("Foo::Bar#method_with_code_example")
|
16
|
+
assert m.grade
|
17
|
+
end
|
18
|
+
|
9
19
|
def test_method_with_code_example
|
10
20
|
m = @source_parser.find_object("Foo::Bar#method_with_code_example")
|
11
21
|
assert m.has_code_example?
|