activesupport 4.2.0 → 4.2.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a92aaed8c92253b60d615c68b681d0187185010
4
- data.tar.gz: 16a0f7761127de79598b4787717f1d90da9d64fd
3
+ metadata.gz: f650b87b7119a5b7165a1e4f529d1c425e438f39
4
+ data.tar.gz: f5bf7949a9f940550e3767064dfba037267fc670
5
5
  SHA512:
6
- metadata.gz: 81470e00892e899e539f8791a1d6ba3a86d0a2e3760a0719c7922a987c92337d10dbffe9e157357d456c4aba6d64c6c71366db8b6772c19435ab64cd7c55894b
7
- data.tar.gz: 9e645639534174a986106a4a4df445c6c13498ef3e419dacab8b67870c088199412ed8db81a96a7a73e0c526d0971dc5368bbd8a2027252e632ba867c46be975
6
+ metadata.gz: cff2bcb80b67ac0327843c5cecfc9fd0575b606c5be4c438b95bbfa2e46c2e7563c3737c16c931ab19b7268375b24257c2fa1c12acc2f8fa127f39fa49fcc2a7
7
+ data.tar.gz: 369e41edf6cc159e7f38b71bf6b754c989423884a3b80e7f6600f7dda96c98cb2ea6d2c59decd15b30612b6d85bf051edf5d2e102c6f8153f65bf971d1843a70
@@ -1,3 +1,36 @@
1
+ * Fixed a roundtrip problem with AS::SafeBuffer where primitive-like strings
2
+ will be dumped as primitives:
3
+
4
+ Before:
5
+
6
+ YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello"
7
+ YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true
8
+ YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false
9
+ YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1
10
+ YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1
11
+
12
+ After:
13
+
14
+ YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello"
15
+ YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true"
16
+ YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false"
17
+ YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1"
18
+ YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1"
19
+
20
+ *Godfrey Chan*
21
+
22
+ * Replace fixed `:en` with `I18n.default_locale` in `Duration#inspect`.
23
+
24
+ *Dominik Masur*
25
+
26
+ * Add missing time zone definitions for Russian Federation and sync them
27
+ with `zone.tab` file from tzdata version 2014j (latest).
28
+
29
+ *Andrey Novikov*
30
+
31
+
32
+ ## Rails 4.2.0 (December 20, 2014) ##
33
+
1
34
  * The decorated `load` and `require` methods are now kept private.
2
35
 
3
36
  Fixes #17553.
@@ -622,7 +622,7 @@ module ActiveSupport
622
622
  # Check if the entry is expired. The +expires_in+ parameter can override
623
623
  # the value set when the entry was created.
624
624
  def expired?
625
- convert_version_4beta1_entry! if defined?(@value)
625
+ convert_version_4beta1_entry! if defined?(@v)
626
626
  @expires_in && @created_at + @expires_in <= Time.now.to_f
627
627
  end
628
628
 
@@ -121,22 +121,22 @@ module ActiveSupport
121
121
  ENDING = End.new
122
122
 
123
123
  class Before
124
- def self.build(next_callback, user_callback, user_conditions, chain_config, filter)
124
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config, filter)
125
125
  halted_lambda = chain_config[:terminator]
126
126
 
127
127
  if chain_config.key?(:terminator) && user_conditions.any?
128
- halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
128
+ halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
129
129
  elsif chain_config.key? :terminator
130
- halting(next_callback, user_callback, halted_lambda, filter)
130
+ halting(callback_sequence, user_callback, halted_lambda, filter)
131
131
  elsif user_conditions.any?
132
- conditional(next_callback, user_callback, user_conditions)
132
+ conditional(callback_sequence, user_callback, user_conditions)
133
133
  else
134
- simple next_callback, user_callback
134
+ simple callback_sequence, user_callback
135
135
  end
136
136
  end
137
137
 
138
- def self.halting_and_conditional(next_callback, user_callback, user_conditions, halted_lambda, filter)
139
- lambda { |env|
138
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
139
+ callback_sequence.before do |env|
140
140
  target = env.target
141
141
  value = env.value
142
142
  halted = env.halted
@@ -148,13 +148,14 @@ module ActiveSupport
148
148
  target.send :halted_callback_hook, filter
149
149
  end
150
150
  end
151
- next_callback.call env
152
- }
151
+
152
+ env
153
+ end
153
154
  end
154
155
  private_class_method :halting_and_conditional
155
156
 
156
- def self.halting(next_callback, user_callback, halted_lambda, filter)
157
- lambda { |env|
157
+ def self.halting(callback_sequence, user_callback, halted_lambda, filter)
158
+ callback_sequence.before do |env|
158
159
  target = env.target
159
160
  value = env.value
160
161
  halted = env.halted
@@ -166,57 +167,59 @@ module ActiveSupport
166
167
  target.send :halted_callback_hook, filter
167
168
  end
168
169
  end
169
- next_callback.call env
170
- }
170
+
171
+ env
172
+ end
171
173
  end
172
174
  private_class_method :halting
173
175
 
174
- def self.conditional(next_callback, user_callback, user_conditions)
175
- lambda { |env|
176
+ def self.conditional(callback_sequence, user_callback, user_conditions)
177
+ callback_sequence.before do |env|
176
178
  target = env.target
177
179
  value = env.value
178
180
 
179
181
  if user_conditions.all? { |c| c.call(target, value) }
180
182
  user_callback.call target, value
181
183
  end
182
- next_callback.call env
183
- }
184
+
185
+ env
186
+ end
184
187
  end
185
188
  private_class_method :conditional
186
189
 
187
- def self.simple(next_callback, user_callback)
188
- lambda { |env|
190
+ def self.simple(callback_sequence, user_callback)
191
+ callback_sequence.before do |env|
189
192
  user_callback.call env.target, env.value
190
- next_callback.call env
191
- }
193
+
194
+ env
195
+ end
192
196
  end
193
197
  private_class_method :simple
194
198
  end
195
199
 
196
200
  class After
197
- def self.build(next_callback, user_callback, user_conditions, chain_config)
201
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config)
198
202
  if chain_config[:skip_after_callbacks_if_terminated]
199
203
  if chain_config.key?(:terminator) && user_conditions.any?
200
- halting_and_conditional(next_callback, user_callback, user_conditions)
204
+ halting_and_conditional(callback_sequence, user_callback, user_conditions)
201
205
  elsif chain_config.key?(:terminator)
202
- halting(next_callback, user_callback)
206
+ halting(callback_sequence, user_callback)
203
207
  elsif user_conditions.any?
204
- conditional next_callback, user_callback, user_conditions
208
+ conditional callback_sequence, user_callback, user_conditions
205
209
  else
206
- simple next_callback, user_callback
210
+ simple callback_sequence, user_callback
207
211
  end
208
212
  else
209
213
  if user_conditions.any?
210
- conditional next_callback, user_callback, user_conditions
214
+ conditional callback_sequence, user_callback, user_conditions
211
215
  else
212
- simple next_callback, user_callback
216
+ simple callback_sequence, user_callback
213
217
  end
214
218
  end
215
219
  end
216
220
 
217
- def self.halting_and_conditional(next_callback, user_callback, user_conditions)
218
- lambda { |env|
219
- env = next_callback.call env
221
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
222
+ callback_sequence.after do |env|
220
223
  target = env.target
221
224
  value = env.value
222
225
  halted = env.halted
@@ -224,122 +227,124 @@ module ActiveSupport
224
227
  if !halted && user_conditions.all? { |c| c.call(target, value) }
225
228
  user_callback.call target, value
226
229
  end
230
+
227
231
  env
228
- }
232
+ end
229
233
  end
230
234
  private_class_method :halting_and_conditional
231
235
 
232
- def self.halting(next_callback, user_callback)
233
- lambda { |env|
234
- env = next_callback.call env
236
+ def self.halting(callback_sequence, user_callback)
237
+ callback_sequence.after do |env|
235
238
  unless env.halted
236
239
  user_callback.call env.target, env.value
237
240
  end
241
+
238
242
  env
239
- }
243
+ end
240
244
  end
241
245
  private_class_method :halting
242
246
 
243
- def self.conditional(next_callback, user_callback, user_conditions)
244
- lambda { |env|
245
- env = next_callback.call env
247
+ def self.conditional(callback_sequence, user_callback, user_conditions)
248
+ callback_sequence.after do |env|
246
249
  target = env.target
247
250
  value = env.value
248
251
 
249
252
  if user_conditions.all? { |c| c.call(target, value) }
250
253
  user_callback.call target, value
251
254
  end
255
+
252
256
  env
253
- }
257
+ end
254
258
  end
