isolate 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 1.5.0 / 2009-10-01
2
+
3
+ * Implemented passthrough.
4
+
1
5
  === 1.4.0 / 2009-09-30
2
6
 
3
7
  * Added automatic cleanup.
@@ -64,6 +64,27 @@ Unsurprisingly, the <tt>mocha</tt> gem will only be activated in the
64
64
  example below for an example of how to use <tt>RAILS_ENV</tt> to set
65
65
  your environment.
66
66
 
67
+ === Passthrough
68
+
69
+ Sometimes (especially on systems with alternative Gem management like
70
+ Heroku) you want Isolate to sit in a corner, be very, very quiet, and
71
+ let all calls pass right through.
72
+
73
+ If you want to make Isolate a complete no-op in production, and your
74
+ environment sets <tt>RACK_ENV</tt>, you could do something like this:
75
+
76
+ Isolate.gems "vendor/isolated" do
77
+ passthrough { %w(beta production).include? ENV["RACK_ENV"] }
78
+
79
+ # the rest of your gems...
80
+ end
81
+
82
+ ...and nothing will get isolated. The block should evaluate to
83
+ <tt>true</tt> if that's what you want, and it's only evaluated
84
+ once. This is run really early, so don't blindly assume things like
85
+ the <tt>RAILS_ENV</tt> constant are set. Check your environment for
86
+ details.
87
+
67
88
  === Options
68
89
 
69
90
  Any trailing hash args to <tt>gem</tt> are passed to
@@ -21,7 +21,7 @@ class Isolate
21
21
  end
22
22
  end
23
23
 
24
- VERSION = "1.4.0" # :nodoc:
24
+ VERSION = "1.5.0" # :nodoc:
25
25
 
26
26
  attr_reader :entries # :nodoc:
27
27
 
@@ -81,6 +81,7 @@ class Isolate
81
81
  end
82
82
 
83
83
  def activate environment = nil # :nodoc:
84
+ return self if passthrough?
84
85
  enable unless enabled?
85
86
 
86
87
  env = environment.to_s if environment
@@ -94,6 +95,8 @@ class Isolate
94
95
  end
95
96
 
96
97
  def cleanup
98
+ return self if passthrough?
99
+
97
100
  activated = Gem.loaded_specs.values.map { |s| s.full_name }
98
101
  extra = Gem.source_index.gems.values.sort.reject { |spec|
99
102
  activated.include? spec.full_name or
@@ -122,6 +125,7 @@ class Isolate
122
125
  end
123
126
 
124
127
  def disable # :nodoc:
128
+ return self if passthrough?
125
129
  return self unless enabled?
126
130
 
127
131
  ENV["GEM_PATH"] = @old_gem_path
@@ -137,7 +141,7 @@ class Isolate
137
141
  end
138
142
 
139
143
  def enable # :nodoc:
140
- return self if enabled?
144
+ return self if passthrough? || enabled?
141
145
 
142
146
  @old_gem_path = ENV["GEM_PATH"]
143
147
  @old_gem_home = ENV["GEM_HOME"]
@@ -198,6 +202,8 @@ class Isolate
198
202
  end
199
203
 
200
204
  def install environment = nil # :nodoc:
205
+ return self if passthrough?
206
+
201
207
  env = environment.to_s if environment
202
208
 
203
209
  installable = entries.select do |e|
@@ -235,6 +241,14 @@ class Isolate
235
241
  @install
236
242
  end
237
243
 
244
+ def passthrough &block # :nodoc:
245
+ @passthrough = block
246
+ end
247
+
248
+ def passthrough? # :nodoc:
249
+ defined? @passthrough and @passthrough ||= @passthrough.call
250
+ end
251
+
238
252
  def verbose? # :nodoc:
239
253
  @verbose
240
254
  end
@@ -206,6 +206,17 @@ class TestIsolate < MiniTest::Unit::TestCase
206
206
  i = Isolate.new "foo/gems", :install => false
207
207
  refute i.cleanup?, "no install, no cleanup"
208
208
  end
209
+
210
+ def test_passthrough
211
+ refute @isolate.passthrough?
212
+
213
+ @isolate.passthrough { true }
214
+ assert @isolate.passthrough?
215
+
216
+ idx = Gem.source_index.dup
217
+ @isolate.activate
218
+ assert_equal idx, Gem.source_index
219
+ end
209
220
  end
210
221
 
211
222
  module BrutalStub
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isolate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-09-30 00:00:00 -07:00
13
+ date: 2009-10-01 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency