inch 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +335 -3
  4. data/Rakefile +8 -0
  5. data/TODOS.md +12 -0
  6. data/bin/inch +17 -0
  7. data/inch.gemspec +7 -2
  8. data/lib/inch.rb +6 -1
  9. data/lib/inch/cli.rb +24 -0
  10. data/lib/inch/cli/arguments.rb +45 -0
  11. data/lib/inch/cli/command.rb +29 -0
  12. data/lib/inch/cli/command/base.rb +62 -0
  13. data/lib/inch/cli/command/base_list.rb +75 -0
  14. data/lib/inch/cli/command/base_object.rb +40 -0
  15. data/lib/inch/cli/command/console.rb +22 -0
  16. data/lib/inch/cli/command/inspect.rb +20 -0
  17. data/lib/inch/cli/command/list.rb +25 -0
  18. data/lib/inch/cli/command/options/base.rb +137 -0
  19. data/lib/inch/cli/command/options/base_list.rb +84 -0
  20. data/lib/inch/cli/command/options/base_object.rb +47 -0
  21. data/lib/inch/cli/command/options/console.rb +26 -0
  22. data/lib/inch/cli/command/options/inspect.rb +25 -0
  23. data/lib/inch/cli/command/options/list.rb +30 -0
  24. data/lib/inch/cli/command/options/show.rb +27 -0
  25. data/lib/inch/cli/command/options/stats.rb +20 -0
  26. data/lib/inch/cli/command/options/suggest.rb +61 -0
  27. data/lib/inch/cli/command/output/base.rb +32 -0
  28. data/lib/inch/cli/command/output/console.rb +45 -0
  29. data/lib/inch/cli/command/output/inspect.rb +129 -0
  30. data/lib/inch/cli/command/output/list.rb +87 -0
  31. data/lib/inch/cli/command/output/show.rb +79 -0
  32. data/lib/inch/cli/command/output/stats.rb +111 -0
  33. data/lib/inch/cli/command/output/suggest.rb +104 -0
  34. data/lib/inch/cli/command/show.rb +20 -0
  35. data/lib/inch/cli/command/stats.rb +20 -0
  36. data/lib/inch/cli/command/suggest.rb +104 -0
  37. data/lib/inch/cli/command_parser.rb +82 -0
  38. data/lib/inch/cli/sparkline_helper.rb +31 -0
  39. data/lib/inch/cli/trace_helper.rb +42 -0
  40. data/lib/inch/cli/yardopts_helper.rb +49 -0
  41. data/lib/inch/code_object.rb +8 -0
  42. data/lib/inch/code_object/docstring.rb +97 -0
  43. data/lib/inch/code_object/nodoc_helper.rb +84 -0
  44. data/lib/inch/code_object/proxy.rb +37 -0
  45. data/lib/inch/code_object/proxy/base.rb +194 -0
  46. data/lib/inch/code_object/proxy/class_object.rb +9 -0
  47. data/lib/inch/code_object/proxy/constant_object.rb +8 -0
  48. data/lib/inch/code_object/proxy/method_object.rb +118 -0
  49. data/lib/inch/code_object/proxy/method_parameter_object.rb +81 -0
  50. data/lib/inch/code_object/proxy/module_object.rb +8 -0
  51. data/lib/inch/code_object/proxy/namespace_object.rb +38 -0
  52. data/lib/inch/core_ext.rb +2 -0
  53. data/lib/inch/core_ext/string.rb +3 -0
  54. data/lib/inch/core_ext/yard.rb +4 -0
  55. data/lib/inch/evaluation.rb +35 -0
  56. data/lib/inch/evaluation/base.rb +60 -0
  57. data/lib/inch/evaluation/class_object.rb +6 -0
  58. data/lib/inch/evaluation/constant_object.rb +34 -0
  59. data/lib/inch/evaluation/file.rb +66 -0
  60. data/lib/inch/evaluation/method_object.rb +127 -0
  61. data/lib/inch/evaluation/module_object.rb +6 -0
  62. data/lib/inch/evaluation/namespace_object.rb +94 -0
  63. data/lib/inch/evaluation/role/base.rb +49 -0
  64. data/lib/inch/evaluation/role/constant.rb +43 -0
  65. data/lib/inch/evaluation/role/method.rb +60 -0
  66. data/lib/inch/evaluation/role/method_parameter.rb +46 -0
  67. data/lib/inch/evaluation/role/missing.rb +20 -0
  68. data/lib/inch/evaluation/role/namespace.rb +58 -0
  69. data/lib/inch/evaluation/role/object.rb +64 -0
  70. data/lib/inch/evaluation/score_range.rb +26 -0
  71. data/lib/inch/rake.rb +1 -0
  72. data/lib/inch/rake/suggest.rb +26 -0
  73. data/lib/inch/source_parser.rb +36 -0
  74. data/lib/inch/version.rb +1 -1
  75. data/test/fixtures/code_examples/lib/foo.rb +87 -0
  76. data/test/fixtures/readme/lib/foo.rb +17 -0
  77. data/test/fixtures/simple/README +25 -0
  78. data/test/fixtures/simple/lib/broken.rb +10 -0
  79. data/test/fixtures/simple/lib/foo.rb +214 -0
  80. data/test/fixtures/simple/lib/role_methods.rb +78 -0
  81. data/test/fixtures/simple/lib/role_namespaces.rb +68 -0
  82. data/test/fixtures/visibility/lib/foo.rb +18 -0
  83. data/test/fixtures/yardopts/.yardopts +1 -0
  84. data/test/fixtures/yardopts/foo/bar.rb +6 -0
  85. data/test/inch/cli/arguments_test.rb +70 -0
  86. data/test/inch/cli/command/console_test.rb +59 -0
  87. data/test/inch/cli/command/inspect_test.rb +59 -0
  88. data/test/inch/cli/command/list_test.rb +61 -0
  89. data/test/inch/cli/command/show_test.rb +59 -0
  90. data/test/inch/cli/command/stats_test.rb +57 -0
  91. data/test/inch/cli/command/suggest_test.rb +57 -0
  92. data/test/inch/cli/command_parser_test.rb +33 -0
  93. data/test/inch/cli/yardopts_helper_test.rb +84 -0
  94. data/test/inch/code_object/docstring_test.rb +204 -0
  95. data/test/inch/code_object/nodoc_helper_test.rb +38 -0
  96. data/test/inch/code_object/proxy_test.rb +188 -0
  97. data/test/inch/source_parser_test.rb +23 -0
  98. data/test/integration/stats_options_test.rb +34 -0
  99. data/test/integration/visibility_options_test.rb +79 -0
  100. data/test/test_helper.rb +21 -0
  101. metadata +184 -7
