inch 0.3.3 → 0.3.4.rc1
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/.gitignore +1 -0
- data/CHANGELOG.md +109 -0
- data/inch.gemspec +1 -6
- data/lib/inch/cli.rb +0 -6
- data/lib/inch/cli/command.rb +2 -0
- data/lib/inch/cli/command/console.rb +26 -0
- data/lib/inch/cli/command/inspect.rb +25 -0
- data/lib/inch/cli/command/options/console.rb +26 -0
- data/lib/inch/cli/command/options/inspect.rb +25 -0
- data/lib/inch/cli/command/output/console.rb +61 -0
- data/lib/inch/cli/command/output/inspect.rb +186 -0
- data/lib/inch/code_object/converter.rb +2 -1
- data/lib/inch/code_object/provider/yard/object.rb +4 -0
- data/lib/inch/code_object/provider/yard/object/base.rb +10 -4
- data/lib/inch/code_object/provider/yard/object/method_object.rb +6 -7
- data/lib/inch/code_object/provider/yard/parser.rb +6 -0
- data/lib/inch/code_object/proxy.rb +2 -15
- data/lib/inch/code_object/proxy/base.rb +18 -4
- data/lib/inch/evaluation/grade.rb +8 -0
- data/lib/inch/evaluation/proxy/base.rb +1 -2
- data/lib/inch/evaluation/role/object.rb +12 -0
- data/lib/inch/version.rb +1 -1
- data/test/fixtures/simple/lib/role_methods.rb +6 -1
- data/test/integration/cli/command/console_test.rb +59 -0
- data/test/integration/cli/command/inspect_test.rb +68 -0
- data/test/unit/code_object/proxy/method_object_test.rb +6 -0
- metadata +15 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bee5d78b05fdeb0f445662eb4249e8faaa17111e
|
4
|
+
data.tar.gz: 3b2fc21a47176e5dcf8585bd535586d16f6df72f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04a14a7a0cae1fc250381a3da92626e0149f32dd1ab2f614db0ac522f0e1b4a26ac39af5bbb3acb403c29f7b90c95a6941f3bee8a517d97e0b5ab69ee754c142
|
7
|
+
data.tar.gz: 6a8a0ec1621b7ea8ec9543514520ab8dabfae9ded1c483aa845a13aa78224c3ba4edebf266ec442075b721a629dfb421ced96169a580ecfbde8698ba47983455
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.3.3
|
4
|
+
|
5
|
+
- Fix rake task
|
6
|
+
- Remove unused constant
|
7
|
+
- Add support for overload tag
|
8
|
+
- Add failing test re: method overloading
|
9
|
+
- Update README with configuration instructions
|
10
|
+
|
11
|
+
|
12
|
+
## 0.3.2
|
13
|
+
|
14
|
+
- Fix bug when parsing .inch.yml
|
15
|
+
- Separate test suite in unit and integration tests
|
16
|
+
- Support regexes in .inch.yml
|
17
|
+
- Add some basic ideas for .inch.yml support
|
18
|
+
- Speed up tests by caching code objects
|
19
|
+
|
20
|
+
|
21
|
+
## 0.3.1
|
22
|
+
|
23
|
+
- Fix error with empty docstring
|
24
|
+
- Do not count @raise tag if it is auto-assigned via YARD
|
25
|
+
- Add a role to encapsulate notations of private tags
|
26
|
+
- Update Docstring to detect internal apis
|
27
|
+
- Fix output of priority arrows in Suggest command
|
28
|
+
- Use original docstring to determine if an object is undocumented?
|
29
|
+
- Fix things complained about in last commit
|
30
|
+
- Exclude failing test
|
31
|
+
- Don't apply transitive :since tag to children's evaluation
|
32
|
+
- Fix bug in YARD method object proxy
|
33
|
+
- Fix wrong detection of splat and block parameters
|
34
|
+
- Fix 1.9.3 compatibility of Inch::Utils::UI
|
35
|
+
- Fix #depth method
|
36
|
+
- Add Inch::Utils::UI utility class
|
37
|
+
- Cache some repeatedly calculated values
|
38
|
+
|
39
|
+
|
40
|
+
## 0.3.0
|
41
|
+
|
42
|
+
- Add proxy for RootObject to YARD object provider
|
43
|
+
- Ignore some YARD code objects by type
|
44
|
+
- Remove YARD from core_ext
|
45
|
+
- Fix bug showing wrong paths instead of files in Suggest
|
46
|
+
- Ensure output if Suggest has nothing to suggest
|
47
|
+
- Merge pull request #5 from splattael/perf
|
48
|
+
- Upgrade to Ruby 2.1 as default
|
49
|
+
- Prefer `Module#const_get(class_name)` over `eval(class_name)`
|
50
|
+
- Prefer `public_send(name)` over `method(name).call`
|
51
|
+
- Perf: Index codeobjects objects by fullname
|
52
|
+
- Merge pull request #4 from jimjeffers/master
|
53
|
+
- Fixed minor typo in CLI for suggest command.
|
54
|
+
- Require 'forwardable' at the very top
|
55
|
+
- Add fix for failing test
|
56
|
+
- Add failing test fixture
|
57
|
+
- Refactor Evaluation namespace
|
58
|
+
- Add doc to ObjectsFilter
|
59
|
+
- Add CodeObject::Provider modules
|
60
|
+
- Rewrite Evaluation Role model
|
61
|
+
- Add some more docs
|
62
|
+
- Extract shared specs into own file
|
63
|
+
- Depend on minitest ~> 5.2
|
64
|
+
- Merge pull request #3 from splattael/simplecov
|
65
|
+
- Add docs to ReadWriteMethods
|
66
|
+
- Move simplecov's configuration into own file
|
67
|
+
- Add tests for new API classes
|
68
|
+
- Rename Evaluation::WeightedList -> Utils::WeightedList
|
69
|
+
- Fix description of stats command
|
70
|
+
- Add PriorityRange
|
71
|
+
- Refactor inspect/show output
|
72
|
+
- Introduce API namespace
|
73
|
+
- Fix wrong command registration in Command::Inspect
|
74
|
+
- Add Codebase::ObjectsFilter
|
75
|
+
- Update commands to use Codebase
|
76
|
+
- Introduce Codebase namespace
|
77
|
+
- Remove unused method alias
|
78
|
+
- Fix bug in Docstring
|
79
|
+
|
80
|
+
|
81
|
+
## 0.2.3
|
82
|
+
|
83
|
+
- Bump version
|
84
|
+
- Rescue error raised by YARD
|
85
|
+
- Let Command classes register themselves in CommandParser
|
86
|
+
- Fix failing tests (typo)
|
87
|
+
- Refactor some more methods
|
88
|
+
- Refactor complex methods
|
89
|
+
- Add Getter and Setter roles
|
90
|
+
- Refactor ScoreRanges into GradeLists
|
91
|
+
- Add Inch::Config
|
92
|
+
- Rename Evaluation::Criteria -> ObjectSchema
|
93
|
+
- Add weighted_list for suggest output
|
94
|
+
- Make CodeObject::Proxy#object an attr_reader
|
95
|
+
|
96
|
+
|
97
|
+
## 0.2.2
|
98
|
+
|
99
|
+
- Fix bug related to private @api tags (again)
|
100
|
+
|
101
|
+
|
102
|
+
## 0.2.1
|
103
|
+
|
104
|
+
- Fix bug related to private @api tags
|
105
|
+
|
106
|
+
|
107
|
+
## 0.2.0
|
108
|
+
|
109
|
+
- First public release
|
data/inch.gemspec
CHANGED
@@ -13,12 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "http://trivelop.de/inch/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
files_without_dev_commands = all_files.select do |f|
|
18
|
-
f !~ /cli\/command\/.*(console|inspect)/
|
19
|
-
end
|
20
|
-
|
21
|
-
spec.files = files_without_dev_commands
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
22
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
24
19
|
spec.require_paths = ["lib"]
|
data/lib/inch/cli.rb
CHANGED
@@ -26,9 +26,3 @@ require_relative 'cli/trace_helper'
|
|
26
26
|
require_relative 'cli/yardopts_helper'
|
27
27
|
|
28
28
|
require_relative 'cli/command'
|
29
|
-
|
30
|
-
console_rb = File.join(File.dirname(__FILE__), 'cli', 'command', 'console.rb')
|
31
|
-
if File.exists?(console_rb)
|
32
|
-
require_relative 'cli/command/console'
|
33
|
-
require_relative 'cli/command/inspect'
|
34
|
-
end
|
data/lib/inch/cli/command.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require_relative 'options/console'
|
3
|
+
require_relative 'output/console'
|
4
|
+
|
5
|
+
module Inch
|
6
|
+
module CLI
|
7
|
+
module Command
|
8
|
+
class Console < BaseObject
|
9
|
+
register_command_as :console
|
10
|
+
|
11
|
+
def description
|
12
|
+
'Shows a console'
|
13
|
+
end
|
14
|
+
|
15
|
+
def usage
|
16
|
+
'Usage: inch console [paths] [OBJECT_NAME] [options]'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(*args)
|
20
|
+
prepare_objects(*args)
|
21
|
+
Output::Console.new(@options, @object, @objects, codebase)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'options/inspect'
|
2
|
+
require_relative 'output/inspect'
|
3
|
+
|
4
|
+
module Inch
|
5
|
+
module CLI
|
6
|
+
module Command
|
7
|
+
class Inspect < BaseObject
|
8
|
+
register_command_as :inspect
|
9
|
+
|
10
|
+
def description
|
11
|
+
'Inspects an object'
|
12
|
+
end
|
13
|
+
|
14
|
+
def usage
|
15
|
+
'Usage: inch inspect [paths] OBJECT_NAME [[OBJECT_NAME2] ...] [options]'
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(*args)
|
19
|
+
prepare_objects(*args)
|
20
|
+
Output::Inspect.new(@options, objects)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Inch
|
2
|
+
module CLI
|
3
|
+
module Command
|
4
|
+
module Options
|
5
|
+
class Console < BaseObject
|
6
|
+
def descriptions
|
7
|
+
[
|
8
|
+
"",
|
9
|
+
"Provides a PRY based REPL to inspect objects.",
|
10
|
+
"",
|
11
|
+
"Example: " + "$ inch console lib/**/*.rb Foo::Bar#initialize".cyan,
|
12
|
+
"",
|
13
|
+
"Shortcut commands on the prompt are:",
|
14
|
+
"",
|
15
|
+
"all".ljust(5) + " returns all code objects",
|
16
|
+
"f".ljust(5) + " finds an object by its path",
|
17
|
+
"ff".ljust(5) + " finds all objects given a partial path",
|
18
|
+
"o".ljust(5) + " returns the code object for OBJECT_NAME (if present)",
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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
|
@@ -0,0 +1,61 @@
|
|
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, :codebase
|
9
|
+
|
10
|
+
COLOR = :color198 # magenta-ish
|
11
|
+
BG_COLOR = :color207 # magenta-ish
|
12
|
+
|
13
|
+
# @param options [Options::Console]
|
14
|
+
# @param object [CodeObject::Proxy::Base]
|
15
|
+
# @param objects [Array<CodeObject::Proxy::Base>]
|
16
|
+
# @param codebase [Codebase::Proxy]
|
17
|
+
def initialize(options, object, objects, codebase)
|
18
|
+
@options = options
|
19
|
+
@object = object
|
20
|
+
@objects = objects
|
21
|
+
@codebase = codebase
|
22
|
+
|
23
|
+
run
|
24
|
+
end
|
25
|
+
|
26
|
+
def all_objects
|
27
|
+
@codebase.objects.all
|
28
|
+
end
|
29
|
+
|
30
|
+
def find_objects(fullname)
|
31
|
+
@codebase.objects.starting_with(fullname)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_object(fullname)
|
35
|
+
@codebase.objects.find(fullname)
|
36
|
+
end
|
37
|
+
|
38
|
+
alias :all :all_objects
|
39
|
+
alias :ff :find_objects
|
40
|
+
alias :f :find_object
|
41
|
+
alias :o :object
|
42
|
+
|
43
|
+
|
44
|
+
def run
|
45
|
+
ui.trace
|
46
|
+
ui.header("Welcome to Inch's console", COLOR, BG_COLOR)
|
47
|
+
ui.sub @options.usage
|
48
|
+
@options.descriptions.each do |line|
|
49
|
+
ui.sub line
|
50
|
+
end
|
51
|
+
run_pry
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_pry
|
55
|
+
binding.pry
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,186 @@
|
|
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
|
+
ui.trace
|
29
|
+
ui.header(o.fullname, COLOR, BG_COLOR)
|
30
|
+
|
31
|
+
print_file_info(o, COLOR)
|
32
|
+
print_code_info(o)
|
33
|
+
print_namespace_info(o)
|
34
|
+
print_roles_info(o)
|
35
|
+
|
36
|
+
print_score_summary(o)
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_score_summary(o)
|
40
|
+
min = o.evaluation.min_score
|
41
|
+
max = o.evaluation.max_score
|
42
|
+
echo "Score (min: #{min}, max: #{max})".ljust(40) +
|
43
|
+
"#{o.score.to_i}".rjust(5) + "#{o.priority.to_i}".rjust(4)
|
44
|
+
echo
|
45
|
+
end
|
46
|
+
|
47
|
+
def print_code_info(o)
|
48
|
+
if o.method?
|
49
|
+
CommentAndAbbrevSource.new(o).lines.each do |line|
|
50
|
+
echo line.gsub(/\n$/m, '').dark
|
51
|
+
end
|
52
|
+
echo separator
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def print_roles_info(o)
|
57
|
+
if o.roles.empty?
|
58
|
+
echo "No roles assigned.".dark
|
59
|
+
else
|
60
|
+
o.roles.each do |role|
|
61
|
+
print_role_info(role)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
echo separator
|
65
|
+
end
|
66
|
+
|
67
|
+
def print_role_info(role)
|
68
|
+
name = role.class.to_s.split('::Role::').last
|
69
|
+
score = colored_role_score(role)
|
70
|
+
|
71
|
+
priority = role.priority.to_s.rjust(4)
|
72
|
+
if role.priority == 0
|
73
|
+
priority = priority.dark
|
74
|
+
end
|
75
|
+
|
76
|
+
echo name.ljust(40) + score + priority
|
77
|
+
print_min_max_score(role)
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_min_max_score(role)
|
81
|
+
if role.max_score
|
82
|
+
echo " (set max score to #{role.max_score})"
|
83
|
+
elsif role.min_score
|
84
|
+
echo " (set min score to #{role.min_score})"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def print_namespace_info(o)
|
89
|
+
if o.namespace?
|
90
|
+
echo "Children:"
|
91
|
+
o.children.each do |child|
|
92
|
+
echo "+ " + child.fullname.color(COLOR)
|
93
|
+
end
|
94
|
+
echo separator
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def colored_role_score(role)
|
99
|
+
if role.potential_score
|
100
|
+
"(#{role.potential_score.to_i})".rjust(5).yellow.dark
|
101
|
+
else
|
102
|
+
value = role.score.to_i
|
103
|
+
colored_score value, value.abs.to_s.rjust(4)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def colored_score(value, score)
|
108
|
+
if value < 0
|
109
|
+
("-" + score).red
|
110
|
+
elsif value > 0
|
111
|
+
("+" + score).green
|
112
|
+
else
|
113
|
+
" " + score
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def echo(msg = "")
|
118
|
+
ui.edged(COLOR, msg)
|
119
|
+
end
|
120
|
+
|
121
|
+
def separator
|
122
|
+
"-".color(COLOR) * (CLI::COLUMNS - 2)
|
123
|
+
end
|
124
|
+
|
125
|
+
class CommentAndAbbrevSource < Struct.new(:code_object)
|
126
|
+
extend Forwardable
|
127
|
+
|
128
|
+
def_delegators :code_object, :source, :files
|
129
|
+
|
130
|
+
def lines
|
131
|
+
to_s.lines
|
132
|
+
end
|
133
|
+
|
134
|
+
def to_s
|
135
|
+
comments.join('') + abbrev_source
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def abbrev_source
|
141
|
+
lines = code_object.source.to_s.lines.to_a
|
142
|
+
if lines.size >= 5
|
143
|
+
indent = lines[1].scan(/^(\s+)/).flatten.join('')
|
144
|
+
lines = lines[0..1] +
|
145
|
+
["#{indent}# ... snip ...\n"] +
|
146
|
+
lines[-2..-1]
|
147
|
+
end
|
148
|
+
lines.join('')
|
149
|
+
end
|
150
|
+
|
151
|
+
def comments
|
152
|
+
@comments ||= code_object.files.map do |declaration|
|
153
|
+
get_lines_up_while(declaration.filename, declaration.line_no - 1) do |line|
|
154
|
+
line =~ /^\s*#/
|
155
|
+
end.flatten.join('')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def get_lines_up_while(filename, line_no, &block)
|
160
|
+
lines = []
|
161
|
+
line = get_line_no(filename, line_no)
|
162
|
+
if yield(line) && line_no > 0
|
163
|
+
lines << line.gsub(/^(\s+)/, '')
|
164
|
+
lines << get_lines_up_while(filename, line_no - 1, &block)
|
165
|
+
end
|
166
|
+
lines.reverse
|
167
|
+
end
|
168
|
+
|
169
|
+
# Returns a +line_number+ from a file
|
170
|
+
#
|
171
|
+
# @param filename [String]
|
172
|
+
# @param line_number [Fixnum]
|
173
|
+
# @return [String]
|
174
|
+
def get_line_no(filename, line_number)
|
175
|
+
f = File.open(filename)
|
176
|
+
line_number.times{f.gets}
|
177
|
+
result = $_
|
178
|
+
f.close
|
179
|
+
result
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -16,6 +16,8 @@ module Inch
|
|
16
16
|
parent_fullname
|
17
17
|
|
18
18
|
api_tag?
|
19
|
+
aliased_object_fullname
|
20
|
+
aliases_fullnames
|
19
21
|
attributes
|
20
22
|
bang_name?
|
21
23
|
constant?
|
@@ -23,7 +25,6 @@ module Inch
|
|
23
25
|
depth
|
24
26
|
docstring
|
25
27
|
getter?
|
26
|
-
has_alias?
|
27
28
|
has_children?
|
28
29
|
has_code_example?
|
29
30
|
has_doc?
|
@@ -30,6 +30,16 @@ module Inch
|
|
30
30
|
@__private_tag = __private_tag
|
31
31
|
end
|
32
32
|
|
33
|
+
# Returns the fullname of the object that the current object
|
34
|
+
# is an alias for
|
35
|
+
attr_accessor :aliased_object_fullname
|
36
|
+
|
37
|
+
# Returns the fullnames of the objects that are aliases
|
38
|
+
# for the current object
|
39
|
+
def aliases_fullnames
|
40
|
+
[]
|
41
|
+
end
|
42
|
+
|
33
43
|
def api_tag?
|
34
44
|
!api_tag.nil?
|
35
45
|
end
|
@@ -104,10 +114,6 @@ module Inch
|
|
104
114
|
@name ||= object.name
|
105
115
|
end
|
106
116
|
|
107
|
-
def has_alias?
|
108
|
-
false
|
109
|
-
end
|
110
|
-
|
111
117
|
def has_children?
|
112
118
|
!children.empty?
|
113
119
|
end
|
@@ -5,15 +5,18 @@ module Inch
|
|
5
5
|
module Object
|
6
6
|
# Proxy class for methods
|
7
7
|
class MethodObject < Base
|
8
|
-
|
9
|
-
|
10
|
-
name == :initialize
|
8
|
+
def aliases_fullnames
|
9
|
+
object.aliases.map(&:path)
|
11
10
|
end
|
12
11
|
|
13
12
|
def bang_name?
|
14
13
|
name =~ /\!$/
|
15
14
|
end
|
16
15
|
|
16
|
+
def constructor?
|
17
|
+
name == :initialize
|
18
|
+
end
|
19
|
+
|
17
20
|
def getter?
|
18
21
|
attr_info = object.attr_info || {}
|
19
22
|
read_info = attr_info[:read]
|
@@ -28,10 +31,6 @@ module Inch
|
|
28
31
|
super && !implicit_docstring?
|
29
32
|
end
|
30
33
|
|
31
|
-
def has_alias?
|
32
|
-
!object.aliases.empty?
|
33
|
-
end
|
34
|
-
|
35
34
|
def method?
|
36
35
|
true
|
37
36
|
end
|
@@ -37,6 +37,7 @@ module Inch
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def parse_yard_objects(paths, excluded)
|
40
|
+
YARD::Object.clear_cache
|
40
41
|
::YARD::Registry.clear
|
41
42
|
::YARD.parse(paths, excluded)
|
42
43
|
end
|
@@ -44,6 +45,11 @@ module Inch
|
|
44
45
|
def inject_base_dir(dir)
|
45
46
|
objects.each do |object|
|
46
47
|
object.base_dir = dir
|
48
|
+
|
49
|
+
object.aliases_fullnames.each do |fullname|
|
50
|
+
_alias = objects.detect { |o| o.fullname == fullname }
|
51
|
+
_alias.aliased_object_fullname = object.fullname
|
52
|
+
end
|
47
53
|
end
|
48
54
|
end
|
49
55
|
|
@@ -10,14 +10,8 @@ module Inch
|
|
10
10
|
# @param code_object [YARD::Object::Base]
|
11
11
|
# @return [CodeObject::Proxy::Base]
|
12
12
|
def for(code_object)
|
13
|
-
|
14
|
-
|
15
|
-
proxy_object
|
16
|
-
else
|
17
|
-
attributes = Converter.to_hash(code_object)
|
18
|
-
proxy_object = class_for(code_object).new(attributes)
|
19
|
-
@cache[cache_key(code_object)] = proxy_object
|
20
|
-
end
|
13
|
+
attributes = Converter.to_hash(code_object)
|
14
|
+
proxy_object = class_for(code_object).new(attributes)
|
21
15
|
end
|
22
16
|
|
23
17
|
private
|
@@ -30,13 +24,6 @@ module Inch
|
|
30
24
|
class_name = code_object.class.to_s.split('::').last
|
31
25
|
const_get(class_name)
|
32
26
|
end
|
33
|
-
|
34
|
-
# Returns a cache key for the given +code_object+
|
35
|
-
#
|
36
|
-
# @return [String]
|
37
|
-
def cache_key(code_object)
|
38
|
-
code_object.fullname
|
39
|
-
end
|
40
27
|
end
|
41
28
|
end
|
42
29
|
end
|
@@ -3,11 +3,15 @@ require 'forwardable'
|
|
3
3
|
module Inch
|
4
4
|
module CodeObject
|
5
5
|
module Proxy
|
6
|
+
# This is the base class for code object proxies.
|
7
|
+
# Code object proxies are via an attributes Hash and provide all methods
|
8
|
+
# necessary for the evaluation of its documentation.
|
9
|
+
#
|
6
10
|
# @abstract
|
7
11
|
class Base
|
8
12
|
extend Forwardable
|
9
13
|
|
10
|
-
# @return [
|
14
|
+
# @return [Grade]
|
11
15
|
# when objects are assigned to GradeLists, this grade is set to
|
12
16
|
# enable easier querying for objects of a certain grade
|
13
17
|
attr_writer :grade
|
@@ -43,6 +47,16 @@ module Inch
|
|
43
47
|
}.grade
|
44
48
|
end
|
45
49
|
|
50
|
+
# @return [Boolean] if the current object is an alias for something else
|
51
|
+
def alias?
|
52
|
+
!aliased_object.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [CodeObject::Proxy::Base] the object the current object is an alias of
|
56
|
+
def aliased_object
|
57
|
+
object_lookup.find( self[:aliased_object_fullname] )
|
58
|
+
end
|
59
|
+
|
46
60
|
# @return [Boolean] +true+ if the object has an @api tag
|
47
61
|
def api_tag?
|
48
62
|
self[:api_tag?]
|
@@ -61,7 +75,7 @@ module Inch
|
|
61
75
|
end
|
62
76
|
|
63
77
|
def core?
|
64
|
-
self[:
|
78
|
+
self[:core?]
|
65
79
|
end
|
66
80
|
|
67
81
|
# The depth of the following is 4:
|
@@ -110,7 +124,7 @@ module Inch
|
|
110
124
|
end
|
111
125
|
|
112
126
|
def has_alias?
|
113
|
-
self[:
|
127
|
+
!self[:aliases_fullnames].empty?
|
114
128
|
end
|
115
129
|
|
116
130
|
def has_children?
|
@@ -152,7 +166,7 @@ module Inch
|
|
152
166
|
self[:nodoc?]
|
153
167
|
end
|
154
168
|
|
155
|
-
# @return [
|
169
|
+
# @return [CodeObject::Proxy::Base,nil] the parent of the current object or +nil+
|
156
170
|
def parent
|
157
171
|
object_lookup.find( self[:parent_fullname] )
|
158
172
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module Inch
|
2
2
|
module Evaluation
|
3
|
+
# Grades are human-friendly representations of scores.
|
4
|
+
#
|
3
5
|
class Grade
|
4
6
|
extend Utils::ReadWriteMethods
|
5
7
|
|
@@ -9,14 +11,20 @@ module Inch
|
|
9
11
|
@symbol = symbol
|
10
12
|
end
|
11
13
|
|
14
|
+
# Updates the grade's configuration with the given block
|
15
|
+
#
|
16
|
+
# @param block [Proc]
|
17
|
+
# @return [void]
|
12
18
|
def update(&block)
|
13
19
|
instance_eval(&block)
|
14
20
|
end
|
15
21
|
|
22
|
+
# @return [Symbol] the grade as a symbol (e.g. +:A+)
|
16
23
|
def to_sym
|
17
24
|
@symbol
|
18
25
|
end
|
19
26
|
|
27
|
+
# @return [String] the grade as a string (e.g. "A")
|
20
28
|
def to_s
|
21
29
|
@symbol.to_s
|
22
30
|
end
|
@@ -11,8 +11,6 @@ module Inch
|
|
11
11
|
# @return [CodeObject::Proxy::Base]
|
12
12
|
attr_accessor :object
|
13
13
|
|
14
|
-
attr_reader :min_score, :max_score
|
15
|
-
|
16
14
|
class << self
|
17
15
|
attr_reader :criteria_map
|
18
16
|
|
@@ -103,6 +101,7 @@ module Inch
|
|
103
101
|
Role::Object::TaggedAsAPI => nil,
|
104
102
|
Role::Object::TaggedAsInternalAPI => nil,
|
105
103
|
Role::Object::TaggedAsPrivate => nil,
|
104
|
+
Role::Object::Alias => object.alias? ? object.aliased_object.score : nil,
|
106
105
|
}
|
107
106
|
end
|
108
107
|
|
@@ -3,6 +3,18 @@ module Inch
|
|
3
3
|
module Role
|
4
4
|
# Roles assigned to all objects
|
5
5
|
module Object
|
6
|
+
# Role assigned to objects that are aliases.
|
7
|
+
#
|
8
|
+
class Alias < Base
|
9
|
+
applicable_if :alias?
|
10
|
+
|
11
|
+
def priority
|
12
|
+
# not sure about this yet,
|
13
|
+
# but aliases should not show up high in the reports
|
14
|
+
-7
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
6
18
|
# Role assigned to objects with a describing comment (docstring)
|
7
19
|
class WithDoc < Base
|
8
20
|
applicable_if :has_doc?
|
data/lib/inch/version.rb
CHANGED
@@ -95,7 +95,6 @@ module InchTest
|
|
95
95
|
def public_method
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
98
|
def protected_method
|
100
99
|
end
|
101
100
|
protected :protected_method
|
@@ -119,4 +118,10 @@ module InchTest
|
|
119
118
|
# Private: Normalize the filename.
|
120
119
|
def private_method_with_tomdoc
|
121
120
|
end
|
121
|
+
|
122
|
+
# @return [Boolean] something funny
|
123
|
+
def _aliased_method
|
124
|
+
end
|
125
|
+
alias _alias_method _aliased_method
|
126
|
+
|
122
127
|
end
|
@@ -0,0 +1,59 @@
|
|
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.all.empty?
|
41
|
+
assert !@prompt.ff("Foo::Bar#").empty?
|
42
|
+
assert !@prompt.f("Foo::Bar").nil?
|
43
|
+
assert !@prompt.o.nil?
|
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
|
@@ -0,0 +1,68 @@
|
|
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
|
@@ -264,6 +264,12 @@ describe ::Inch::CodeObject::Proxy::MethodObject do
|
|
264
264
|
assert_equal m1.score, m2.score
|
265
265
|
end
|
266
266
|
|
267
|
+
def test_alias_method
|
268
|
+
m1 = @objects.find("InchTest#_aliased_method")
|
269
|
+
m2 = @objects.find("InchTest#_alias_method")
|
270
|
+
assert_equal m1.score, m2.score
|
271
|
+
end
|
272
|
+
|
267
273
|
def test_overloading1
|
268
274
|
list = []
|
269
275
|
list << @objects.find("Overloading#rgb")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Föhring
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- ".ruby-version"
|
122
122
|
- ".simplecov"
|
123
123
|
- ".travis.yml"
|
124
|
+
- CHANGELOG.md
|
124
125
|
- Gemfile
|
125
126
|
- LICENSE
|
126
127
|
- README.md
|
@@ -146,15 +147,21 @@ files:
|
|
146
147
|
- lib/inch/cli/command/base.rb
|
147
148
|
- lib/inch/cli/command/base_list.rb
|
148
149
|
- lib/inch/cli/command/base_object.rb
|
150
|
+
- lib/inch/cli/command/console.rb
|
151
|
+
- lib/inch/cli/command/inspect.rb
|
149
152
|
- lib/inch/cli/command/list.rb
|
150
153
|
- lib/inch/cli/command/options/base.rb
|
151
154
|
- lib/inch/cli/command/options/base_list.rb
|
152
155
|
- lib/inch/cli/command/options/base_object.rb
|
156
|
+
- lib/inch/cli/command/options/console.rb
|
157
|
+
- lib/inch/cli/command/options/inspect.rb
|
153
158
|
- lib/inch/cli/command/options/list.rb
|
154
159
|
- lib/inch/cli/command/options/show.rb
|
155
160
|
- lib/inch/cli/command/options/stats.rb
|
156
161
|
- lib/inch/cli/command/options/suggest.rb
|
157
162
|
- lib/inch/cli/command/output/base.rb
|
163
|
+
- lib/inch/cli/command/output/console.rb
|
164
|
+
- lib/inch/cli/command/output/inspect.rb
|
158
165
|
- lib/inch/cli/command/output/list.rb
|
159
166
|
- lib/inch/cli/command/output/show.rb
|
160
167
|
- lib/inch/cli/command/output/stats.rb
|
@@ -242,6 +249,8 @@ files:
|
|
242
249
|
- test/fixtures/visibility/lib/foo.rb
|
243
250
|
- test/fixtures/yardopts/.yardopts
|
244
251
|
- test/fixtures/yardopts/foo/bar.rb
|
252
|
+
- test/integration/cli/command/console_test.rb
|
253
|
+
- test/integration/cli/command/inspect_test.rb
|
245
254
|
- test/integration/cli/command/list_test.rb
|
246
255
|
- test/integration/cli/command/show_test.rb
|
247
256
|
- test/integration/cli/command/stats_test.rb
|
@@ -292,9 +301,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
292
301
|
version: '0'
|
293
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
294
303
|
requirements:
|
295
|
-
- - "
|
304
|
+
- - ">"
|
296
305
|
- !ruby/object:Gem::Version
|
297
|
-
version:
|
306
|
+
version: 1.3.1
|
298
307
|
requirements: []
|
299
308
|
rubyforge_project:
|
300
309
|
rubygems_version: 2.2.2
|
@@ -319,6 +328,8 @@ test_files:
|
|
319
328
|
- test/fixtures/visibility/lib/foo.rb
|
320
329
|
- test/fixtures/yardopts/.yardopts
|
321
330
|
- test/fixtures/yardopts/foo/bar.rb
|
331
|
+
- test/integration/cli/command/console_test.rb
|
332
|
+
- test/integration/cli/command/inspect_test.rb
|
322
333
|
- test/integration/cli/command/list_test.rb
|
323
334
|
- test/integration/cli/command/show_test.rb
|
324
335
|
- test/integration/cli/command/stats_test.rb
|