looksee 0.2.1 → 1.0.0

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.
Files changed (57) hide show
  1. data/CHANGELOG +14 -0
  2. data/LICENSE +22 -0
  3. data/README.markdown +161 -0
  4. data/Rakefile +9 -36
  5. data/ext/extconf.rb +9 -0
  6. data/ext/mri/1.9.2/debug.h +36 -0
  7. data/ext/mri/1.9.2/id.h +170 -0
  8. data/ext/mri/1.9.2/method.h +103 -0
  9. data/ext/mri/1.9.2/node.h +483 -0
  10. data/ext/mri/1.9.2/thread_pthread.h +27 -0
  11. data/ext/mri/1.9.2/vm_core.h +707 -0
  12. data/ext/mri/1.9.2/vm_opts.h +51 -0
  13. data/ext/mri/env-1.8.h +27 -0
  14. data/ext/mri/eval_c-1.8.h +27 -0
  15. data/ext/mri/mri.c +269 -0
  16. data/ext/{looksee → mri}/node-1.9.h +0 -0
  17. data/ext/rbx/rbx.c +13 -0
  18. data/lib/looksee.rb +4 -385
  19. data/lib/looksee/adapter.rb +10 -0
  20. data/lib/looksee/adapter/base.rb +100 -0
  21. data/lib/looksee/adapter/rubinius.rb +73 -0
  22. data/lib/looksee/clean.rb +122 -0
  23. data/lib/looksee/columnizer.rb +73 -0
  24. data/lib/looksee/core_ext.rb +59 -0
  25. data/lib/looksee/editor.rb +58 -0
  26. data/lib/looksee/help.rb +54 -0
  27. data/lib/looksee/inspector.rb +55 -0
  28. data/lib/looksee/lookup_path.rb +95 -0
  29. data/lib/looksee/rbx.bundle +0 -0
  30. data/lib/looksee/shortcuts.rb +1 -105
  31. data/lib/looksee/version.rb +9 -1
  32. data/lib/looksee/wirble_compatibility.rb +2 -3
  33. data/spec/adapter_spec.rb +546 -0
  34. data/spec/columnizer_spec.rb +52 -0
  35. data/spec/core_ext_spec.rb +41 -0
  36. data/spec/editor_spec.rb +128 -0
  37. data/spec/inspector_spec.rb +178 -0
  38. data/spec/lookup_path_spec.rb +84 -0
  39. data/spec/spec_helper.rb +13 -127
  40. data/spec/support/core_ext.rb +25 -0
  41. data/spec/support/temporary_classes.rb +102 -0
  42. data/spec/support/test_adapter.rb +72 -0
  43. data/spec/wirble_compatibility_spec.rb +20 -23
  44. metadata +91 -57
  45. data/.autotest +0 -9
  46. data/History.txt +0 -22
  47. data/Manifest.txt +0 -21
  48. data/README.rdoc +0 -129
  49. data/ext/looksee/extconf.rb +0 -6
  50. data/ext/looksee/looksee.c +0 -144
  51. data/looksee.gemspec +0 -44
  52. data/script/console +0 -7
  53. data/script/destroy +0 -14
  54. data/script/generate +0 -14
  55. data/spec/looksee_spec.rb +0 -425
  56. data/tasks/extconf.rake +0 -13
  57. data/tasks/extconf/looksee.rake +0 -43
data/spec/spec_helper.rb CHANGED
@@ -1,139 +1,25 @@
1
- require 'spec'
1
+ require 'rspec'
2
2
  require 'mocha'
3
3
  require 'looksee'
4
4
 
5
5
  require 'rbconfig'
6
6
  require 'set'
7
+ require 'fileutils'
7
8
 
8
- Spec::Runner.configure do |config|
9
- config.mock_with :mocha
10
- end
9
+ ROOT = File.dirname(File.dirname(__FILE__))
11
10
 
12
- class Object
13
- #
14
- # Return this object's singleton class.
15
- #
16
- def singleton_class
17
- class << self; self; end
18
- end
19
-
20
- #
21
- # Return true if the given object include?-s this object.
22
- #
23
- def in?(object)
24
- object.include?(self)
25
- end
11
+ Dir['spec/support/*.rb'].each do |path|
12
+ require path
26
13
  end
27
14
 