@@ -0,0 +1,78 @@
1
+ def root_method
2
+ end
3
+
4
+ module InchTest
5
+ def bang_method!
6
+ end
7
+
8
+ def splat_method(*args)
9
+ end
10
+
11
+ def block_method(&block)
12
+ end
13
+
14
+ def question_mark_method?
15
+ if true
16
+ bang_method!
17
+ end
18
+ end
19
+
20
+ def many_parameters_method(a,b,c,d,e,f)
21
+ end
22
+
23
+ def alias_method
24
+ end
25
+ alias :am :alias_method
26
+
27
+ def many_lines_method
28
+ if true
29
+ if true
30
+ if true
31
+ if true
32
+ bang_method!
33
+ end
34
+ end
35
+ end
36
+ end
37
+ if true
38
+ if true
39
+ if true
40
+ if true
41
+ bang_method!
42
+ end
43
+ end
44
+ end
45
+ end
46
+ if true
47
+ if true
48
+ if true
49
+ if true
50
+ bang_method!
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ # @deprecated
58
+ # @see InchTest
59
+ def unconsidered_tags_method
60
+ end
61
+ public :public_method
62
+
63
+ def public_method
64
+ end
65
+
66
+
67
+ def protected_method
68
+ end
69
+ protected :protected_method
70
+
71
+ def private_method
72
+ end
73
+ private :private_method
74
+
75
+ # @private
76
+ def method_with_private_tag
77
+ end
78
+ end
@@ -0,0 +1,68 @@
1
+
2
+ # @deprecated
3
+ # @see PureNamespace
4
+ PUBLIC_ROOT_CONSTANT = :foo
5
+
6
+ class String
7
+ def foobar
8
+ self + 'foobar!'
9
+ end
10
+ end
11
+
12
+ module InchTest
13
+ # You would want to use it like this:
14
+ #
15
+ # CodeExample.new
16
+ #
17
+ class CodeExample
18
+ end
19
+
20
+ # You would want to use it like this:
21
+ #
22
+ # CodeExample.new
23
+ #
24
+ # CodeExample.new # => something
25
+ #
26
+ class MultipleCodeExamples
27
+ end
28
+
29
+ module PureNamespace
30
+ end
31
+
32
+ # @deprecated
33
+ # @see PureNamespace
34
+ module ManyChildren
35
+ class Base0; end
36
+ class Base1; end
37
+ class Base2; end
38
+ class Base3; end
39
+ class Base4; end
40
+ class Base5; end
41
+ class Base6; end
42
+ class Base7; end
43
+ class Base8; end
44
+ class Base9; end
45
+ class Base10; end
46
+ class Base11; end
47
+ class Base12; end
48
+ class Base13; end
49
+ class Base14; end
50
+ class Base15; end
51
+ class Base16; end
52
+ class Base17; end
53
+ class Base18; end
54
+ class Base19; end
55
+ class Base20; end
56
+ class Base21; end
57
+ end
58
+
59
+ module ManyAttributes
60
+ attr_accessor :base0
61
+ attr_accessor :base1
62
+ attr_accessor :base2
63
+ attr_accessor :base3
64
+ attr_accessor :base4
65
+ attr_accessor :base5
66
+ attr_accessor :base6
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ class Foo
2
+ def public_method
3
+ end
4
+ public :public_method
5
+
6
+
7
+ def protected_method
8
+ end
9
+ protected :protected_method
10
+
11
+ def private_method
12
+ end
13
+ private :private_method
14
+
15
+ # @private
16
+ def method_with_private_tag
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ foo/**/*.rb
@@ -0,0 +1,6 @@
1
+ class Foo
2
+ class Bar
3
+ def initialize
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,70 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ describe ::Inch::CLI::Arguments do
4
+ before do
5
+ Dir.chdir fixture_path(:simple)
6
+ assert File.file?("README")
7
+ end
8
+
9
+ it "should run with files" do
10
+ args = [
11
+ "lib/**/*.rb", "app/**/*.rb", "README"
12
+ ]
13
+ arguments = ::Inch::CLI::Arguments.new(args)
14
+ assert_equal ["lib/**/*.rb", "app/**/*.rb", "README"], arguments.files
15
+ assert_equal [], arguments.object_names
16
+ assert_equal [], arguments.switches
17
+ end
18
+
19
+ it "should run with directories as well" do
20
+ args = [
21
+ "lib", "app/**/*.rb", "README"
22
+ ]
23
+ arguments = ::Inch::CLI::Arguments.new(args)
24
+ assert_equal ["lib", "app/**/*.rb", "README"], arguments.files
25
+ assert_equal [], arguments.object_names
26
+ assert_equal [], arguments.switches
27
+ end
28
+
29
+ it "should run with files and object_name" do
30
+ args = [
31
+ "{app,lib}.rb", "README", "Foo"
32
+ ]
33
+ arguments = ::Inch::CLI::Arguments.new(args)
34
+ assert_equal ["{app,lib}.rb", "README"], arguments.files
35
+ assert_equal ["Foo"], arguments.object_names
36
+ assert_equal [], arguments.switches
37
+ end
38
+
39
+ it "should run with object_names" do
40
+ args = [
41
+ "Foo::Bar"
42
+ ]
43
+ arguments = ::Inch::CLI::Arguments.new(args)
44
+ assert_equal [], arguments.files, "files"
45
+ assert_equal ["Foo::Bar"], arguments.object_names
46
+ assert_equal [], arguments.switches
47
+ end
48
+
49
+ it "should run with option switches" do
50
+ args = [
51
+ "--no-color", "--all"
52
+ ]
53
+ arguments = ::Inch::CLI::Arguments.new(args)
54
+ assert_equal [], arguments.files
55
+ assert_equal [], arguments.object_names
56
+ assert_equal ["--no-color", "--all"], arguments.switches
57
+ end
58
+
59
+ it "should run with all of them" do
60
+ args = [
61
+ "lib/**/*.rb", "app/**/*.rb", "README",
62
+ "Foo", "Foo::Bar", "--no-color", "--all"
63
+ ]
64
+ arguments = ::Inch::CLI::Arguments.new(args)
65
+ assert_equal ["lib/**/*.rb", "app/**/*.rb", "README"], arguments.files
66
+ assert_equal ["Foo", "Foo::Bar"], arguments.object_names
67
+ assert_equal ["--no-color", "--all"], arguments.switches
68
+ end
69
+
70
+ 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.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
@@ -0,0 +1,59 @@
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
+ it "should output all children info when run with a partial name" do
37
+ out, err = capture_io do
38
+ @command.run("Foo::Bar#", "--no-color")
39
+ end
40
+ refute out.empty?, "there should be some output"
41
+ assert_match /\bFoo::Bar#method_without_doc\b/, out
42
+ assert_match /\bFoo::Bar#method_with_full_doc\b/, out
43
+ assert err.empty?, "there should be no errors"
44
+ end
45
+
46
+ it "should output colored information" do
47
+ out, err = capture_io do
48
+ @command.run("Foo::Bar#")
49
+ end
50
+ refute_equal out.uncolor, out, "should be colored"
51
+ end
52
+
53
+ it "should output uncolored information when asked" do
54
+ out, err = capture_io do
55
+ @command.run("Foo::Bar#", "--no-color")
56
+ end
57
+ assert_equal out.uncolor, out, "should not be colored"
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
+
3
+ describe ::Inch::CLI::Command::List do
4
+ before do
5
+ Dir.chdir fixture_path(:simple)
6
+ @command = ::Inch::CLI::Command::List
7
+ end
8
+
9
+ it "should run without args" do
10
+ out, err = capture_io do
11
+ @command.run()
12
+ end
13
+ refute out.empty?, "there should be some output"
14
+ assert err.empty?, "there should be no errors"
15
+ assert_match /\bFoo\b/, out
16
+ assert_match /\bFoo::Bar\b/, out
17
+ assert_match /\bFoo::Bar#method_with_full_doc\b/, out
18
+ assert_match /\bFoo::Bar#method_with_code_example\b/, out
19
+ end
20
+
21
+ it "should run with --numbers switch" do
22
+ out, err = capture_io do
23
+ @command.run("--numbers")
24
+ end
25
+ refute out.empty?, "there should be some output"
26
+ assert err.empty?, "there should be no errors"
27
+ assert_match /\bFoo\b/, out
28
+ assert_match /\bFoo::Bar\b/, out
29
+ assert_match /\bFoo::Bar#method_with_full_doc\b/, out
30
+ assert_match /\bFoo::Bar#method_with_code_example\b/, out
31
+ end
32
+
33
+ it "should run with filelist in args" do
34
+ out, err = capture_io do
35
+ @command.run("lib/**/*.rb", "app/**/*.rb")
36
+ end
37
+ refute out.empty?, "there should be some output"
38
+ assert err.empty?, "there should be no errors"
39
+ assert_match /\bFoo\b/, out
40
+ assert_match /\bFoo::Bar\b/, out
41
+ assert_match /\bFoo::Bar#method_with_full_doc\b/, out
42
+ assert_match /\bFoo::Bar#method_with_code_example\b/, out
43
+ end
44
+
45
+ it "should run with non-existing filelist in args" do
46
+ out, err = capture_io do
47
+ @command.run("app/**/*.rb")
48
+ end
49
+ assert out.empty?, "there should be no output"
50
+ assert err.empty?, "there should be no errors"
51
+ end
52
+
53
+ it "should output info when run with --help" do
54
+ out, err = capture_io do
55
+ assert_raises(SystemExit) { @command.run("--help") }
56
+ end
57
+ refute out.empty?, "there should be some output"
58
+ assert_match /\bUsage\b.+list/, out
59
+ assert err.empty?, "there should be no errors"
60
+ end
61
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../test_helper')
2
+
3
+ describe ::Inch::CLI::Command::Show do
4
+ before do
5
+ Dir.chdir fixture_path(:simple)
6
+ @command = ::Inch::CLI::Command::Show
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.+show/, 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
+ it "should output all children info when run with a partial name" do
37
+ out, err = capture_io do
38
+ @command.run("Foo::Bar#", "--no-color")
39
+ end
40
+ refute out.empty?, "there should be some output"
41
+ assert_match /\bFoo::Bar#method_without_doc\b/, out
42
+ assert_match /\bFoo::Bar#method_with_full_doc\b/, out
43
+ assert err.empty?, "there should be no errors"
44
+ end
45
+
46
+ it "should output colored information" do
47
+ out, err = capture_io do
48
+ @command.run("Foo::Bar#")
49
+ end
50
+ refute_equal out.uncolor, out, "should be colored"
51
+ end
52
+
53
+ it "should output uncolored information when asked" do
54
+ out, err = capture_io do
55
+ @command.run("Foo::Bar#", "--no-color")
56
+ end
57
+ assert_equal out.uncolor, out, "should not be colored"
58
+ end
59
+ end