255
259
  private_class_method :conditional
256
260
 
257
- def self.simple(next_callback, user_callback)
258
- lambda { |env|
259
- env = next_callback.call env
261
+ def self.simple(callback_sequence, user_callback)
262
+ callback_sequence.after do |env|
260
263
  user_callback.call env.target, env.value
264
+
261
265
  env
262
- }
266
+ end
263
267
  end
264
268
  private_class_method :simple
265
269
  end
266
270
 
267
271
  class Around
268
- def self.build(next_callback, user_callback, user_conditions, chain_config)
272
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config)
269
273
  if chain_config.key?(:terminator) && user_conditions.any?
270
- halting_and_conditional(next_callback, user_callback, user_conditions)
274
+ halting_and_conditional(callback_sequence, user_callback, user_conditions)
271
275
  elsif chain_config.key? :terminator
272
- halting(next_callback, user_callback)
276
+ halting(callback_sequence, user_callback)
273
277
  elsif user_conditions.any?
274
- conditional(next_callback, user_callback, user_conditions)
278
+ conditional(callback_sequence, user_callback, user_conditions)
275
279
  else
276
- simple(next_callback, user_callback)
280
+ simple(callback_sequence, user_callback)
277
281
  end
278
282
  end
279
283
 
280
- def self.halting_and_conditional(next_callback, user_callback, user_conditions)
281
- lambda { |env|
284
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
285
+ callback_sequence.around do |env, &run|
282
286
  target = env.target
283
287
  value = env.value
284
288
  halted = env.halted
285
289
 
286
290
  if !halted && user_conditions.all? { |c| c.call(target, value) }
287
291
  user_callback.call(target, value) {
288
- env = next_callback.call env
292
+ env = run.call env
289
293
  env.value
290
294
  }
295
+
291
296
  env
292
297
  else
293
- next_callback.call env
298
+ run.call env
294
299
  end
295
- }
300
+ end
296
301
  end
297
302
  private_class_method :halting_and_conditional
298
303
 
299
- def self.halting(next_callback, user_callback)
300
- lambda { |env|
304
+ def self.halting(callback_sequence, user_callback)
305
+ callback_sequence.around do |env, &run|
301
306
  target = env.target
302
307
  value = env.value
303
308
 
304
309
  if env.halted
305
- next_callback.call env
310
+ run.call env
306
311
  else
307
312
  user_callback.call(target, value) {
308
- env = next_callback.call env
313
+ env = run.call env
309
314
  env.value
310
315
  }
311
316
  env
312
317
  end
313
- }
318
+ end
314
319
  end
315
320
  private_class_method :halting
316
321
 
317
- def self.conditional(next_callback, user_callback, user_conditions)
318
- lambda { |env|
322
+ def self.conditional(callback_sequence, user_callback, user_conditions)
323
+ callback_sequence.around do |env, &run|
319
324
  target = env.target
320
325
  value = env.value
321
326
 
322
327
  if user_conditions.all? { |c| c.call(target, value) }
323
328
  user_callback.call(target, value) {
324
- env = next_callback.call env
329
+ env = run.call env
325
330
  env.value
326
331
  }
327
332
  env
328
333
  else
329
- next_callback.call env
334
+ run.call env
330
335
  end
331
- }
336
+ end
332
337
  end
333
338
  private_class_method :conditional
334
339
 
335
- def self.simple(next_callback, user_callback)
336
- lambda { |env|
340
+ def self.simple(callback_sequence, user_callback)
341
+ callback_sequence.around do |env, &run|
337
342
  user_callback.call(env.target, env.value) {
338
- env = next_callback.call env
343
+ env = run.call env
339
344
  env.value
340
345
  }
341
346
  env
342
- }
347
+ end
343
348
  end
344
349
  private_class_method :simple
345
350
  end
@@ -392,17 +397,17 @@ module ActiveSupport
392
397
  end
393
398
 
394
399
  # Wraps code with filter
395
- def apply(next_callback)
400
+ def apply(callback_sequence)
396
401
  user_conditions = conditions_lambdas
397
402
  user_callback = make_lambda @filter
398
403
 
399
404
  case kind
