police-vminfo 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,9 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem 'bundler', '>= 1.1.0'
5
- gem 'jeweler', '>= 1.8.3'
6
- gem 'minitest', '>= 2.11.2'
7
- gem 'rdoc', '>= 3.12'
8
- gem 'simplecov', '>= 0.6.1'
9
- gem 'yard', '>= 0.7'
4
+ gem 'bundler', '>= 1.3.5'
5
+ gem 'jeweler', '>= 1.8.4'
6
+ gem 'minitest', '>= 4.7.4'
7
+ gem 'simplecov', '>= 0.7.1'
8
+ gem 'yard', '>= 0.8.6.1'
10
9
  end
data/Gemfile.lock CHANGED
@@ -1,31 +1,30 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
4
  git (1.2.5)
5
- jeweler (1.8.3)
5
+ jeweler (1.8.4)
6
6
  bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
9
  rdoc
10
- json (1.6.6)
11
- minitest (2.11.4)
12
- multi_json (1.2.0)
13
- rake (0.9.2.2)
14
- rdoc (3.12)
10
+ json (1.7.7)
11
+ minitest (4.7.4)
12
+ multi_json (1.7.3)
13
+ rake (10.0.4)
14
+ rdoc (4.0.1)
15
15
  json (~> 1.4)
16
- simplecov (0.6.1)
16
+ simplecov (0.7.1)
17
17
  multi_json (~> 1.0)
18
- simplecov-html (~> 0.5.3)
19
- simplecov-html (0.5.3)
20
- yard (0.7.5)
18
+ simplecov-html (~> 0.7.1)
19
+ simplecov-html (0.7.1)
20
+ yard (0.8.6.1)
21
21
 
22
22
  PLATFORMS
23
23
  ruby
24
24
 
25
25
  DEPENDENCIES
26
- bundler (>= 1.1.0)
27
- jeweler (>= 1.8.3)
28
- minitest (>= 2.11.2)
29
- rdoc (>= 3.12)
30
- simplecov (>= 0.6.1)
31
- yard (>= 0.7)
26
+ bundler (>= 1.3.5)
27
+ jeweler (>= 1.8.4)
28
+ minitest (>= 4.7.4)
29
+ simplecov (>= 0.7.1)
30
+ yard (>= 0.8.6.1)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -4,8 +4,8 @@ module VmInfo
4
4
  # All loaded Ruby modules, obtained by walking the constants graph.
5
5
  #
6
6
  # @return [Array<Module>] the Ruby modules that could be discovered by
7
- # searching the constants graph; this should include everything except for
8
- # anonymous (not assigned to constants) classes
7
+ # searching the constants graph; this should include everything except
8
+ # for anonymous (not assigned to constants) classes
9
9
  def self.named_modules
10
10
  # NOTE: this is a Set, but we don't want to load the module.
11
11
  explored = { Object => true }
@@ -36,13 +36,13 @@ module VmInfo
36
36
  # Note that all classes are modules, so this is a subset of named_modules.
37
37
  #
38
38
  # @return [Array<Module>] the Ruby classes that could be discovered by
39
- # searching the constants graph; this should include everything except for
40
- # anonymous (not assigned to constants) classes
39
+ # searching the constants graph; this should include everything except
40
+ # for anonymous (not assigned to constants) classes
41
41
  def self.named_classes
42
42
  named_modules.select { |m| m.kind_of? Class }
43
43
  end
44
-
45
- # All loaded Ruby modules, obtained by querying ObjectSpace.
44
+
45
+ # All loaded Ruby modules, obtained by querying ObjectSpace.
46
46
  #
47
47
  # Querying ObjectSpace can be painfully slow, especially on non-MRI VMs.
48
48
  #
@@ -50,24 +50,24 @@ module VmInfo
50
50
  def self.all_modules
51
51
  ObjectSpace.each_object(Module).to_a
52
52
  end
53
-
54
- # All loaded Ruby classes, obtained by querying ObjectSpace.
53
+
54
+ # All loaded Ruby classes, obtained by querying ObjectSpace.
55
55
  #
56
56
  # Querying ObjectSpace can be painfully slow, especially on non-MRI VMs. Note
57
- # that all classes are modules, so this is a subset of all_modules.
57
+ # that all classes are modules, so this is a subset of all_modules.
58
58
  #
59
59
  # @return [Array<Classes>] all the Ruby classes
60
60
  def self.all_classes
61
61
  ObjectSpace.each_object(Class).to_a
62
62
  end
63
-
63
+
64
64
  # The modules making up the Ruby VM implementation.
65
65
  #
66
66
  # @return [Array<Module>] the modules that are present in a vanilla Ruby
67
67
  # environment
68
68
  def self.core_modules
69
69
  return @core_modules if @core_modules
70
-
70
+
71
71
  output =
72
72
  `#{Gem.ruby} -e 'puts ObjectSpace.each_object(Module).to_a.join("\n")'`
73
73
  modules = []
@@ -82,14 +82,14 @@ module VmInfo
82
82
  next
83
83
  end
84
84
  end
85
-
85
+
86
86
  @core_modules = modules.freeze
87
87
  end
88
88
  @core_modules = nil
89
-
89
+
90
90
  # The classes making up the Ruby VM implementation.
91
91
  #
92
- # Note that all classes are modules, so this is a subset of core_modules.
92
+ # Note that all classes are modules, so this is a subset of core_modules.
93
93
  #
94
94
  # @return [Array<Class>] the classes that are present in a vanilla Ruby
95
95
  # environment
@@ -99,11 +99,11 @@ module VmInfo
99
99
  @core_classes.freeze
100
100
  end
101
101
  @core_classes = nil
102
-
102
+
103
103
  # All methods defined in a class or module.
104
104
  #
105
105
  # @param [Module] module_or_class a Class or Module instance
106
- # @return [Array<Method, UnboundMethod>] all the class and instance methods
106
+ # @return [Array<UnboundMethod>] all the class and instance methods
107
107
  # defined by the given Class or Module
108
108
  def self.all_methods(module_or_class)
109
109
  class_methods(module_or_class) + instance_methods(module_or_class)
@@ -112,8 +112,8 @@ module VmInfo
112
112
  # All instance methods defined in a class or module.
113
113
  #
114
114
  # @param [Module] module_or_class a Class or Module instance
115
- # @return [Array<Method, UnboundMethod>] all the instance methods defined by
116
- # the given Class or Module
115
+ # @return [Array<UnboundMethod>] all the instance methods defined by the
116
+ # given Class or Module
117
117
  def self.instance_methods(module_or_class)
118
118
  module_or_class.instance_methods.tap do |array|
119
119
  array.map! { |name| module_or_class.instance_method name }
@@ -123,23 +123,64 @@ module VmInfo
123
123
 
124
124
  # All class methods defined in a class or module.
125
125
  #
126
- # Note: the class methods of a class or module are the instance methods of the
127
- # class or module's meta-class.
126
+ # Note: the class methods of a class or module are the instance methods of
127
+ # the class or module's meta-class.
128
128
  #
129
129
  # @param [Module] module_or_class a Class or Module instance
130
- # @return [Array<Method, UnboundMethod>] all the instance methods defined by
131
- # the given Class or Module
130
+ # @return [Array<UnboundMethod>] all the instance methods defined by the
131
+ # given Class or Module
132
132
  def self.class_methods(module_or_class)
133
133
  # NOTE: this long-winded approach avoids creating new singleton classes
134
134
  method_names = module_or_class.singleton_methods
135
135
  return [] if method_names.empty?
136
136
  singleton_class = module_or_class.singleton_class
137
137
  method_names.tap do |array|
138
- array.map! { |name| module_or_class.method name }
138
+ array.map! { |name| singleton_class.instance_method name }
139
139
  array.select! { |method| method.owner == singleton_class }
140
140
  end
141
141
  end
142
-
142
+
143
+ # The core instance methods defined in a core class or module.
144
+ #
145
+ # @param [Module] module_or_class the module or class whose instance methods
146
+ # will be retrieved; should be one of the core modules / classes in the
147
+ # Ruby VM
148
+ # @return [Array<UnboundMethod>] the instance methods defined by the Ruby VM
149
+ def self.core_instance_methods(module_or_class)
150
+ output =
151
+ `#{Gem.ruby} -e 'puts #{module_or_class}.instance_methods.join("\n")'`
152
+
153
+ methods = []
154
+ output.split("\n").each do |name|
155
+ method = module_or_class.instance_method name.to_sym
156
+ # TODO(pwnall): consider checking for re-defined core methods
157
+ methods << method
158
+ end
159
+ methods
160
+ end
161
+
162
+ # The core class methods defined in a core class or module.
163
+ #
164
+ # @param [Module] module_or_class the module or class whose class methods
165
+ # will be retrieved; should be one of the core modules / classes in the
166
+ # Ruby VM
167
+ # @return [Array<UnboundMethod>] the class methods defined by the Ruby VM
168
+ def self.core_class_methods(module_or_class)
169
+ output =
170
+ `#{Gem.ruby} -e 'puts #{module_or_class}.singleton_methods.join("\n")'`
171
+
172
+ methods = []
173
+ method_names = output.split "\n"
174
+ return [] if method_names.empty?
175
+ singleton_class = module_or_class.singleton_class
176
+ output.split("\n").each do |name|
177
+ method = singleton_class.instance_method name.to_sym
178
+ # TODO(pwnall): consider checking for re-defined core methods
179
+ methods << method
180
+ end
181
+ methods
182
+ end
183
+
143
184
  # Resolves the name of a constant into its value.
144
185
  #
145
186
  # @param [String] name a constant name, potentially including the scope
@@ -157,7 +198,7 @@ module VmInfo
157
198
  value.const_missing segment
158
199
  end
159
200
  end
160
- value
201
+ value
161
202
  end
162
203
  end # namespace VmInfo
163
204
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "police-vminfo"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Victor Costan"]
12
- s.date = "2012-03-28"
12
+ s.date = "2013-05-08"
13
13
  s.description = "Collects information about the Ruby VM implementation details."
14
14
  s.email = "victor@costan.us"
15
15
  s.extra_rdoc_files = [
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.homepage = "http://github.com/pwnall/police-vminfo"
39
39
  s.licenses = ["MIT"]
40
40
  s.require_paths = ["lib"]
41
- s.rubygems_version = "1.8.21"
41
+ s.rubygems_version = "1.8.23"
42
42
  s.summary = "Information about the Ruby VM internals."
43
43
 
44
44
  if s.respond_to? :specification_version then
@@ -7,7 +7,7 @@ describe Police::VmInfo do
7
7
  CORE_CLASSES = [Object, Encoding::Converter]
8
8
  GEM_CLASSES = [MiniTest::Unit]
9
9
  CLASSES = CORE_CLASSES + GEM_CLASSES
10
-
10
+
11
11
  describe '#named_modules' do
12
12
  let(:result) { Police::VmInfo.named_modules }
13
13
  (MODULES + CLASSES).each do |const|
@@ -16,7 +16,7 @@ describe Police::VmInfo do
16
16
  end
17
17
  end
18
18
  end
19
-
19
+
20
20
  describe '#named_classes' do
21
21
  let(:result) { Police::VmInfo.named_classes }
22
22
 
@@ -25,7 +25,7 @@ describe Police::VmInfo do
25
25
  result.must_include const
26
26
  end
27
27
  end
28
-
28
+
29
29
  MODULES.each do |const|
30
30
  it "does not contain #{const}" do
31
31
  result.wont_include const
@@ -40,7 +40,7 @@ describe Police::VmInfo do
40
40
  result.must_include const
41
41
  end
42
42
  end
43
-
43
+
44
44
  it 'contains anonymous module' do
45
45
  anonymous_module = Module.new
46
46
  Police::VmInfo.all_modules.must_include anonymous_module
@@ -51,7 +51,7 @@ describe Police::VmInfo do
51
51
  Police::VmInfo.all_modules.must_include anonymous_class
52
52
  end
53
53
  end
54
-
54
+
55
55
  describe '#all_classes' do
56
56
  let(:result) { Police::VmInfo.all_classes }
57
57
 
@@ -60,7 +60,7 @@ describe Police::VmInfo do
60
60
  result.must_include const
61
61
  end
62
62
  end
63
-
63
+
64
64
  MODULES.each do |const|
65
65
  it "does not contain #{const}" do
66
66
  result.wont_include const
@@ -80,21 +80,21 @@ describe Police::VmInfo do
80
80
 
81
81
  describe '#core_modules' do
82
82
  let(:result) { Police::VmInfo.core_modules }
83
-
83
+
84
84
  (CORE_MODULES + CORE_CLASSES).each do |const|
85
85
  it "contains #{const}" do
86
86
  result.must_include const
87
87
  end
88
88
  end
89
-
89
+
90
90
  (GEM_MODULES + GEM_CLASSES).each do |const|
91
91
  it "does not contain #{const}" do
92
92
  result.wont_include const
93
93
  end
94
94
  end
95
95
  end
96
-
97
- describe '#code_classes' do
96
+
97
+ describe '#core_classes' do
98
98
  let(:result) { Police::VmInfo.core_classes }
99
99
 
100
100
  (CORE_CLASSES).each do |const|
@@ -102,21 +102,21 @@ describe Police::VmInfo do
102
102
  result.must_include const
103
103
  end
104
104
  end
105
-
105
+
106
106
  (CORE_MODULES + GEM_MODULES + GEM_CLASSES).each do |const|
107
107
  it "does not contain #{const}" do
108
108
  result.wont_include const
109
109
  end
110
110
  end
111
- end
111
+ end
112
112
 
113
113
  def fixture_module
114
114
  Module.new do
115
115
  include Enumerable
116
-
116
+
117
117
  def police_new_module_method; end
118
118
  def map; end
119
-
119
+
120
120
  def self.dup; end
121
121
  def self.police_new_module_class_method; end
122
122
  end
@@ -126,20 +126,23 @@ describe Police::VmInfo do
126
126
  Class.new String do
127
127
  def police_new_method; end
128
128
  def length; end
129
-
129
+
130
130
  def self.new; end
131
131
  def self.police_new_class_method; end
132
132
  end
133
133
  end
134
-
134
+
135
135
  describe "#all_methods" do
136
136
  describe 'on the fixture module' do
137
- let :method_names do
138
- Police::VmInfo.all_methods(fixture_module).map(&:name)
137
+ let(:methods) { Police::VmInfo.all_methods(fixture_module) }
138
+ let(:method_names) { methods.map(&:name) }
139
+
140
+ it 'returns UnboundMethods' do
141
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
139
142
  end
140
-
143
+
141
144
  it 'contains overridden class methods' do
142
- method_names.must_include :dup
145
+ method_names.must_include :dup
143
146
  end
144
147
 
145
148
  it 'contains new class methods' do
@@ -151,7 +154,7 @@ describe Police::VmInfo do
151
154
  end
152
155
 
153
156
  it 'contains overridden instance methods' do
154
- method_names.must_include :map
157
+ method_names.must_include :map
155
158
  end
156
159
 
157
160
  it 'contains new instance methods' do
@@ -162,14 +165,17 @@ describe Police::VmInfo do
162
165
  method_names.wont_include :select
163
166
  end
164
167
  end
165
-
168
+
166
169
  describe 'on the fixture class' do
167
- let :method_names do
168
- Police::VmInfo.all_methods(fixture_class).map(&:name)
170
+ let(:methods) { Police::VmInfo.all_methods(fixture_class) }
171
+ let(:method_names) { methods.map(&:name) }
172
+
173
+ it 'returns UnboundMethods' do
174
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
169
175
  end
170
-
176
+
171
177
  it 'contains overridden class methods' do
172
- method_names.must_include :new
178
+ method_names.must_include :new
173
179
  end
174
180
 
175
181
  it 'contains new class methods' do
@@ -179,9 +185,9 @@ describe Police::VmInfo do
179
185
  it 'does not contain inherited class methods' do
180
186
  method_names.wont_include :superclass
181
187
  end
182
-
188
+
183
189
  it 'contains overridden instance methods' do
184
- method_names.must_include :length
190
+ method_names.must_include :length
185
191
  end
186
192
 
187
193
  it 'contains new instance methods' do
@@ -193,15 +199,18 @@ describe Police::VmInfo do
193
199
  end
194
200
  end
195
201
  end
196
-
202
+
197
203
  describe "#class_methods" do
198
204
  describe 'on the fixture module' do
199
- let :method_names do
200
- Police::VmInfo.class_methods(fixture_module).map(&:name)
205
+ let(:methods) { Police::VmInfo.class_methods(fixture_module) }
206
+ let(:method_names) { methods.map(&:name) }
207
+
208
+ it 'returns UnboundMethods' do
209
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
201
210
  end
202
-
211
+
203
212
  it 'contains overridden methods' do
204
- method_names.must_include :dup
213
+ method_names.must_include :dup
205
214
  end
206
215
 
207
216
  it 'contains new methods' do
@@ -216,14 +225,17 @@ describe Police::VmInfo do
216
225
  method_names.wont_include :police_new_module_method
217
226
  end
218
227
  end
219
-
228
+
220
229
  describe 'on the fixture class' do
221
- let :method_names do
222
- Police::VmInfo.class_methods(fixture_class).map(&:name)
230
+ let(:methods) { Police::VmInfo.class_methods(fixture_class) }
231
+ let(:method_names) { methods.map(&:name) }
232
+
233
+ it 'returns UnboundMethods' do
234
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
223
235
  end
224
-
236
+
225
237
  it 'contains overridden methods' do
226
- method_names.must_include :new
238
+ method_names.must_include :new
227
239
  end
228
240
 
229
241
  it 'contains new methods' do
@@ -238,16 +250,19 @@ describe Police::VmInfo do
238
250
  method_names.wont_include :police_new_method
239
251
  end
240
252
  end
241
- end
242
-
253
+ end
254
+
243
255
  describe "#instance_methods" do
244
256
  describe 'on the fixture module' do
245
- let :method_names do
246
- Police::VmInfo.instance_methods(fixture_module).map(&:name)
257
+ let(:methods) { Police::VmInfo.instance_methods(fixture_module) }
258
+ let(:method_names) { methods.map(&:name) }
259
+
260
+ it 'returns UnboundMethods' do
261
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
247
262
  end
248
-
263
+
249
264
  it 'contains overridden methods' do
250
- method_names.must_include :map
265
+ method_names.must_include :map
251
266
  end
252
267
 
253
268
  it 'contains new methods' do
@@ -262,14 +277,17 @@ describe Police::VmInfo do
262
277
  method_names.wont_include :police_new_module_class_method
263
278
  end
264
279
  end
265
-
280
+
266
281
  describe 'on the fixture class' do
267
- let :method_names do
268
- Police::VmInfo.instance_methods(fixture_class).map(&:name)
282
+ let(:methods) { Police::VmInfo.instance_methods(fixture_class) }
283
+ let(:method_names) { methods.map(&:name) }
284
+
285
+ it 'returns UnboundMethods' do
286
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
269
287
  end
270
-
288
+
271
289
  it 'contains overridden methods' do
272
- method_names.must_include :length
290
+ method_names.must_include :length
273
291
  end
274
292
 
275
293
  it 'contains new methods' do
@@ -285,7 +303,80 @@ describe Police::VmInfo do
285
303
  end
286
304
  end
287
305
  end
288
-
306
+
307
+ describe "#core_class_methods" do
308
+ describe 'on Process' do
309
+ before do
310
+ module Process
311
+ def self.not_a_core_method
312
+ end
313
+ end
314
+ end
315
+ after do
316
+ module Process
317
+ class <<self
318
+ remove_method :not_a_core_method
319
+ end
320
+ end
321
+ end
322
+
323
+ let(:methods) { Police::VmInfo.core_class_methods(Process) }
324
+ let(:method_names) { methods.map(&:name) }
325
+
326
+ it 'returns UnboundMethods' do
327
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
328
+ end
329
+
330
+ it 'contains spawn' do
331
+ method_names.must_include :spawn
332
+ end
333
+
334
+ it 'does not contain not_a_core_method' do
335
+ method_names.wont_include :not_a_core_method
336
+
337
+ # Ensure that the test setup is correct.
338
+ Police::VmInfo.class_methods(Process).map(&:name).
339
+ must_include :not_a_core_method
340
+ end
341
+ end
342
+ end
343
+
344
+ describe "#core_instance_methods" do
345
+ describe 'on Object' do
346
+ before do
347
+ class Object
348
+ def not_a_core_method
349
+ end
350
+ end
351
+ end
352
+ after do
353
+ class Object
354
+ remove_method :not_a_core_method
355
+ end
356
+ end
357
+
358
+ let(:methods) { Police::VmInfo.core_instance_methods(Object) }
359
+ let(:method_names) { methods.map(&:name) }
360
+
361
+ it 'returns UnboundMethods' do
362
+ methods.each { |method| method.must_be_instance_of UnboundMethod }
363
+ end
364
+
365
+ it 'contains ==' do
366
+ method_names.must_include :==
367
+ end
368
+
369
+ it 'does not contain not_a_core_method' do
370
+ method_names.wont_include :not_a_core_method
371
+
372
+ # Ensure that the test setup is correct.
373
+ Police::VmInfo.instance_methods(Object).map(&:name).
374
+ must_include :not_a_core_method
375
+ end
376
+ end
377
+ end
378
+
379
+
289
380
  describe "#constantize" do
290
381
  it 'works on simple names' do
291
382
  Police::VmInfo.constantize('Object').must_equal Object
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: police-vminfo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2013-05-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Collects information about the Ruby VM implementation details.
15
15
  email: victor@costan.us
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  version: '0'
52
52
  segments:
53
53
  - 0
54
- hash: -2040166733346347996
54
+ hash: 4055543244165856730
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  version: '0'
61
61
  requirements: []
62
62
  rubyforge_project:
63
- rubygems_version: 1.8.21
63
+ rubygems_version: 1.8.23
64
64
  signing_key:
65
65
  specification_version: 3
66
66
  summary: Information about the Ruby VM internals.