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 CHANGED
@@ -1 +1 @@
1
- 0.0.2
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
- output =
72
- `#{Gem.ruby} -e 'puts ObjectSpace.each_object(Module).to_a.join("\n")'`
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
- output =
151
- `#{Gem.ruby} -e 'puts #{module_or_class}.instance_methods.join("\n")'`
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
- output =
170
- `#{Gem.ruby} -e 'puts #{module_or_class}.singleton_methods.join("\n")'`
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
@@ -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; usually
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 Ruby
12
- # gem, and :app for all other methods (presumably defined in the current
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "police-vminfo"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
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"]
@@ -92,6 +92,10 @@ describe Police::VmInfo do
92
92
  result.wont_include const
93
93
  end
94
94
  end
95
+
96
+ it 'does not contain Bundler' do
97
+ result.wont_include Bundler
98
+ end
95
99
  end
96
100
 
97
101
  describe '#core_classes' do
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.2
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: 4055543244165856730
54
+ hash: 4595345354086175528
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements: