police-vminfo 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/police/vminfo/objects.rb +26 -6
- data/lib/police/vminfo/paths.rb +11 -11
- data/police-vminfo.gemspec +1 -1
- data/test/vminfo/objects_test.rb +4 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
@@ -68,8 +68,9 @@ module VmInfo
|
|
68
68
|
def self.core_modules
|
69
69
|
return @core_modules if @core_modules
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
ruby = Gem.ruby
|
72
|
+
output = _kernel_backtick(
|
73
|
+
%Q|#{ruby} -e 'puts ObjectSpace.each_object(Module).to_a.join("\n")'|)
|
73
74
|
modules = []
|
74
75
|
output.split("\n").each do |name|
|
75
76
|
next if name[0] == ?#
|
@@ -147,8 +148,9 @@ module VmInfo
|
|
147
148
|
# Ruby VM
|
148
149
|
# @return [Array<UnboundMethod>] the instance methods defined by the Ruby VM
|
149
150
|
def self.core_instance_methods(module_or_class)
|
150
|
-
|
151
|
-
|
151
|
+
ruby = Gem.ruby
|
152
|
+
output = _kernel_backtick(
|
153
|
+
%Q|#{ruby} -e 'puts #{module_or_class}.instance_methods.join("\n")'|)
|
152
154
|
|
153
155
|
methods = []
|
154
156
|
output.split("\n").each do |name|
|
@@ -166,8 +168,9 @@ module VmInfo
|
|
166
168
|
# Ruby VM
|
167
169
|
# @return [Array<UnboundMethod>] the class methods defined by the Ruby VM
|
168
170
|
def self.core_class_methods(module_or_class)
|
169
|
-
|
170
|
-
|
171
|
+
ruby = Gem.ruby
|
172
|
+
output = _kernel_backtick(
|
173
|
+
%Q|#{ruby} -e 'puts #{module_or_class}.singleton_methods.join("\n")'|)
|
171
174
|
|
172
175
|
methods = []
|
173
176
|
method_names = output.split "\n"
|
@@ -200,6 +203,23 @@ module VmInfo
|
|
200
203
|
end
|
201
204
|
value
|
202
205
|
end
|
206
|
+
|
207
|
+
# Executes Kernel.` without external interferences.
|
208
|
+
#
|
209
|
+
# @private
|
210
|
+
# This is meant for internal use only.
|
211
|
+
#
|
212
|
+
# @param {String} command the command to be executed
|
213
|
+
# @return {String} the command's stdout
|
214
|
+
def self._kernel_backtick(command)
|
215
|
+
if defined?(Bundler)
|
216
|
+
Bundler.with_clean_env do
|
217
|
+
Kernel.send :`, command
|
218
|
+
end
|
219
|
+
else
|
220
|
+
Kernel.send :`, command
|
221
|
+
end
|
222
|
+
end
|
203
223
|
end # namespace VmInfo
|
204
224
|
|
205
225
|
end # namespace Police
|
data/lib/police/vminfo/paths.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
module Police
|
2
|
-
|
2
|
+
|
3
3
|
module VmInfo
|
4
4
|
# Classifies the path to a Ruby file based on its provenance.
|
5
5
|
#
|
6
|
-
# @param [Method, UnboundMethod] method VM information about a method;
|
7
|
-
# obtained by calling Object#method or Module#instance_method
|
6
|
+
# @param [Method, UnboundMethod] method VM information about a method;
|
7
|
+
# usually obtained by calling Object#method or Module#instance_method
|
8
8
|
# @return [Symbol] :native for methods defined in a low-level language (C/C++
|
9
9
|
# for MRI and Rubinius, Java for JRuby), :kernel for methods belonging to
|
10
10
|
# the core VM code (Rubinius and JRuby), :stdlib for methods in Ruby's
|
11
|
-
# standard library, :gem for methods that are implemented in a loaded
|
12
|
-
# gem, and :app for all other methods (presumably defined in the
|
13
|
-
# application)
|
11
|
+
# standard library, :gem for methods that are implemented in a loaded
|
12
|
+
# Ruby gem, and :app for all other methods (presumably defined in the
|
13
|
+
# current application)
|
14
14
|
def self.method_source(method)
|
15
15
|
location = method.source_location
|
16
16
|
return :native if location.nil?
|
@@ -20,17 +20,17 @@ module VmInfo
|
|
20
20
|
return :kernel if kernel_path?(code_path)
|
21
21
|
:app
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# True if the given source code path belongs to a gem.
|
25
25
|
def self.gem_path?(path)
|
26
26
|
Gem.default_path.any? { |gem_path| Paths.descendant? path, gem_path }
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
# True if the given source code path belongs to the Ruby standard library.
|
30
30
|
def self.stdlib_path?(path)
|
31
31
|
# NOTE: assuming the convention that all directories are prepended to the
|
32
32
|
# load path throughout a program's execution
|
33
|
-
load_paths = $LOAD_PATH
|
33
|
+
load_paths = $LOAD_PATH
|
34
34
|
last_gem_index = -1
|
35
35
|
(load_paths.length - 1).downto(0) do |index|
|
36
36
|
if gem_path? load_paths[index]
|
@@ -41,12 +41,12 @@ module VmInfo
|
|
41
41
|
stdlib_paths = load_paths[(last_gem_index + 1)..-1]
|
42
42
|
stdlib_paths.any? { |stdlib_path| Paths.descendant? path, stdlib_path }
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# True if the given source code path belongs to the Ruby VM kernel.
|
46
46
|
def self.kernel_path?(path)
|
47
47
|
!$LOAD_PATH.any? { |load_path| Paths.descendant? path, load_path }
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# Implementation details.
|
51
51
|
# @private
|
52
52
|
module Paths
|
data/police-vminfo.gemspec
CHANGED
data/test/vminfo/objects_test.rb
CHANGED
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.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
segments:
|
53
53
|
- 0
|
54
|
-
hash:
|
54
|
+
hash: 4595345354086175528
|
55
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
56
|
none: false
|
57
57
|
requirements:
|