inch 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODOS.md +5 -3
- data/bin/inch +9 -4
- data/inch.gemspec +9 -4
- data/lib/inch.rb +1 -0
- data/lib/inch/cli.rb +6 -0
- data/lib/inch/cli/command.rb +0 -6
- data/lib/inch/cli/command_parser.rb +0 -2
- data/lib/inch/code_object/nodoc_helper.rb +1 -1
- data/lib/inch/code_object/proxy/base.rb +18 -3
- data/lib/inch/code_object/proxy/method_object.rb +5 -0
- data/lib/inch/config.rb +53 -0
- data/lib/inch/evaluation.rb +1 -1
- data/lib/inch/evaluation/base.rb +45 -1
- data/lib/inch/evaluation/constant_object.rb +10 -5
- data/lib/inch/evaluation/criteria.rb +38 -0
- data/lib/inch/evaluation/method_object.rb +50 -42
- data/lib/inch/evaluation/namespace_object.rb +38 -33
- data/lib/inch/evaluation/role/constant.rb +1 -0
- data/lib/inch/evaluation/role/method.rb +41 -10
- data/lib/inch/evaluation/role/method_parameter.rb +16 -1
- data/lib/inch/evaluation/role/namespace.rb +17 -5
- data/lib/inch/evaluation/role/object.rb +35 -0
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/simple/lib/foo.rb +0 -37
- data/test/fixtures/simple/lib/nodoc.rb +45 -0
- data/test/fixtures/simple/lib/role_methods.rb +4 -0
- data/test/inch/code_object/nodoc_helper_test.rb +3 -1
- data/test/inch/code_object/proxy/method_object_test.rb +9 -0
- metadata +26 -32
- data/lib/inch/cli/command/console.rb +0 -22
- data/lib/inch/cli/command/inspect.rb +0 -20
- data/lib/inch/cli/command/options/console.rb +0 -26
- data/lib/inch/cli/command/options/inspect.rb +0 -25
- data/lib/inch/cli/command/output/console.rb +0 -49
- data/lib/inch/cli/command/output/inspect.rb +0 -129
- data/test/inch/cli/command/console_test.rb +0 -59
- data/test/inch/cli/command/inspect_test.rb +0 -68
@@ -1,25 +0,0 @@
|
|
1
|
-
module Inch
|
2
|
-
module CLI
|
3
|
-
module Command
|
4
|
-
module Options
|
5
|
-
class Inspect < BaseObject
|
6
|
-
|
7
|
-
def descriptions
|
8
|
-
[
|
9
|
-
"",
|
10
|
-
"Example: " + "$ inch inspect lib/**/*.rb Foo::Bar#initialize".cyan,
|
11
|
-
"",
|
12
|
-
"Shows one or more objects in detail."
|
13
|
-
]
|
14
|
-
end
|
15
|
-
|
16
|
-
def verify
|
17
|
-
if object_names.empty?
|
18
|
-
kill # "Provide a name to an object to show it's evaluation."
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Inch
|
2
|
-
module CLI
|
3
|
-
module Command
|
4
|
-
module Output
|
5
|
-
class Console < Base
|
6
|
-
extend Forwardable
|
7
|
-
|
8
|
-
attr_reader :object, :objects, :source_parser
|
9
|
-
|
10
|
-
def_delegators :source_parser, :all_objects, :find_object, :find_objects
|
11
|
-
alias :all :all_objects
|
12
|
-
alias :ff :find_objects
|
13
|
-
alias :f :find_object
|
14
|
-
alias :o :object
|
15
|
-
|
16
|
-
COLOR = :color198 # magenta-ish
|
17
|
-
BG_COLOR = :color207 # magenta-ish
|
18
|
-
|
19
|
-
# @param options [Options::Console]
|
20
|
-
# @param object [CodeObject::Proxy::Base]
|
21
|
-
# @param objects [Array<CodeObject::Proxy::Base>]
|
22
|
-
# @param source_parser [SourceParser]
|
23
|
-
def initialize(options, object, objects, source_parser)
|
24
|
-
@options = options
|
25
|
-
@object = object
|
26
|
-
@objects = objects
|
27
|
-
@source_parser = source_parser
|
28
|
-
|
29
|
-
run
|
30
|
-
end
|
31
|
-
|
32
|
-
def run
|
33
|
-
trace
|
34
|
-
trace_header("Welcome to Inch's console", COLOR, BG_COLOR)
|
35
|
-
trace edged(COLOR, @options.usage)
|
36
|
-
@options.descriptions.each do |line|
|
37
|
-
trace edged(COLOR, line)
|
38
|
-
end
|
39
|
-
run_pry
|
40
|
-
end
|
41
|
-
|
42
|
-
def run_pry
|
43
|
-
binding.pry
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
module Inch
|
2
|
-
module CLI
|
3
|
-
module Command
|
4
|
-
module Output
|
5
|
-
class Inspect < Base
|
6
|
-
attr_reader :objects
|
7
|
-
|
8
|
-
COLOR = :color198 # magenta-ish
|
9
|
-
BG_COLOR = :color207 # magenta-ish
|
10
|
-
LJUST = 20
|
11
|
-
|
12
|
-
def initialize(options, objects)
|
13
|
-
@options = options
|
14
|
-
@objects = objects
|
15
|
-
|
16
|
-
display_objects
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def display_objects
|
22
|
-
objects.each do |o|
|
23
|
-
print_object(o)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def print_object(o)
|
28
|
-
trace
|
29
|
-
trace_header(o.path, COLOR, BG_COLOR)
|
30
|
-
|
31
|
-
print_file_info(o)
|
32
|
-
print_code_info(o)
|
33
|
-
print_doc_info(o)
|
34
|
-
print_namespace_info(o)
|
35
|
-
print_roles_info(o)
|
36
|
-
|
37
|
-
echo "Score (min: #{o.evaluation.min_score}, max: #{o.evaluation.max_score})".ljust(40) + "#{o.score.to_i}".rjust(5) + "#{o.priority.to_i}".rjust(4)
|
38
|
-
echo
|
39
|
-
end
|
40
|
-
|
41
|
-
def print_file_info(o)
|
42
|
-
o.files.each do |f|
|
43
|
-
echo "-> #{f[0]}:#{f[1]}".color(COLOR)
|
44
|
-
end
|
45
|
-
echo separator
|
46
|
-
end
|
47
|
-
|
48
|
-
def print_code_info(o)
|
49
|
-
if o.method?
|
50
|
-
o.comment_and_abbrev_source.lines.each do |line|
|
51
|
-
echo line.gsub(/\n$/m, '').dark
|
52
|
-
end
|
53
|
-
echo separator
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def print_roles_info(o)
|
58
|
-
if o.roles.empty?
|
59
|
-
echo "No roles assigned.".dark
|
60
|
-
else
|
61
|
-
o.roles.each do |role|
|
62
|
-
name = role.class.to_s.split('::Role::').last
|
63
|
-
if role.potential_score
|
64
|
-
score = "(#{role.potential_score.to_i})".rjust(5).yellow.dark
|
65
|
-
else
|
66
|
-
value = role.score.to_i
|
67
|
-
score = value.abs.to_s.rjust(4)
|
68
|
-
if value < 0
|
69
|
-
score = ("-" + score).red
|
70
|
-
elsif value > 0
|
71
|
-
score = ("+" + score).green
|
72
|
-
else
|
73
|
-
score = " " + score
|
74
|
-
end
|
75
|
-
end
|
76
|
-
priority = role.priority.to_s.rjust(4)
|
77
|
-
if role.priority == 0
|
78
|
-
priority = priority.dark
|
79
|
-
end
|
80
|
-
echo name.ljust(40) + score + priority
|
81
|
-
if role.max_score
|
82
|
-
echo " (set max score to #{role.max_score})"
|
83
|
-
end
|
84
|
-
if role.min_score
|
85
|
-
echo " (set min score to #{role.min_score})"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
echo separator
|
90
|
-
end
|
91
|
-
|
92
|
-
def print_doc_info(o)
|
93
|
-
if o.nodoc?
|
94
|
-
echo "The object was tagged not to be documented.".yellow
|
95
|
-
else
|
96
|
-
echo "Docstring".ljust(LJUST) + "#{o.has_doc? ? 'Yes' : 'No text'}"
|
97
|
-
if o.method?
|
98
|
-
echo "Parameters:".ljust(LJUST) + "#{o.has_parameters? ? '' : 'No parameters'}"
|
99
|
-
o.parameters.each do |p|
|
100
|
-
echo " " + p.name.ljust(LJUST-2) + "#{p.mentioned? ? 'Mentioned' : 'No text'} / #{p.typed? ? 'Typed' : 'Not typed'} / #{p.described? ? 'Described' : 'Not described'}"
|
101
|
-
end
|
102
|
-
echo "Return type:".ljust(LJUST) + "#{o.return_mentioned? ? 'Defined' : 'Not defined'}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
echo separator
|
106
|
-
end
|
107
|
-
|
108
|
-
def print_namespace_info(o)
|
109
|
-
if o.namespace?
|
110
|
-
echo "Children:"
|
111
|
-
o.children.each do |child|
|
112
|
-
echo "+ " + child.path.color(COLOR)
|
113
|
-
end
|
114
|
-
echo separator
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def echo(msg = "")
|
119
|
-
trace edged(COLOR, msg)
|
120
|
-
end
|
121
|
-
|
122
|
-
def separator
|
123
|
-
"-".color(COLOR) * (CLI::COLUMNS - 2)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
2
|
-
|
3
|
-
class Inch::CLI::Command::Output::Console
|
4
|
-
def run_pry
|
5
|
-
nil # instead of binding.pry
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe ::Inch::CLI::Command::Console do
|
10
|
-
before do
|
11
|
-
Dir.chdir fixture_path(:simple)
|
12
|
-
@command = ::Inch::CLI::Command::Console
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should output info when run with --help" do
|
16
|
-
out, err = capture_io do
|
17
|
-
assert_raises(SystemExit) { @command.run("--help") }
|
18
|
-
end
|
19
|
-
refute out.empty?, "there should be some output"
|
20
|
-
assert_match /\bUsage\b.+console/, out
|
21
|
-
assert err.empty?, "there should be no errors"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should run without args" do
|
25
|
-
out, err = capture_io do
|
26
|
-
@prompt = @command.new.run()
|
27
|
-
end
|
28
|
-
assert @prompt.respond_to?(:all)
|
29
|
-
assert @prompt.respond_to?(:ff)
|
30
|
-
assert @prompt.respond_to?(:f)
|
31
|
-
assert @prompt.respond_to?(:o)
|
32
|
-
assert @prompt.o.nil?
|
33
|
-
assert @prompt.objects.empty?
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should run with a definitive object name" do
|
37
|
-
out, err = capture_io do
|
38
|
-
@prompt = @command.new.run("Foo::Bar#method_with_full_doc")
|
39
|
-
end
|
40
|
-
assert @prompt.respond_to?(:all)
|
41
|
-
assert @prompt.respond_to?(:ff)
|
42
|
-
assert @prompt.respond_to?(:f)
|
43
|
-
assert @prompt.respond_to?(:o)
|
44
|
-
refute @prompt.o.nil?
|
45
|
-
assert_equal 1, @prompt.objects.size
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should run with a partial name" do
|
49
|
-
out, err = capture_io do
|
50
|
-
@prompt = @command.new.run("Foo::Bar#")
|
51
|
-
end
|
52
|
-
assert @prompt.respond_to?(:all)
|
53
|
-
assert @prompt.respond_to?(:ff)
|
54
|
-
assert @prompt.respond_to?(:f)
|
55
|
-
assert @prompt.respond_to?(:o)
|
56
|
-
refute @prompt.o.nil?
|
57
|
-
assert @prompt.objects.size > 1
|
58
|
-
end
|
59
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
|
2
|
-
|
3
|
-
describe ::Inch::CLI::Command::Inspect do
|
4
|
-
before do
|
5
|
-
Dir.chdir fixture_path(:simple)
|
6
|
-
@command = ::Inch::CLI::Command::Inspect
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should warn and exit when run without args" do
|
10
|
-
out, err = capture_io do
|
11
|
-
assert_raises(SystemExit) { @command.run() }
|
12
|
-
end
|
13
|
-
assert out.empty?, "there should be no output"
|
14
|
-
refute err.empty?, "there should be some error message"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should output info when run with --help" do
|
18
|
-
out, err = capture_io do
|
19
|
-
assert_raises(SystemExit) { @command.run("--help") }
|
20
|
-
end
|
21
|
-
refute out.empty?, "there should be some output"
|
22
|
-
assert_match /\bUsage\b.+inspect/, out
|
23
|
-
assert err.empty?, "there should be no errors"
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should output some info when run with a definitive object name" do
|
27
|
-
out, err = capture_io do
|
28
|
-
@command.run("Foo::Bar#method_with_full_doc", "--no-color")
|
29
|
-
end
|
30
|
-
refute out.empty?, "there should be some output"
|
31
|
-
assert_match /\bFoo::Bar#method_with_full_doc\b/, out
|
32
|
-
refute_match(/\b Foo::Bar#method_without_doc\b/, out)
|
33
|
-
assert err.empty?, "there should be no errors"
|
34
|
-
end
|
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
|
-
|
45
|
-
it "should output all children info when run with a partial name" do
|
46
|
-
out, err = capture_io do
|
47
|
-
@command.run("Foo::Bar#", "--no-color")
|
48
|
-
end
|
49
|
-
refute out.empty?, "there should be some output"
|
50
|
-
assert_match /\bFoo::Bar#method_without_doc\b/, out
|
51
|
-
assert_match /\bFoo::Bar#method_with_full_doc\b/, out
|
52
|
-
assert err.empty?, "there should be no errors"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should output colored information" do
|
56
|
-
out, err = capture_io do
|
57
|
-
@command.run("Foo::Bar#")
|
58
|
-
end
|
59
|
-
refute_equal out.uncolor, out, "should be colored"
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should output uncolored information when asked" do
|
63
|
-
out, err = capture_io do
|
64
|
-
@command.run("Foo::Bar#", "--no-color")
|
65
|
-
end
|
66
|
-
assert_equal out.uncolor, out, "should not be colored"
|
67
|
-
end
|
68
|
-
end
|