28
- class String
29
- #
30
- # Remove a left margin delimited by '|'-characters. Useful for
31
- # heredocs:
32
- #
33
- def demargin
34
- gsub(/^ *\|/, '')
35
- end
36
- end
37
-
38
- #
39
- # Include these in example groups to add facilities to create
40
- # temporary classes and modules, which are swept up at the end of each
41
- # example.
42
- #
43
- # Call make_class('ClassName') or make_module('ModuleName') to create
44
- # a temporary class, then access them with plain constants (ClassName,
45
- # ModuleName).
46
- #
47
- module TemporaryClasses
48
- def self.included(mod)
49
- mod.before do
50
- @temporary_modules = []
51
- end
52
-
53
- mod.after do
54
- @temporary_modules.each do |mod|
55
- Object.send :remove_const, mod.name
56
- end
57
- end
58
- end
59
-
60
- #
61
- # Create a temporary class with the given name and superclass.
62
- #
63
- def temporary_class(name, options={}, &block)
64
- klass = Class.new(options[:superclass] || Object)
65
- Object.const_set(name, klass)
66
- klass.class_eval(&block) if block
67
- @temporary_modules << klass
68
- klass
69
- end
15
+ NATIVE_ADAPTER = Looksee.adapter
70
16
 
71
- #
72
- # Create a temporary module with the given name.
73
- #
74
- def temporary_module(name, &block)
75
- mod = Module.new
76
- Object.const_set(name, mod)
77
- mod.class_eval(&block) if block
78
- @temporary_modules << mod
79
- mod
80
- end
81
-
82
- #
83
- # Remove all methods defined exactly on the given module.
84
- #
85
- # As Ruby's reflection on singleton classes of classes isn't quite
86
- # adequate, you need to provide a :class_singleton option when such
87
- # a class is given.
88
- #
89
- def remove_methods(mod, opts={})
90
- names = all_instance_methods(mod)
91
-
92
- # all_instance_methods can't get just the methods on a class
93
- # singleton class. Filter out superclass methods here.
94
- if opts[:class_singleton]
95
- klass = ObjectSpace.each_object(mod){|klass| break klass}
96
- names -= all_instance_methods(klass.superclass.singleton_class)
97
- end
98
-
99
- names.sort_by{|name| name.in?([:remove_method, :send]) ? 1 : 0}.flatten
100
- names.each do |name|
101
- mod.send :remove_method, name
102
- end
103
- end
104
-
105
- #
106
- # Replace the methods of the given module with those named.
107
- #
108
- # +methods+ is a hash of visibilities to names.
109
- #
110
- # As Ruby's reflection on singleton classes of classes isn't quite
111
- # adequate, you need to provide a :class_singleton option when such
112
- # a class is given.
113
- #
114
- # e.g.:
115
- #
116
- # replace_methods MyClass, :public => [:a, :b]
117
- #
118
- def replace_methods(mod, options={})
119
- remove_methods(mod, options)
120
- mod.module_eval do
121
- [:public, :protected, :private].each do |visibility|
122
- Array(options[visibility]).each do |name|
123
- define_method(name){}
124
- send visibility, name
125
- end
126
- end
127
- end
128
- end
129
-
130
- private # ---------------------------------------------------------
17
+ RSpec.configure do |config|
18
+ config.mock_with :mocha
19
+ config.before { Looksee.adapter = TestAdapter.new }
20
+ end
131
21
 
132
- def all_instance_methods(mod)
133
- names =
134
- mod.public_instance_methods(false) +
135
- mod.protected_instance_methods(false) +
136
- mod.private_instance_methods(false)
137
- names.map{|name| name.to_sym} # they're strings in ruby <1.9
138
- end
22
+ if Looksee.ruby_engine == 'jruby'
23
+ require 'jruby'
24
+ JRuby.objectspace = true
139
25
  end