400
405
  when :before
401
- Filters::Before.build(next_callback, user_callback, user_conditions, chain_config, @filter)
406
+ Filters::Before.build(callback_sequence, user_callback, user_conditions, chain_config, @filter)
402
407
  when :after
403
- Filters::After.build(next_callback, user_callback, user_conditions, chain_config)
408
+ Filters::After.build(callback_sequence, user_callback, user_conditions, chain_config)
404
409
  when :around
405
- Filters::Around.build(next_callback, user_callback, user_conditions, chain_config)
410
+ Filters::Around.build(callback_sequence, user_callback, user_conditions, chain_config)
406
411
  end
407
412
  end
408
413
 
@@ -467,6 +472,42 @@ module ActiveSupport
467
472
  end
468
473
  end
469
474
 
475
+ # Execute before and after filters in a sequence instead of
476
+ # chaining them with nested lambda calls, see:
477
+ # https://github.com/rails/rails/issues/18011
478
+ class CallbackSequence
479
+ def initialize(&call)
480
+ @call = call
481
+ @before = []
482
+ @after = []
483
+ end
484
+
485
+ def before(&before)
486
+ @before.unshift(before)
487
+ self
488
+ end
489
+
490
+ def after(&after)
491
+ @after.push(after)
492
+ self
493
+ end
494
+
495
+ def around(&around)
496
+ CallbackSequence.new do |*args|
497
+ around.call(*args) {
498
+ self.call(*args)
499
+ }
500
+ end
501
+ end
502
+
503
+ def call(*args)
504
+ @before.each { |b| b.call(*args) }
505
+ value = @call.call(*args)
506
+ @after.each { |a| a.call(*args) }
507
+ value
508
+ end
509
+ end
510
+
470
511
  # An Array with a compile method.
471
512
  class CallbackChain #:nodoc:#
472
513
  include Enumerable
@@ -511,8 +552,9 @@ module ActiveSupport
511
552
 
512
553
  def compile
513
554
  @callbacks || @mutex.synchronize do
514
- @callbacks ||= @chain.reverse.inject(Filters::ENDING) do |chain, callback|
515
- callback.apply chain
555
+ final_sequence = CallbackSequence.new { |env| Filters::ENDING.call(env) }
556
+ @callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
557
+ callback.apply callback_sequence
516
558
  end
517
559
  end
518
560
  end
@@ -3,7 +3,7 @@ module Kernel
3
3
  # Starts a debugging session if the +debugger+ gem has been loaded (call rails server --debugger to do load it).
4
4
  def debugger
5
5
  message = "\n***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
6
- defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
6
+ defined?(Rails.logger) ? Rails.logger.info(message) : $stderr.puts(message)
7
7
  end
8
8
  alias breakpoint debugger unless respond_to?(:breakpoint)
9
9
  end
@@ -185,19 +185,31 @@ class Module
185
185
  # On the other hand it could be that the target has side-effects,
186
186
  # whereas conceptually, from the user point of view, the delegator should
187
187
  # be doing one call.
188
-
189
- exception = %(raise DelegationError, "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
190
-
191
- method_def = [
192
- "def #{method_prefix}#{method}(#{definition})",
193
- " _ = #{to}",
194
- " if !_.nil? || nil.respond_to?(:#{method})",
195
- " _.#{method}(#{definition})",
196
- " else",
197
- " #{exception unless allow_nil}",
198
- " end",
188
+ if allow_nil
189
+ method_def = [
190
+ "def #{method_prefix}#{method}(#{definition})",
191
+ "_ = #{to}",
192
+ "if !_.nil? || nil.respond_to?(:#{method})",
193
+ " _.#{method}(#{definition})",
194
+ "end",
199
195
  "end"
200
- ].join ';'
196
+ ].join ';'
197
+ else
198
+ exception = %(raise DelegationError, "#{self}##{method_prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
199
+
200
+ method_def = [
201
+ "def #{method_prefix}#{method}(#{definition})",
202
+ " _ = #{to}",
203
+ " _.#{method}(#{definition})",
204
+ "rescue NoMethodError => e",
205
+ " if _.nil? && e.name == :#{method}",
206
+ " #{exception}",
207
+ " else",
208
+ " raise",
209
+ " end",
210
+ "end"
211
+ ].join ';'
212
+ end
201
213
 
202
214
  module_eval(method_def, file, line)
203
215
  end
@@ -150,7 +150,11 @@ module ActiveSupport #:nodoc:
150
150
  else
151
151
  if html_safe?
152
152
  new_safe_buffer = super
153
- new_safe_buffer.instance_variable_set :@html_safe, true
153
+
154
+ if new_safe_buffer
155
+ new_safe_buffer.instance_variable_set :@html_safe, true
156
+ end
157
+
154
158
  new_safe_buffer
155
159
  else
156
160
  to_str[*args]
@@ -219,7 +223,7 @@ module ActiveSupport #:nodoc:
219
223
  end
220
224
 
221
225
  def encode_with(coder)
222
- coder.represent_scalar nil, to_str
226
+ coder.represent_object nil, to_str
223
227
  end
224
228
 
225
229
  UNSAFE_STRING_METHODS.each do |unsafe_method|
@@ -20,7 +20,7 @@ module ActiveSupport
20
20
 
21
21
  log: ->(message, callstack) {
22
22
  logger =
23
- if defined?(Rails) && Rails.logger
23
+ if defined?(Rails.logger) && Rails.logger
24
24
  Rails.logger
25
25
  else
26
26
  require 'active_support/logger'
@@ -91,7 +91,7 @@ module ActiveSupport
91
91
  reduce(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }.
92
92
  sort_by {|unit, _ | [:years, :months, :days, :minutes, :seconds].index(unit)}.
93
93
  map {|unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}"}.
94
- to_sentence(:locale => :en)
94
+ to_sentence(locale: ::I18n.default_locale)
95
95
  end
96
96
 
97
97
  def as_json(options = nil) #:nodoc:
@@ -7,8 +7,8 @@ module ActiveSupport
7
7
  module VERSION
8
8
  MAJOR = 4
9
9
  MINOR = 2
10
- TINY = 0
11
- PRE = nil
10
+ TINY = 1
11
+ PRE = "rc1"
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
14
  end
@@ -111,9 +111,11 @@ module ActiveSupport
111
111
  "Jerusalem" => "Asia/Jerusalem",
112
112
  "Harare" => "Africa/Harare",
113
113
  "Pretoria" => "Africa/Johannesburg",
114
+ "Kaliningrad" => "Europe/Kaliningrad",
114
115
  "Moscow" => "Europe/Moscow",
115
116
  "St. Petersburg" => "Europe/Moscow",
116
- "Volgograd" => "Europe/Moscow",
117
+ "Volgograd" => "Europe/Volgograd",
118
+ "Samara" => "Europe/Samara",
117
119
  "Kuwait" => "Asia/Kuwait",
118
120
  "Riyadh" => "Asia/Riyadh",
119
121
  "Nairobi" => "Africa/Nairobi",
@@ -170,6 +172,7 @@ module ActiveSupport
170
172
  "Guam" => "Pacific/Guam",
171
173
  "Port Moresby" => "Pacific/Port_Moresby",
172
174
  "Magadan" => "Asia/Magadan",
175
+ "Srednekolymsk" => "Asia/Srednekolymsk",
173
176
  "Solomon Is." => "Pacific/Guadalcanal",
174
177
  "New Caledonia" => "Pacific/Noumea",
175
178
  "Fiji" => "Pacific/Fiji",
@@ -221,7 +224,7 @@ module ActiveSupport
221
224
  @zones ||= zones_map.values.sort
222
225
  end
223
226
 
224
- def zones_map
227
+ def zones_map #:nodoc:
225
228
  @zones_map ||= begin
226
229
  MAPPING.each_key {|place| self[place]} # load all the zones
227
230
  @lazy_zones_map
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-20 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -334,12 +334,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
334
334
  version: 1.9.3
335
335
  required_rubygems_version: !ruby/object:Gem::Requirement
336
336
  requirements:
337
- - - ">="
337
+ - - ">"
338
338
  - !ruby/object:Gem::Version
339
- version: '0'
339
+ version: 1.3.1
340
340
  requirements: []
341
341
  rubyforge_project:
342
- rubygems_version: 2.2.2
342
+ rubygems_version: 2.4.5
343
343
  signing_key:
344
344
  specification_version: 4
345
345
  summary: A toolkit of support libraries and Ruby core extensions extracted from the