activesupport 4.2.5 → 4.2.11.3
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 +5 -5
- data/CHANGELOG.md +200 -0
- data/lib/active_support/cache/mem_cache_store.rb +1 -1
- data/lib/active_support/callbacks.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +0 -2
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +22 -2
- data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_time.rb +1 -0
- data/lib/active_support/core_ext/enumerable.rb +16 -0
- data/lib/active_support/core_ext/hash/compact.rb +19 -15
- data/lib/active_support/core_ext/hash/conversions.rb +1 -2
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -2
- data/lib/active_support/core_ext/marshal.rb +8 -5
- data/lib/active_support/core_ext/module/delegation.rb +8 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +9 -1
- data/lib/active_support/core_ext/object/duplicable.rb +58 -32
- data/lib/active_support/core_ext/string/access.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +1 -1
- data/lib/active_support/core_ext/time/calculations.rb +10 -1
- data/lib/active_support/core_ext/time/compatibility.rb +14 -0
- data/lib/active_support/core_ext/time.rb +1 -0
- data/lib/active_support/gem_version.rb +2 -2
- data/lib/active_support/hash_with_indifferent_access.rb +9 -0
- data/lib/active_support/inflector/methods.rb +1 -1
- data/lib/active_support/logger.rb +50 -0
- data/lib/active_support/logger_silence.rb +7 -4
- data/lib/active_support/logger_thread_safe_level.rb +32 -0
- data/lib/active_support/message_encryptor.rb +8 -1
- data/lib/active_support/per_thread_registry.rb +2 -0
- data/lib/active_support/security_utils.rb +7 -0
- data/lib/active_support/testing/time_helpers.rb +16 -13
- data/lib/active_support/time_with_zone.rb +28 -16
- data/lib/active_support/values/time_zone.rb +5 -3
- data/lib/active_support/xml_mini/libxml.rb +1 -3
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -4
- data/lib/active_support/xml_mini/nokogiri.rb +1 -3
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -3
- data/lib/active_support/xml_mini/rexml.rb +1 -3
- data/lib/active_support/xml_mini.rb +30 -15
- data/lib/active_support.rb +9 -0
- metadata +7 -24
@@ -245,6 +245,15 @@ module ActiveSupport
|
|
245
245
|
dup.tap { |hash| hash.reject!(*args, &block) }
|
246
246
|
end
|
247
247
|
|
248
|
+
def transform_values(*args, &block)
|
249
|
+
return to_enum(:transform_values) unless block_given?
|
250
|
+
dup.tap { |hash| hash.transform_values!(*args, &block) }
|
251
|
+
end
|
252
|
+
|
253
|
+
def compact
|
254
|
+
dup.tap(&:compact!)
|
255
|
+
end
|
256
|
+
|
248
257
|
# Convert to a regular hash with string keys.
|
249
258
|
def to_hash
|
250
259
|
_new_hash = Hash.new
|
@@ -153,7 +153,7 @@ module ActiveSupport
|
|
153
153
|
# 'TheManWithoutAPast'.titleize # => "The Man Without A Past"
|
154
154
|
# 'raiders_of_the_lost_ark'.titleize # => "Raiders Of The Lost Ark"
|
155
155
|
def titleize(word)
|
156
|
-
humanize(underscore(word)).gsub(/\b(?<!['’`])[a-z]/) {
|
156
|
+
humanize(underscore(word)).gsub(/\b(?<!['’`])[a-z]/) { |match| match.capitalize }
|
157
157
|
end
|
158
158
|
|
159
159
|
# Create the name of a table like Rails does for models to table names. This
|
@@ -1,11 +1,24 @@
|
|
1
1
|
require 'active_support/core_ext/module/attribute_accessors'
|
2
2
|
require 'active_support/logger_silence'
|
3
|
+
require 'active_support/logger_thread_safe_level'
|
3
4
|
require 'logger'
|
4
5
|
|
5
6
|
module ActiveSupport
|
6
7
|
class Logger < ::Logger
|
8
|
+
include ActiveSupport::LoggerThreadSafeLevel
|
7
9
|
include LoggerSilence
|
8
10
|
|
11
|
+
# Returns true if the logger destination matches one of the sources
|
12
|
+
#
|
13
|
+
# logger = Logger.new(STDOUT)
|
14
|
+
# ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
|
15
|
+
# # => true
|
16
|
+
def self.logger_outputs_to?(logger, *sources)
|
17
|
+
logdev = logger.instance_variable_get("@logdev")
|
18
|
+
logger_source = logdev.dev if logdev.respond_to?(:dev)
|
19
|
+
sources.any? { |source| source == logger_source }
|
20
|
+
end
|
21
|
+
|
9
22
|
# Broadcasts logs to multiple loggers.
|
10
23
|
def self.broadcast(logger) # :nodoc:
|
11
24
|
Module.new do
|
@@ -38,12 +51,49 @@ module ActiveSupport
|
|
38
51
|
logger.level = level
|
39
52
|
super(level)
|
40
53
|
end
|
54
|
+
|
55
|
+
define_method(:local_level=) do |level|
|
56
|
+
logger.local_level = level if logger.respond_to?(:local_level=)
|
57
|
+
super(level) if respond_to?(:local_level=)
|
58
|
+
end
|
59
|
+
|
60
|
+
define_method(:silence) do |level = Logger::ERROR, &block|
|
61
|
+
if logger.respond_to?(:silence) && logger.method(:silence).owner != ::Kernel
|
62
|
+
logger.silence(level) do
|
63
|
+
if respond_to?(:silence) && method(:silence).owner != ::Kernel
|
64
|
+
super(level, &block)
|
65
|
+
else
|
66
|
+
block.call(self)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
if respond_to?(:silence) && method(:silence).owner != ::Kernel
|
71
|
+
super(level, &block)
|
72
|
+
else
|
73
|
+
block.call(self)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
41
77
|
end
|
42
78
|
end
|
43
79
|
|
44
80
|
def initialize(*args)
|
45
81
|
super
|
46
82
|
@formatter = SimpleFormatter.new
|
83
|
+
after_initialize if respond_to? :after_initialize
|
84
|
+
end
|
85
|
+
|
86
|
+
def add(severity, message = nil, progname = nil, &block)
|
87
|
+
return true if @logdev.nil? || (severity || UNKNOWN) < level
|
88
|
+
super
|
89
|
+
end
|
90
|
+
|
91
|
+
Logger::Severity.constants.each do |severity|
|
92
|
+
class_eval(<<-EOT, __FILE__, __LINE__ + 1)
|
93
|
+
def #{severity.downcase}? # def debug?
|
94
|
+
Logger::#{severity} >= level # DEBUG >= level
|
95
|
+
end # end
|
96
|
+
EOT
|
47
97
|
end
|
48
98
|
|
49
99
|
# Simple formatter which only displays the message.
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'active_support/concern'
|
2
|
+
require 'thread_safe'
|
2
3
|
|
3
4
|
module LoggerSilence
|
4
5
|
extend ActiveSupport::Concern
|
5
|
-
|
6
|
+
|
6
7
|
included do
|
7
8
|
cattr_accessor :silencer
|
8
9
|
self.silencer = true
|
@@ -12,13 +13,15 @@ module LoggerSilence
|
|
12
13
|
def silence(temporary_level = Logger::ERROR)
|
13
14
|
if silencer
|
14
15
|
begin
|
15
|
-
|
16
|
+
old_local_level = local_level
|
17
|
+
self.local_level = temporary_level
|
18
|
+
|
16
19
|
yield self
|
17
20
|
ensure
|
18
|
-
self.
|
21
|
+
self.local_level = old_local_level
|
19
22
|
end
|
20
23
|
else
|
21
24
|
yield self
|
22
25
|
end
|
23
26
|
end
|
24
|
-
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'thread_safe'
|
3
|
+
|
4
|
+
module ActiveSupport
|
5
|
+
module LoggerThreadSafeLevel
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
def after_initialize
|
9
|
+
@local_levels = ThreadSafe::Cache.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def local_log_id
|
13
|
+
Thread.current.__id__
|
14
|
+
end
|
15
|
+
|
16
|
+
def local_level
|
17
|
+
@local_levels[local_log_id]
|
18
|
+
end
|
19
|
+
|
20
|
+
def local_level=(level)
|
21
|
+
if level
|
22
|
+
@local_levels[local_log_id] = level
|
23
|
+
else
|
24
|
+
@local_levels.delete(local_log_id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def level
|
29
|
+
local_level || super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -18,6 +18,8 @@ module ActiveSupport
|
|
18
18
|
# encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..."
|
19
19
|
# crypt.decrypt_and_verify(encrypted_data) # => "my secret data"
|
20
20
|
class MessageEncryptor
|
21
|
+
DEFAULT_CIPHER = "aes-256-cbc"
|
22
|
+
|
21
23
|
module NullSerializer #:nodoc:
|
22
24
|
def self.load(value)
|
23
25
|
value
|
@@ -64,6 +66,11 @@ module ActiveSupport
|
|
64
66
|
_decrypt(verifier.verify(value))
|
65
67
|
end
|
66
68
|
|
69
|
+
# Given a cipher, returns the key length of the cipher to help generate the key of desired size
|
70
|
+
def self.key_len(cipher = DEFAULT_CIPHER)
|
71
|
+
OpenSSL::Cipher.new(cipher).key_len
|
72
|
+
end
|
73
|
+
|
67
74
|
private
|
68
75
|
|
69
76
|
def _encrypt(value)
|
@@ -97,7 +104,7 @@ module ActiveSupport
|
|
97
104
|
end
|
98
105
|
|
99
106
|
def new_cipher
|
100
|
-
OpenSSL::Cipher
|
107
|
+
OpenSSL::Cipher.new(@cipher)
|
101
108
|
end
|
102
109
|
|
103
110
|
def verifier
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
module SecurityUtils
|
3
5
|
# Constant time string comparison.
|
@@ -16,5 +18,10 @@ module ActiveSupport
|
|
16
18
|
res == 0
|
17
19
|
end
|
18
20
|
module_function :secure_compare
|
21
|
+
|
22
|
+
def variable_size_secure_compare(a, b) # :nodoc:
|
23
|
+
secure_compare(::Digest::SHA256.hexdigest(a), ::Digest::SHA256.hexdigest(b))
|
24
|
+
end
|
25
|
+
module_function :variable_size_secure_compare
|
19
26
|
end
|
20
27
|
end
|
@@ -7,7 +7,7 @@ module ActiveSupport
|
|
7
7
|
@stubs = {}
|
8
8
|
end
|
9
9
|
|
10
|
-
def stub_object(object, method_name,
|
10
|
+
def stub_object(object, method_name, &block)
|
11
11
|
key = [object.object_id, method_name]
|
12
12
|
|
13
13
|
if stub = @stubs[key]
|
@@ -19,7 +19,7 @@ module ActiveSupport
|
|
19
19
|
@stubs[key] = Stub.new(object, method_name, new_name)
|
20
20
|
|
21
21
|
object.singleton_class.send :alias_method, new_name, method_name
|
22
|
-
object.define_singleton_method(method_name)
|
22
|
+
object.define_singleton_method(method_name, &block)
|
23
23
|
end
|
24
24
|
|
25
25
|
def unstub_all!
|
@@ -42,12 +42,13 @@ module ActiveSupport
|
|
42
42
|
# Containing helpers that helps you test passage of time.
|
43
43
|
module TimeHelpers
|
44
44
|
# Changes current time to the time in the future or in the past by a given time difference by
|
45
|
-
# stubbing +Time.now+ and +
|
45
|
+
# stubbing +Time.now+, +Date.today+, and +DateTime.now+.
|
46
46
|
#
|
47
|
-
# Time.current
|
47
|
+
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
|
48
48
|
# travel 1.day
|
49
|
-
# Time.current
|
50
|
-
# Date.current
|
49
|
+
# Time.current # => Sun, 10 Nov 2013 15:34:49 EST -05:00
|
50
|
+
# Date.current # => Sun, 10 Nov 2013
|
51
|
+
# DateTime.current # => Sun, 10 Nov 2013 15:34:49 -0500
|
51
52
|
#
|
52
53
|
# This method also accepts a block, which will return the current time back to its original
|
53
54
|
# state at the end of the block:
|
@@ -61,13 +62,14 @@ module ActiveSupport
|
|
61
62
|
travel_to Time.now + duration, &block
|
62
63
|
end
|
63
64
|
|
64
|
-
# Changes current time to the given time by stubbing +Time.now
|
65
|
-
# +Date.today+ to return the time or date passed into this method.
|
65
|
+
# Changes current time to the given time by stubbing +Time.now+,
|
66
|
+
# +Date.today+, and +DateTime.now+ to return the time or date passed into this method.
|
66
67
|
#
|
67
|
-
# Time.current
|
68
|
+
# Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
|
68
69
|
# travel_to Time.new(2004, 11, 24, 01, 04, 44)
|
69
|
-
# Time.current
|
70
|
-
# Date.current
|
70
|
+
# Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
|
71
|
+
# Date.current # => Wed, 24 Nov 2004
|
72
|
+
# DateTime.current # => Wed, 24 Nov 2004 01:04:44 -0500
|
71
73
|
#
|
72
74
|
# Dates are taken as their timestamp at the beginning of the day in the
|
73
75
|
# application time zone. <tt>Time.current</tt> returns said timestamp,
|
@@ -97,8 +99,9 @@ module ActiveSupport
|
|
97
99
|
now = date_or_time.to_time.change(usec: 0)
|
98
100
|
end
|
99
101
|
|
100
|
-
simple_stubs.stub_object(Time, :now
|
101
|
-
simple_stubs.stub_object(Date, :today
|
102
|
+
simple_stubs.stub_object(Time, :now) { at(now.to_i) }
|
103
|
+
simple_stubs.stub_object(Date, :today) { jd(now.to_date.jd) }
|
104
|
+
simple_stubs.stub_object(DateTime, :now) { jd(now.to_date.jd, now.hour, now.min, now.sec, Rational(now.utc_offset, 86400)) }
|
102
105
|
|
103
106
|
if block_given?
|
104
107
|
begin
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/values/time_zone'
|
2
2
|
require 'active_support/core_ext/object/acts_like'
|
3
|
+
require 'active_support/core_ext/date_and_time/compatibility'
|
3
4
|
|
4
5
|
module ActiveSupport
|
5
6
|
# A Time-like class that can represent a time in any time zone. Necessary
|
@@ -40,20 +41,21 @@ module ActiveSupport
|
|
40
41
|
'Time'
|
41
42
|
end
|
42
43
|
|
43
|
-
include Comparable
|
44
|
+
include Comparable, DateAndTime::Compatibility
|
44
45
|
attr_reader :time_zone
|
45
46
|
|
46
47
|
def initialize(utc_time, time_zone, local_time = nil, period = nil)
|
47
|
-
@utc
|
48
|
+
@utc = utc_time ? transfer_time_values_to_utc_constructor(utc_time) : nil
|
49
|
+
@time_zone, @time = time_zone, local_time
|
48
50
|
@period = @utc ? period : get_period_and_ensure_valid_local_time(period)
|
49
51
|
end
|
50
52
|
|
51
|
-
# Returns a Time
|
53
|
+
# Returns a <tt>Time</tt> instance that represents the time in +time_zone+.
|
52
54
|
def time
|
53
55
|
@time ||= period.to_local(@utc)
|
54
56
|
end
|
55
57
|
|
56
|
-
# Returns a Time
|
58
|
+
# Returns a <tt>Time</tt> instance of the simultaneous time in the UTC timezone.
|
57
59
|
def utc
|
58
60
|
@utc ||= period.to_utc(@time)
|
59
61
|
end
|
@@ -73,10 +75,9 @@ module ActiveSupport
|
|
73
75
|
utc.in_time_zone(new_zone)
|
74
76
|
end
|
75
77
|
|
76
|
-
# Returns a <tt>Time
|
77
|
-
# system's <tt>ENV['TZ']</tt> zone.
|
78
|
+
# Returns a <tt>Time</tt> instance of the simultaneous time in the system timezone.
|
78
79
|
def localtime(utc_offset = nil)
|
79
|
-
utc.
|
80
|
+
utc.getlocal(utc_offset)
|
80
81
|
end
|
81
82
|
alias_method :getlocal, :localtime
|
82
83
|
|
@@ -160,7 +161,11 @@ module ActiveSupport
|
|
160
161
|
end
|
161
162
|
end
|
162
163
|
|
163
|
-
def
|
164
|
+
def init_with(coder) #:nodoc:
|
165
|
+
initialize(coder['utc'], coder['zone'], coder['time'])
|
166
|
+
end
|
167
|
+
|
168
|
+
def encode_with(coder) #:nodoc:
|
164
169
|
if coder.respond_to?(:represent_object)
|
165
170
|
coder.represent_object(nil, utc)
|
166
171
|
else
|
@@ -276,6 +281,7 @@ module ActiveSupport
|
|
276
281
|
utc.since(other).in_time_zone(time_zone)
|
277
282
|
end
|
278
283
|
end
|
284
|
+
alias_method :in, :since
|
279
285
|
|
280
286
|
def ago(other)
|
281
287
|
since(-other)
|
@@ -316,13 +322,19 @@ module ActiveSupport
|
|
316
322
|
utc.to_r
|
317
323
|
end
|
318
324
|
|
319
|
-
|
320
|
-
|
321
|
-
utc.to_time
|
325
|
+
def to_datetime
|
326
|
+
@to_datetime ||= utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
|
322
327
|
end
|
323
328
|
|
324
|
-
|
325
|
-
|
329
|
+
# Returns an instance of +Time+, either with the same UTC offset
|
330
|
+
# as +self+ or in the local system timezone depending on the setting
|
331
|
+
# of +ActiveSupport.to_time_preserves_timezone+.
|
332
|
+
def to_time
|
333
|
+
if preserve_timezone
|
334
|
+
@to_time_with_instance_offset ||= getlocal(utc_offset)
|
335
|
+
else
|
336
|
+
@to_time_with_system_offset ||= getlocal
|
337
|
+
end
|
326
338
|
end
|
327
339
|
|
328
340
|
# So that +self+ <tt>acts_like?(:time)</tt>.
|
@@ -337,7 +349,8 @@ module ActiveSupport
|
|
337
349
|
alias_method :kind_of?, :is_a?
|
338
350
|
|
339
351
|
def freeze
|
340
|
-
|
352
|
+
# preload instance variables before freezing
|
353
|
+
period; utc; time; to_datetime; to_time
|
341
354
|
super
|
342
355
|
end
|
343
356
|
|
@@ -360,7 +373,6 @@ module ActiveSupport
|
|
360
373
|
# Ensure proxy class responds to all methods that underlying time instance
|
361
374
|
# responds to.
|
362
375
|
def respond_to_missing?(sym, include_priv)
|
363
|
-
# consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
|
364
376
|
return false if sym.to_sym == :acts_like_date?
|
365
377
|
time.respond_to?(sym, include_priv)
|
366
378
|
end
|
@@ -388,7 +400,7 @@ module ActiveSupport
|
|
388
400
|
end
|
389
401
|
|
390
402
|
def transfer_time_values_to_utc_constructor(time)
|
391
|
-
::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec
|
403
|
+
::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec + time.subsec)
|
392
404
|
end
|
393
405
|
|
394
406
|
def duration_of_variable_length?(obj)
|
@@ -271,7 +271,10 @@ module ActiveSupport
|
|
271
271
|
@name = name
|
272
272
|
@utc_offset = utc_offset
|
273
273
|
@tzinfo = tzinfo || TimeZone.find_tzinfo(name)
|
274
|
-
|
274
|
+
end
|
275
|
+
|
276
|
+
def init_with(coder) #:nodoc:
|
277
|
+
initialize(coder['name'])
|
275
278
|
end
|
276
279
|
|
277
280
|
# Returns the offset of this time zone from UTC in seconds.
|
@@ -279,8 +282,7 @@ module ActiveSupport
|
|
279
282
|
if @utc_offset
|
280
283
|
@utc_offset
|
281
284
|
else
|
282
|
-
|
283
|
-
@current_period.utc_offset if @current_period
|
285
|
+
tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
|
284
286
|
end
|
285
287
|
end
|
286
288
|
|
@@ -66,12 +66,9 @@ module ActiveSupport
|
|
66
66
|
data = StringIO.new(data || '')
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
if char.nil?
|
69
|
+
if data.eof?
|
71
70
|
{}
|
72
71
|
else
|
73
|
-
data.ungetc(char)
|
74
|
-
|
75
72
|
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
76
73
|
parser = LibXML::XML::SaxParser.io(data)
|
77
74
|
document = self.document_class.new
|
@@ -72,11 +72,9 @@ module ActiveSupport
|
|
72
72
|
data = StringIO.new(data || '')
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
if char.nil?
|
75
|
+
if data.eof?
|
77
76
|
{}
|
78
77
|
else
|
79
|
-
data.ungetc(char)
|
80
78
|
document = self.document_class.new
|
81
79
|
parser = Nokogiri::XML::SAX::Parser.new(document)
|
82
80
|
parser.parse(data)
|
@@ -20,11 +20,9 @@ module ActiveSupport
|
|
20
20
|
data = StringIO.new(data || '')
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
if char.nil?
|
23
|
+
if data.eof?
|
25
24
|
{}
|
26
25
|
else
|
27
|
-
data.ungetc(char)
|
28
26
|
silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
|
29
27
|
doc = REXML::Document.new(data)
|
30
28
|
|
@@ -32,20 +32,25 @@ module ActiveSupport
|
|
32
32
|
"binary" => "base64"
|
33
33
|
} unless defined?(DEFAULT_ENCODINGS)
|
34
34
|
|
35
|
-
TYPE_NAMES
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
35
|
+
unless defined?(TYPE_NAMES)
|
36
|
+
TYPE_NAMES = {
|
37
|
+
"Symbol" => "symbol",
|
38
|
+
"Integer" => "integer",
|
39
|
+
"BigDecimal" => "decimal",
|
40
|
+
"Float" => "float",
|
41
|
+
"TrueClass" => "boolean",
|
42
|
+
"FalseClass" => "boolean",
|
43
|
+
"Date" => "date",
|
44
|
+
"DateTime" => "dateTime",
|
45
|
+
"Time" => "dateTime",
|
46
|
+
"Array" => "array",
|
47
|
+
"Hash" => "hash"
|
48
|
+
}
|
49
|
+
|
50
|
+
# No need to map these on Ruby 2.4+
|
51
|
+
TYPE_NAMES["Fixnum"] = "integer" unless 0.class == Integer
|
52
|
+
TYPE_NAMES["Bignum"] = "integer" unless 0.class == Integer
|
53
|
+
end
|
49
54
|
|
50
55
|
FORMATTING = {
|
51
56
|
"symbol" => Proc.new { |symbol| symbol.to_s },
|
@@ -63,7 +68,17 @@ module ActiveSupport
|
|
63
68
|
"datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
|
64
69
|
"integer" => Proc.new { |integer| integer.to_i },
|
65
70
|
"float" => Proc.new { |float| float.to_f },
|
66
|
-
"decimal" => Proc.new
|
71
|
+
"decimal" => Proc.new do |number|
|
72
|
+
if String === number
|
73
|
+
begin
|
74
|
+
BigDecimal(number)
|
75
|
+
rescue ArgumentError
|
76
|
+
BigDecimal('0')
|
77
|
+
end
|
78
|
+
else
|
79
|
+
BigDecimal(number)
|
80
|
+
end
|
81
|
+
end,
|
67
82
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
|
68
83
|
"string" => Proc.new { |string| string.to_s },
|
69
84
|
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
|
data/lib/active_support.rb
CHANGED
@@ -26,6 +26,7 @@ require "active_support/dependencies/autoload"
|
|
26
26
|
require "active_support/version"
|
27
27
|
require "active_support/logger"
|
28
28
|
require "active_support/lazy_load_hooks"
|
29
|
+
require "active_support/core_ext/date_and_time/compatibility"
|
29
30
|
|
30
31
|
module ActiveSupport
|
31
32
|
extend ActiveSupport::Autoload
|
@@ -80,6 +81,14 @@ module ActiveSupport
|
|
80
81
|
def self.test_order # :nodoc:
|
81
82
|
@@test_order
|
82
83
|
end
|
84
|
+
|
85
|
+
def self.to_time_preserves_timezone
|
86
|
+
DateAndTime::Compatibility.preserve_timezone
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.to_time_preserves_timezone=(value)
|
90
|
+
DateAndTime::Compatibility.preserve_timezone = value
|
91
|
+
end
|
83
92
|
end
|
84
93
|
|
85
94
|
autoload :I18n, "active_support/i18n"
|
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.
|
4
|
+
version: 4.2.11.3
|
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:
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -24,26 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.7'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.7'
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 1.7.7
|
37
|
-
type: :runtime
|
38
|
-
prerelease: false
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
40
|
-
requirements:
|
41
|
-
- - "~>"
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '1.7'
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.7.7
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: tzinfo
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,10 +122,12 @@ files:
|
|
142
122
|
- lib/active_support/core_ext/date/conversions.rb
|
143
123
|
- lib/active_support/core_ext/date/zones.rb
|
144
124
|
- lib/active_support/core_ext/date_and_time/calculations.rb
|
125
|
+
- lib/active_support/core_ext/date_and_time/compatibility.rb
|
145
126
|
- lib/active_support/core_ext/date_and_time/zones.rb
|
146
127
|
- lib/active_support/core_ext/date_time.rb
|
147
128
|
- lib/active_support/core_ext/date_time/acts_like.rb
|
148
129
|
- lib/active_support/core_ext/date_time/calculations.rb
|
130
|
+
- lib/active_support/core_ext/date_time/compatibility.rb
|
149
131
|
- lib/active_support/core_ext/date_time/conversions.rb
|
150
132
|
- lib/active_support/core_ext/date_time/zones.rb
|
151
133
|
- lib/active_support/core_ext/digest/uuid.rb
|
@@ -231,6 +213,7 @@ files:
|
|
231
213
|
- lib/active_support/core_ext/time.rb
|
232
214
|
- lib/active_support/core_ext/time/acts_like.rb
|
233
215
|
- lib/active_support/core_ext/time/calculations.rb
|
216
|
+
- lib/active_support/core_ext/time/compatibility.rb
|
234
217
|
- lib/active_support/core_ext/time/conversions.rb
|
235
218
|
- lib/active_support/core_ext/time/marshal.rb
|
236
219
|
- lib/active_support/core_ext/time/zones.rb
|
@@ -266,6 +249,7 @@ files:
|
|
266
249
|
- lib/active_support/log_subscriber/test_helper.rb
|
267
250
|
- lib/active_support/logger.rb
|
268
251
|
- lib/active_support/logger_silence.rb
|
252
|
+
- lib/active_support/logger_thread_safe_level.rb
|
269
253
|
- lib/active_support/message_encryptor.rb
|
270
254
|
- lib/active_support/message_verifier.rb
|
271
255
|
- lib/active_support/multibyte.rb
|
@@ -338,8 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
338
322
|
- !ruby/object:Gem::Version
|
339
323
|
version: '0'
|
340
324
|
requirements: []
|
341
|
-
|
342
|
-
rubygems_version: 2.4.5.1
|
325
|
+
rubygems_version: 3.0.3
|
343
326
|
signing_key:
|
344
327
|
specification_version: 4
|
345
328
|
summary: A toolkit of support libraries and Ruby core extensions extracted from the
|