@@ -0,0 +1,25 @@
1
+ class Object
2
+ #
3
+ # Return this object's singleton class.
4
+ #
5
+ def singleton_class
6
+ class << self; self; end
7
+ end
8
+
9
+ #
10
+ # Return true if the given object include?-s this object.
11
+ #
12
+ def in?(object)
13
+ object.include?(self)
14
+ end
15
+ end
16
+
17
+ class String
18
+ #
19
+ # Remove a left margin delimited by '|'-characters. Useful for
20
+ # heredocs:
21
+ #
22
+ def demargin
23
+ gsub(/^ *\|/, '')
24
+ end
25
+ end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Include these in example groups to add facilities to create
3
+ # temporary classes and modules, which are swept up at the end of each
4
+ # example.
5
+ #
6
+ # Call make_class('ClassName') or make_module('ModuleName') to create
7
+ # a temporary class, then access them with plain constants (ClassName,
8
+ # ModuleName).
9
+ #
10
+ module TemporaryClasses
11
+ def self.included(mod)
12
+ mod.before do
13
+ @temporary_modules = []
14
+ end
15
+
16
+ mod.after do
17
+ @temporary_modules.each do |mod|
18
+ Object.send :remove_const, mod.name
19
+ end
20
+ end
21
+ end
22
+
23
+ #
24
+ # Create a temporary class with the given name and superclass.
25
+ #
26
+ def temporary_class(name, options={}, &block)
27
+ klass = Class.new(options[:superclass] || Object)
28
+ Object.const_set(name, klass)
29
+ klass.class_eval(&block) if block
30
+ @temporary_modules << klass
31
+ klass
32
+ end
33
+
34
+ #
35
+ # Create a temporary module with the given name.
36
+ #
37
+ def temporary_module(name, &block)
38
+ mod = Module.new
39
+ Object.const_set(name, mod)
40
+ mod.class_eval(&block) if block
41
+ @temporary_modules << mod
42
+ mod
43
+ end
44
+
45
+ #
46
+ # Remove all methods defined exactly on the given module.
47
+ #
48
+ # As Ruby's reflection on singleton classes of classes isn't quite
49
+ # adequate, you need to provide a :class_singleton option when such
50
+ # a class is given.
51
+ #
52
+ def remove_methods(mod, opts={})
53
+ names = all_instance_methods(mod)
54
+
55
+ # all_instance_methods can't get just the methods on a class
56
+ # singleton class. Filter out superclass methods here.
57
+ if opts[:class_singleton]
58
+ klass = ObjectSpace.each_object(mod){|klass| break klass}
59
+ names -= all_instance_methods(klass.superclass.singleton_class)
60
+ end
61
+
62
+ names.sort_by{|name| name.in?([:remove_method, :send]) ? 1 : 0}.flatten
63
+ names.each do |name|
64
+ mod.send :remove_method, name
65
+ end
66
+ end
67
+
68
+ #
69
+ # Replace the methods of the given module with those named.
70
+ #
71
+ # +methods+ is a hash of visibilities to names.
72
+ #
73
+ # As Ruby's reflection on singleton classes of classes isn't quite
74
+ # adequate, you need to provide a :class_singleton option when such
75
+ # a class is given.
76
+ #
77
+ # e.g.:
78
+ #
79
+ # replace_methods MyClass, :public => [:a, :b]
80
+ #
81
+ def replace_methods(mod, options={})
82
+ remove_methods(mod, options)
83
+ mod.module_eval do
84
+ [:public, :protected, :private].each do |visibility|
85
+ Array(options[visibility]).each do |name|
86
+ define_method(name){}
87
+ send visibility, name
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ private # ---------------------------------------------------------
94
+
95
+ def all_instance_methods(mod)
96
+ names =
97
+ mod.public_instance_methods(false) +
98
+ mod.protected_instance_methods(false) +
99
+ mod.private_instance_methods(false)
100
+ names.map{|name| name.to_sym} # they're strings in ruby <1.9
101
+ end
102
+ end
@@ -0,0 +1,72 @@
1
+ class TestAdapter < Looksee::Adapter::Base
2
+ def lookup_modules(object)
3
+ ancestors[object]
4
+ end
5
+
6
+ def internal_public_instance_methods(mod)
7
+ public_methods[mod]
8
+ end
9
+
10
+ def internal_protected_instance_methods(mod)
11
+ protected_methods[mod]
12
+ end
13
+
14
+ def internal_private_instance_methods(mod)
15
+ private_methods[mod]
16
+ end
17
+
18
+ def internal_undefined_instance_methods(mod)
19
+ undefined_methods[mod]
20
+ end
21
+
22
+ def singleton_class?(object)
23
+ NATIVE_ADAPTER.singleton_class?(object)
24
+ end
25
+
26
+ def singleton_instance(object)
27
+ NATIVE_ADAPTER.singleton_instance(object)
28
+ end
29
+
30
+ def module_name(object)
31
+ NATIVE_ADAPTER.module_name(object)
32
+ end
33
+
34
+ def set_methods(mod, public, protected, private, undefined)
35
+ self.public_methods[mod] = public
36
+ self.protected_methods[mod] = protected
37
+ self.private_methods[mod] = private
38
+ self.undefined_methods[mod] = undefined
39
+ end
40
+
41
+ def source_location(method)
42
+ source_locations[[method.owner.name.to_s, method.name.to_s]]
43
+ end
44
+
45
+ def set_source_location(mod, method, location)
46
+ source_locations[[mod.name.to_s, method.to_s]] = location
47
+ end
48
+
49
+ def ancestors
50
+ @ancestors ||= Hash.new { |h, k| h[k] = [] }
51
+ end
52
+
53
+ def public_methods
54
+ @public_methods ||= Hash.new { |h, k| h[k] = [] }
55
+ end
56
+
57
+ def protected_methods
58
+ @protected_methods ||= Hash.new { |h, k| h[k] = [] }
59
+ end
60
+
61
+ def private_methods
62
+ @private_methods ||= Hash.new { |h, k| h[k] = [] }
63
+ end
64
+
65
+ def undefined_methods
66
+ @undefined_methods ||= Hash.new { |h, k| h[k] = [] }
67
+ end
68
+
69
+ def source_locations
70
+ @source_locations ||= {}
71
+ end
72
+ end
@@ -7,12 +7,13 @@ describe Looksee::WirbleCompatibility do
7
7
  # Run the given ruby string, and return the standard output.
8
8
  #
9
9
  def init_irb_with(code)
10
- code = <<-EOS.demargin.gsub(/\n/, ';')
10
+ code = <<-EOS.demargin
11
11
  |#{code}
12
- |#{stubbing_code}
13
- |lp Object.new
12
+ |#{setup_code}
13
+ |c.ls
14
14
  EOS
15
- irb = File.join Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'].sub(/ruby/, 'irb')
15
+ code = code.chomp.gsub(/\n/, ';') # only print value of last line
16
+ irb = File.join Config::CONFIG['bindir'], 'irb'
16
17
  lib_dir = File.expand_path('lib')
17
18
  # irb hangs when using readline without a tty
18
19
  output = IO.popen("#{irb} -f --noreadline --noprompt --noverbose -I#{lib_dir} 2>&1", 'r+') do |io|
@@ -21,34 +22,30 @@ describe Looksee::WirbleCompatibility do
21
22
  io.close_write
22
23
  io.read
23
24
  end
25
+ # Ruby 1.9.2 prints an extra newline on exit.
26
+ output.chomp! if RUBY_VERSION >= '1.9.2'
27
+ output
24
28
  end
25
29
 
26
- def stubbing_code
30
+ def setup_code
27
31
  <<-EOS.demargin
28
32
  |C = Class.new
33
+ |c = C.new
34
+ |#{File.read('spec/support/test_adapter.rb')}
29
35
  |
30
36
  |Looksee.styles = Hash.new{'%s'}
31
37
  |Looksee.styles[:public] = "\\e[1;32m%s\\e[0m"
32
- |
33
- |def Looksee.lookup_modules(object)
34
- | [C]
35
- |end
36
- |def Looksee.internal_public_instance_methods(mod)
37
- | [:a]
38
- |end
39
- |def Looksee.internal_protected_instance_methods(mod)
40
- | []
41
- |end
42
- |def Looksee.internal_private_instance_methods(mod)
43
- | []
44
- |end
38
+ |NATIVE_ADAPTER = Looksee.adapter
39
+ |Looksee.adapter = TestAdapter.new
40
+ |Looksee.adapter.ancestors[c] = [C]
41
+ |Looksee.adapter.public_methods[C] = [:a]
45
42
  EOS
46
43
  end
47
44
 
48
45
  it "should work if wirble is not loaded" do
49
46
  output = init_irb_with(<<-EOS.demargin)
50
47
  |require 'irb'
51
- |require 'looksee/shortcuts'
48
+ |require 'looksee'
52
49
  |require 'wirble'
53
50
  |Wirble.init
54
51
  |Wirble.colorize
@@ -63,7 +60,7 @@ describe Looksee::WirbleCompatibility do
63
60
  output = init_irb_with(<<-EOS.demargin)
64
61
  |require 'irb'
65
62
  |require 'wirble'
66
- |require 'looksee/shortcuts'
63
+ |require 'looksee'
67
64
  |Wirble.init
68
65
  |Wirble.colorize
69
66
  EOS
@@ -78,7 +75,7 @@ describe Looksee::WirbleCompatibility do
78
75
  |require 'irb'
79
76
  |require 'wirble'
80
77
  |Wirble.init
81
- |require 'looksee/shortcuts'
78
+ |require 'looksee'
82
79
  |Wirble.colorize
83
80
  EOS
84
81
  output.should == <<-EOS.demargin
@@ -93,7 +90,7 @@ describe Looksee::WirbleCompatibility do
93
90
  |require 'wirble'
94
91
  |Wirble.init
95
92
  |Wirble.colorize
96
- |require 'looksee/shortcuts'
93
+ |require 'looksee'
97
94
  EOS
98
95
  output.should == <<-EOS.demargin
99
96
  |C
@@ -104,7 +101,7 @@ describe Looksee::WirbleCompatibility do
104
101
  it "should work if wirble colorizing is enabled twice" do
105
102
  output = init_irb_with(<<-EOS.demargin)
106
103
  |require 'irb'
107
- |require 'looksee/shortcuts'
104
+ |require 'looksee'
108
105
  |require 'wirble'
109
106
  |Wirble.init
110
107
  |Wirble.colorize