activesupport 5.0.7.2 → 5.1.0.beta1
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 +215 -820
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +8 -4
- data/lib/active_support/all.rb +3 -3
- data/lib/active_support/array_inquirer.rb +7 -5
- data/lib/active_support/backtrace_cleaner.rb +4 -4
- data/lib/active_support/benchmarkable.rb +3 -3
- data/lib/active_support/builder.rb +1 -1
- data/lib/active_support/cache.rb +42 -49
- data/lib/active_support/cache/file_store.rb +12 -21
- data/lib/active_support/cache/mem_cache_store.rb +30 -40
- data/lib/active_support/cache/memory_store.rb +11 -13
- data/lib/active_support/cache/null_store.rb +4 -4
- data/lib/active_support/cache/strategy/local_cache.rb +16 -25
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +8 -9
- data/lib/active_support/callbacks.rb +647 -584
- data/lib/active_support/concurrency/share_lock.rb +20 -21
- data/lib/active_support/configurable.rb +5 -5
- data/lib/active_support/core_ext.rb +1 -2
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/array/access.rb +1 -1
- data/lib/active_support/core_ext/array/conversions.rb +15 -15
- data/lib/active_support/core_ext/array/grouping.rb +1 -1
- data/lib/active_support/core_ext/array/inquiry.rb +1 -1
- data/lib/active_support/core_ext/array/prepend_and_append.rb +1 -1
- data/lib/active_support/core_ext/benchmark.rb +1 -1
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +4 -6
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/class/attribute.rb +5 -5
- data/lib/active_support/core_ext/class/attribute_accessors.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +18 -4
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date/acts_like.rb +1 -1
- data/lib/active_support/core_ext/date/blank.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +8 -8
- data/lib/active_support/core_ext/date/conversions.rb +12 -12
- data/lib/active_support/core_ext/date/zones.rb +2 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -22
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +9 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +7 -8
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -2
- data/lib/active_support/core_ext/date_time/blank.rb +1 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +9 -9
- data/lib/active_support/core_ext/date_time/compatibility.rb +2 -13
- data/lib/active_support/core_ext/date_time/conversions.rb +12 -12
- data/lib/active_support/core_ext/digest/uuid.rb +4 -4
- data/lib/active_support/core_ext/enumerable.rb +46 -57
- data/lib/active_support/core_ext/file.rb +1 -1
- data/lib/active_support/core_ext/file/atomic.rb +4 -4
- data/lib/active_support/core_ext/hash.rb +9 -9
- data/lib/active_support/core_ext/hash/compact.rb +12 -9
- data/lib/active_support/core_ext/hash/conversions.rb +36 -37
- data/lib/active_support/core_ext/hash/indifferent_access.rb +1 -2
- data/lib/active_support/core_ext/hash/keys.rb +8 -8
- data/lib/active_support/core_ext/hash/reverse_merge.rb +1 -1
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +1 -0
- data/lib/active_support/core_ext/integer.rb +3 -3
- data/lib/active_support/core_ext/integer/inflections.rb +1 -1
- data/lib/active_support/core_ext/integer/time.rb +2 -2
- data/lib/active_support/core_ext/kernel.rb +4 -4
- data/lib/active_support/core_ext/kernel/concern.rb +1 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +1 -18
- data/lib/active_support/core_ext/marshal.rb +2 -2
- data/lib/active_support/core_ext/module.rb +11 -12
- data/lib/active_support/core_ext/module/aliasing.rb +3 -48
- data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -5
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +20 -13
- data/lib/active_support/core_ext/module/concerning.rb +1 -1
- data/lib/active_support/core_ext/module/delegation.rb +82 -16
- data/lib/active_support/core_ext/module/introspection.rb +3 -11
- data/lib/active_support/core_ext/module/reachable.rb +2 -2
- data/lib/active_support/core_ext/numeric.rb +4 -4
- data/lib/active_support/core_ext/numeric/conversions.rb +3 -9
- data/lib/active_support/core_ext/numeric/inquiry.rb +21 -21
- data/lib/active_support/core_ext/numeric/time.rb +5 -5
- data/lib/active_support/core_ext/object.rb +12 -12
- data/lib/active_support/core_ext/object/blank.rb +3 -1
- data/lib/active_support/core_ext/object/conversions.rb +4 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/duplicable.rb +24 -4
- data/lib/active_support/core_ext/object/inclusion.rb +1 -1
- data/lib/active_support/core_ext/object/json.rb +26 -12
- data/lib/active_support/core_ext/object/to_param.rb +1 -1
- data/lib/active_support/core_ext/object/to_query.rb +4 -4
- data/lib/active_support/core_ext/object/try.rb +1 -1
- data/lib/active_support/core_ext/object/with_options.rb +1 -1
- data/lib/active_support/core_ext/range.rb +4 -4
- data/lib/active_support/core_ext/range/conversions.rb +1 -1
- data/lib/active_support/core_ext/regexp.rb +4 -0
- data/lib/active_support/core_ext/securerandom.rb +3 -3
- data/lib/active_support/core_ext/string.rb +13 -13
- data/lib/active_support/core_ext/string/access.rb +6 -6
- data/lib/active_support/core_ext/string/conversions.rb +2 -2
- data/lib/active_support/core_ext/string/filters.rb +3 -3
- data/lib/active_support/core_ext/string/indent.rb +4 -4
- data/lib/active_support/core_ext/string/inflections.rb +10 -14
- data/lib/active_support/core_ext/string/inquiry.rb +1 -1
- data/lib/active_support/core_ext/string/multibyte.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +19 -20
- data/lib/active_support/core_ext/string/strip.rb +1 -1
- data/lib/active_support/core_ext/string/zones.rb +2 -2
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/core_ext/time/acts_like.rb +1 -1
- data/lib/active_support/core_ext/time/calculations.rb +23 -29
- data/lib/active_support/core_ext/time/compatibility.rb +1 -10
- data/lib/active_support/core_ext/time/conversions.rb +12 -12
- data/lib/active_support/core_ext/time/zones.rb +3 -3
- data/lib/active_support/core_ext/uri.rb +2 -2
- data/lib/active_support/dependencies.rb +45 -47
- data/lib/active_support/dependencies/interlock.rb +1 -1
- data/lib/active_support/deprecation.rb +8 -8
- data/lib/active_support/deprecation/behaviors.rb +3 -3
- data/lib/active_support/deprecation/instance_delegator.rb +2 -2
- data/lib/active_support/deprecation/method_wrappers.rb +3 -3
- data/lib/active_support/deprecation/proxy_wrappers.rb +6 -4
- data/lib/active_support/deprecation/reporting.rb +7 -7
- data/lib/active_support/duration.rb +30 -26
- data/lib/active_support/duration/iso8601_parser.rb +66 -65
- data/lib/active_support/duration/iso8601_serializer.rb +11 -9
- data/lib/active_support/evented_file_update_checker.rb +59 -60
- data/lib/active_support/execution_wrapper.rb +3 -3
- data/lib/active_support/executor.rb +1 -1
- data/lib/active_support/file_update_checker.rb +54 -50
- data/lib/active_support/gem_version.rb +3 -3
- data/lib/active_support/gzip.rb +5 -5
- data/lib/active_support/hash_with_indifferent_access.rb +10 -20
- data/lib/active_support/i18n.rb +5 -5
- data/lib/active_support/i18n_railtie.rb +11 -10
- data/lib/active_support/inflections.rb +11 -11
- data/lib/active_support/inflector.rb +5 -5
- data/lib/active_support/inflector/inflections.rb +11 -9
- data/lib/active_support/inflector/methods.rb +51 -50
- data/lib/active_support/inflector/transliterate.rb +8 -11
- data/lib/active_support/json.rb +2 -2
- data/lib/active_support/json/decoding.rb +3 -3
- data/lib/active_support/json/encoding.rb +8 -7
- data/lib/active_support/key_generator.rb +17 -17
- data/lib/active_support/lazy_load_hooks.rb +12 -30
- data/lib/active_support/log_subscriber.rb +5 -5
- data/lib/active_support/log_subscriber/test_helper.rb +9 -9
- data/lib/active_support/logger.rb +3 -3
- data/lib/active_support/logger_silence.rb +3 -3
- data/lib/active_support/logger_thread_safe_level.rb +1 -1
- data/lib/active_support/message_encryptor.rb +72 -35
- data/lib/active_support/message_verifier.rb +7 -7
- data/lib/active_support/multibyte.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +23 -21
- data/lib/active_support/multibyte/unicode.rb +68 -89
- data/lib/active_support/notifications.rb +5 -5
- data/lib/active_support/notifications/fanout.rb +3 -3
- data/lib/active_support/notifications/instrumenter.rb +5 -5
- data/lib/active_support/number_helper.rb +4 -4
- data/lib/active_support/number_helper/number_converter.rb +11 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +3 -3
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -2
- data/lib/active_support/number_helper/number_to_human_converter.rb +6 -6
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -11
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -3
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +6 -6
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +3 -3
- data/lib/active_support/ordered_options.rb +6 -4
- data/lib/active_support/per_thread_registry.rb +5 -5
- data/lib/active_support/rails.rb +12 -6
- data/lib/active_support/railtie.rb +3 -3
- data/lib/active_support/reloader.rb +1 -1
- data/lib/active_support/rescuable.rb +8 -14
- data/lib/active_support/security_utils.rb +1 -1
- data/lib/active_support/string_inquirer.rb +8 -2
- data/lib/active_support/subscriber.rb +9 -5
- data/lib/active_support/tagged_logging.rb +4 -4
- data/lib/active_support/test_case.rb +12 -29
- data/lib/active_support/testing/assertions.rb +100 -2
- data/lib/active_support/testing/autorun.rb +6 -2
- data/lib/active_support/testing/constant_lookup.rb +0 -1
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +3 -2
- data/lib/active_support/testing/isolation.rb +13 -22
- data/lib/active_support/testing/method_call_assertions.rb +1 -1
- data/lib/active_support/testing/setup_and_teardown.rb +2 -2
- data/lib/active_support/testing/stream.rb +28 -28
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +45 -12
- data/lib/active_support/time.rb +12 -12
- data/lib/active_support/time_with_zone.rb +16 -26
- data/lib/active_support/values/time_zone.rb +40 -46
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/xml_mini.rb +34 -36
- data/lib/active_support/xml_mini/jdom.rb +112 -112
- data/lib/active_support/xml_mini/libxml.rb +15 -12
- data/lib/active_support/xml_mini/libxmlsax.rb +17 -15
- data/lib/active_support/xml_mini/nokogiri.rb +13 -11
- data/lib/active_support/xml_mini/nokogirisax.rb +15 -14
- data/lib/active_support/xml_mini/rexml.rb +9 -9
- metadata +8 -19
- data/lib/active_support/concurrency/latch.rb +0 -26
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
- data/lib/active_support/core_ext/struct.rb +0 -3
- data/lib/active_support/core_ext/time/marshal.rb +0 -3
data/lib/active_support/time.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module ActiveSupport
|
2
|
-
autoload :Duration,
|
3
|
-
autoload :TimeWithZone,
|
4
|
-
autoload :TimeZone,
|
2
|
+
autoload :Duration, "active_support/duration"
|
3
|
+
autoload :TimeWithZone, "active_support/time_with_zone"
|
4
|
+
autoload :TimeZone, "active_support/values/time_zone"
|
5
5
|
end
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "date"
|
8
|
+
require "time"
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "active_support/core_ext/time"
|
11
|
+
require "active_support/core_ext/date"
|
12
|
+
require "active_support/core_ext/date_time"
|
13
13
|
|
14
|
-
require
|
15
|
-
require
|
14
|
+
require "active_support/core_ext/integer/time"
|
15
|
+
require "active_support/core_ext/numeric/time"
|
16
16
|
|
17
|
-
require
|
18
|
-
require
|
17
|
+
require "active_support/core_ext/string/conversions"
|
18
|
+
require "active_support/core_ext/string/zones"
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "active_support/duration"
|
2
|
+
require "active_support/values/time_zone"
|
3
|
+
require "active_support/core_ext/object/acts_like"
|
4
|
+
require "active_support/core_ext/date_and_time/compatibility"
|
5
5
|
|
6
6
|
module ActiveSupport
|
7
7
|
# A Time-like class that can represent a time in any time zone. Necessary
|
@@ -36,14 +36,13 @@ module ActiveSupport
|
|
36
36
|
# t.is_a?(Time) # => true
|
37
37
|
# t.is_a?(ActiveSupport::TimeWithZone) # => true
|
38
38
|
class TimeWithZone
|
39
|
-
|
40
39
|
# Report class name as 'Time' to thwart type checking.
|
41
40
|
def self.name
|
42
|
-
|
41
|
+
"Time"
|
43
42
|
end
|
44
43
|
|
45
44
|
PRECISIONS = Hash.new { |h, n| h[n] = "%FT%T.%#{n}N".freeze }
|
46
|
-
PRECISIONS[0] =
|
45
|
+
PRECISIONS[0] = "%FT%T".freeze
|
47
46
|
|
48
47
|
include Comparable, DateAndTime::Compatibility
|
49
48
|
attr_reader :time_zone
|
@@ -134,7 +133,7 @@ module ActiveSupport
|
|
134
133
|
period.zone_identifier.to_s
|
135
134
|
end
|
136
135
|
|
137
|
-
# Returns a string of the object's date, time, zone and offset from UTC.
|
136
|
+
# Returns a string of the object's date, time, zone, and offset from UTC.
|
138
137
|
#
|
139
138
|
# Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25 EST -05:00"
|
140
139
|
def inspect
|
@@ -171,12 +170,12 @@ module ActiveSupport
|
|
171
170
|
end
|
172
171
|
|
173
172
|
def init_with(coder) #:nodoc:
|
174
|
-
initialize(coder[
|
173
|
+
initialize(coder["utc"], coder["zone"], coder["time"])
|
175
174
|
end
|
176
175
|
|
177
176
|
def encode_with(coder) #:nodoc:
|
178
|
-
coder.tag =
|
179
|
-
coder.map = {
|
177
|
+
coder.tag = "!ruby/object:ActiveSupport::TimeWithZone"
|
178
|
+
coder.map = { "utc" => utc, "zone" => time_zone, "time" => time }
|
180
179
|
end
|
181
180
|
|
182
181
|
# Returns a string of the object's date and time in the format used by
|
@@ -408,18 +407,7 @@ module ActiveSupport
|
|
408
407
|
# Time.zone.now.to_datetime # => Tue, 18 Aug 2015 02:32:20 +0000
|
409
408
|
# Time.current.in_time_zone('Hawaii').to_datetime # => Mon, 17 Aug 2015 16:32:20 -1000
|
410
409
|
def to_datetime
|
411
|
-
utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
|
412
|
-
end
|
413
|
-
|
414
|
-
# Returns an instance of +Time+, either with the same UTC offset
|
415
|
-
# as +self+ or in the local system timezone depending on the setting
|
416
|
-
# of +ActiveSupport.to_time_preserves_timezone+.
|
417
|
-
def to_time
|
418
|
-
if preserve_timezone
|
419
|
-
@to_time_with_instance_offset ||= getlocal(utc_offset)
|
420
|
-
else
|
421
|
-
@to_time_with_system_offset ||= getlocal
|
422
|
-
end
|
410
|
+
@to_datetime ||= utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
|
423
411
|
end
|
424
412
|
|
425
413
|
# So that +self+ <tt>acts_like?(:time)</tt>.
|
@@ -440,7 +428,7 @@ module ActiveSupport
|
|
440
428
|
|
441
429
|
def freeze
|
442
430
|
# preload instance variables before freezing
|
443
|
-
period; utc; time; to_datetime
|
431
|
+
period; utc; time; to_datetime
|
444
432
|
super
|
445
433
|
end
|
446
434
|
|
@@ -472,7 +460,7 @@ module ActiveSupport
|
|
472
460
|
def method_missing(sym, *args, &block)
|
473
461
|
wrap_with_time_zone time.__send__(sym, *args, &block)
|
474
462
|
rescue NoMethodError => e
|
475
|
-
raise e, e.message.sub(time.inspect,
|
463
|
+
raise e, e.message.sub(time.inspect, inspect), e.backtrace
|
476
464
|
end
|
477
465
|
|
478
466
|
private
|
@@ -490,11 +478,13 @@ module ActiveSupport
|
|
490
478
|
end
|
491
479
|
|
492
480
|
def transfer_time_values_to_utc_constructor(time)
|
481
|
+
# avoid creating another Time object if possible
|
482
|
+
return time if time.instance_of?(::Time) && time.utc?
|
493
483
|
::Time.utc(time.year, time.month, time.day, time.hour, time.min, time.sec + time.subsec)
|
494
484
|
end
|
495
485
|
|
496
486
|
def duration_of_variable_length?(obj)
|
497
|
-
ActiveSupport::Duration === obj && obj.parts.any? {|p| [:years, :months, :weeks, :days].include?(p[0]) }
|
487
|
+
ActiveSupport::Duration === obj && obj.parts.any? { |p| [:years, :months, :weeks, :days].include?(p[0]) }
|
498
488
|
end
|
499
489
|
|
500
490
|
def wrap_with_time_zone(time)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "tzinfo"
|
2
|
+
require "concurrent/map"
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
4
|
|
5
5
|
module ActiveSupport
|
6
6
|
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
|
@@ -180,8 +180,8 @@ module ActiveSupport
|
|
180
180
|
"Samoa" => "Pacific/Apia"
|
181
181
|
}
|
182
182
|
|
183
|
-
UTC_OFFSET_WITH_COLON =
|
184
|
-
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(
|
183
|
+
UTC_OFFSET_WITH_COLON = "%s%02d:%02d"
|
184
|
+
UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "")
|
185
185
|
|
186
186
|
@lazy_zones_map = Concurrent::Map.new
|
187
187
|
@country_zones = Concurrent::Map.new
|
@@ -193,7 +193,7 @@ module ActiveSupport
|
|
193
193
|
# ActiveSupport::TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00"
|
194
194
|
def seconds_to_utc_offset(seconds, colon = true)
|
195
195
|
format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON
|
196
|
-
sign = (seconds < 0 ?
|
196
|
+
sign = (seconds < 0 ? "-" : "+")
|
197
197
|
hours = seconds.abs / 3600
|
198
198
|
minutes = (seconds.abs % 3600) / 60
|
199
199
|
format % [sign, hours, minutes]
|
@@ -226,17 +226,17 @@ module ActiveSupport
|
|
226
226
|
# Returns +nil+ if no such time zone is known to the system.
|
227
227
|
def [](arg)
|
228
228
|
case arg
|
229
|
-
|
229
|
+
when String
|
230
230
|
begin
|
231
231
|
@lazy_zones_map[arg] ||= create(arg)
|
232
232
|
rescue TZInfo::InvalidTimezoneIdentifier
|
233
233
|
nil
|
234
234
|
end
|
235
|
-
|
236
|
-
|
237
|
-
|
235
|
+
when Numeric, ActiveSupport::Duration
|
236
|
+
arg *= 3600 if arg.abs <= 13
|
237
|
+
all.find { |z| z.utc_offset == arg.to_i }
|
238
238
|
else
|
239
|
-
|
239
|
+
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
@@ -250,27 +250,17 @@ module ActiveSupport
|
|
250
250
|
# for time zones in the country specified by its ISO 3166-1 Alpha2 code.
|
251
251
|
def country_zones(country_code)
|
252
252
|
code = country_code.to_s.upcase
|
253
|
-
@country_zones[code] ||=
|
253
|
+
@country_zones[code] ||=
|
254
|
+
TZInfo::Country.get(code).zone_identifiers.map do |tz_id|
|
255
|
+
name = MAPPING.key(tz_id)
|
256
|
+
name && self[name]
|
257
|
+
end.compact.sort!
|
254
258
|
end
|
255
259
|
|
256
260
|
private
|
257
|
-
def load_country_zones(code)
|
258
|
-
country = TZInfo::Country.get(code)
|
259
|
-
country.zone_identifiers.map do |tz_id|
|
260
|
-
if MAPPING.value?(tz_id)
|
261
|
-
MAPPING.inject([]) do |memo, (key, value)|
|
262
|
-
memo << self[key] if value == tz_id
|
263
|
-
memo
|
264
|
-
end
|
265
|
-
else
|
266
|
-
create(tz_id, nil, TZInfo::Timezone.new(tz_id))
|
267
|
-
end
|
268
|
-
end.flatten(1).sort!
|
269
|
-
end
|
270
|
-
|
271
261
|
def zones_map
|
272
262
|
@zones_map ||= begin
|
273
|
-
MAPPING.each_key {|place| self[place]} # load all the zones
|
263
|
+
MAPPING.each_key { |place| self[place] } # load all the zones
|
274
264
|
@lazy_zones_map
|
275
265
|
end
|
276
266
|
end
|
@@ -305,7 +295,7 @@ module ActiveSupport
|
|
305
295
|
# zone = ActiveSupport::TimeZone['Central Time (US & Canada)']
|
306
296
|
# zone.formatted_offset # => "-06:00"
|
307
297
|
# zone.formatted_offset(false) # => "-0600"
|
308
|
-
def formatted_offset(colon=true, alternate_utc_string = nil)
|
298
|
+
def formatted_offset(colon = true, alternate_utc_string = nil)
|
309
299
|
utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon)
|
310
300
|
end
|
311
301
|
|
@@ -365,7 +355,7 @@ module ActiveSupport
|
|
365
355
|
# components are supplied, then the day of the month defaults to 1:
|
366
356
|
#
|
367
357
|
# Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
|
368
|
-
def parse(str, now=now())
|
358
|
+
def parse(str, now = now())
|
369
359
|
parts_to_time(Date._parse(str, false), now)
|
370
360
|
end
|
371
361
|
|
@@ -389,7 +379,7 @@ module ActiveSupport
|
|
389
379
|
# components are supplied, then the day of the month defaults to 1:
|
390
380
|
#
|
391
381
|
# Time.zone.strptime('Mar 2000', '%b %Y') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
|
392
|
-
def strptime(str, format, now=now())
|
382
|
+
def strptime(str, format, now = now())
|
393
383
|
parts_to_time(DateTime._strptime(str, format), now)
|
394
384
|
end
|
395
385
|
|
@@ -426,7 +416,7 @@ module ActiveSupport
|
|
426
416
|
|
427
417
|
# Adjust the given time to the simultaneous time in UTC. Returns a
|
428
418
|
# Time.utc() instance.
|
429
|
-
def local_to_utc(time, dst=true)
|
419
|
+
def local_to_utc(time, dst = true)
|
430
420
|
tzinfo.local_to_utc(time, dst)
|
431
421
|
end
|
432
422
|
|
@@ -438,7 +428,7 @@ module ActiveSupport
|
|
438
428
|
|
439
429
|
# Available so that TimeZone instances respond like TZInfo::Timezone
|
440
430
|
# instances.
|
441
|
-
def period_for_local(time, dst=true)
|
431
|
+
def period_for_local(time, dst = true)
|
442
432
|
tzinfo.period_for_local(time, dst)
|
443
433
|
end
|
444
434
|
|
@@ -447,12 +437,12 @@ module ActiveSupport
|
|
447
437
|
end
|
448
438
|
|
449
439
|
def init_with(coder) #:nodoc:
|
450
|
-
initialize(coder[
|
440
|
+
initialize(coder["name"])
|
451
441
|
end
|
452
442
|
|
453
443
|
def encode_with(coder) #:nodoc:
|
454
|
-
coder.tag ="!ruby/object:#{self.class}"
|
455
|
-
coder.map = {
|
444
|
+
coder.tag = "!ruby/object:#{self.class}"
|
445
|
+
coder.map = { "name" => tzinfo.name }
|
456
446
|
end
|
457
447
|
|
458
448
|
private
|
@@ -460,17 +450,21 @@ module ActiveSupport
|
|
460
450
|
raise ArgumentError, "invalid date" if parts.nil?
|
461
451
|
return if parts.empty?
|
462
452
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
453
|
+
if parts[:seconds]
|
454
|
+
time = Time.at(parts[:seconds])
|
455
|
+
else
|
456
|
+
time = Time.new(
|
457
|
+
parts.fetch(:year, now.year),
|
458
|
+
parts.fetch(:mon, now.month),
|
459
|
+
parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day),
|
460
|
+
parts.fetch(:hour, 0),
|
461
|
+
parts.fetch(:min, 0),
|
462
|
+
parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
|
463
|
+
parts.fetch(:offset, 0)
|
464
|
+
)
|
465
|
+
end
|
466
|
+
|
467
|
+
if parts[:offset] || parts[:seconds]
|
474
468
|
TimeWithZone.new(time.utc, self)
|
475
469
|
else
|
476
470
|
TimeWithZone.new(nil, self, time)
|
Binary file
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "time"
|
2
|
+
require "base64"
|
3
|
+
require "bigdecimal"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
5
|
+
require "active_support/core_ext/string/inflections"
|
6
|
+
require "active_support/core_ext/date_time/calculations"
|
7
7
|
|
8
8
|
module ActiveSupport
|
9
9
|
# = XmlMini
|
@@ -20,11 +20,11 @@ module ActiveSupport
|
|
20
20
|
attr_writer :original_filename, :content_type
|
21
21
|
|
22
22
|
def original_filename
|
23
|
-
@original_filename ||
|
23
|
+
@original_filename || "untitled"
|
24
24
|
end
|
25
25
|
|
26
26
|
def content_type
|
27
|
-
@content_type ||
|
27
|
+
@content_type || "application/octet-stream"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -73,7 +73,7 @@ module ActiveSupport
|
|
73
73
|
begin
|
74
74
|
BigDecimal(number)
|
75
75
|
rescue ArgumentError
|
76
|
-
BigDecimal(
|
76
|
+
BigDecimal("0")
|
77
77
|
end
|
78
78
|
else
|
79
79
|
BigDecimal(number)
|
@@ -96,7 +96,7 @@ module ActiveSupport
|
|
96
96
|
attr_accessor :depth
|
97
97
|
self.depth = 100
|
98
98
|
|
99
|
-
delegate :parse, :
|
99
|
+
delegate :parse, to: :backend
|
100
100
|
|
101
101
|
def backend
|
102
102
|
current_thread_backend || @backend
|
@@ -118,7 +118,7 @@ module ActiveSupport
|
|
118
118
|
|
119
119
|
def to_tag(key, value, options)
|
120
120
|
type_name = options.delete(:type)
|
121
|
-
merged_options = options.merge(:
|
121
|
+
merged_options = options.merge(root: key, skip_instruct: true)
|
122
122
|
|
123
123
|
if value.is_a?(::Method) || value.is_a?(::Proc)
|
124
124
|
if value.arity == 1
|
@@ -136,7 +136,7 @@ module ActiveSupport
|
|
136
136
|
|
137
137
|
key = rename_key(key.to_s, options)
|
138
138
|
|
139
|
-
attributes = options[:skip_types] || type_name.nil? ? {
|
139
|
+
attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
|
140
140
|
attributes[:nil] = true if value.nil?
|
141
141
|
|
142
142
|
encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
|
@@ -159,33 +159,31 @@ module ActiveSupport
|
|
159
159
|
key
|
160
160
|
end
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
def _dasherize(key)
|
165
|
-
# $2 must be a non-greedy regex for this to work
|
166
|
-
left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
|
167
|
-
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
168
|
-
end
|
162
|
+
private
|
169
163
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
::Base64.decode64(bin)
|
175
|
-
else
|
176
|
-
bin
|
164
|
+
def _dasherize(key)
|
165
|
+
# $2 must be a non-greedy regex for this to work
|
166
|
+
left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
|
167
|
+
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
177
168
|
end
|
178
|
-
end
|
179
169
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
170
|
+
# TODO: Add support for other encodings
|
171
|
+
def _parse_binary(bin, entity)
|
172
|
+
case entity["encoding"]
|
173
|
+
when "base64"
|
174
|
+
::Base64.decode64(bin)
|
175
|
+
else
|
176
|
+
bin
|
177
|
+
end
|
178
|
+
end
|
187
179
|
|
188
|
-
|
180
|
+
def _parse_file(file, entity)
|
181
|
+
f = StringIO.new(::Base64.decode64(file))
|
182
|
+
f.extend(FileLike)
|
183
|
+
f.original_filename = entity["name"]
|
184
|
+
f.content_type = entity["content_type"]
|
185
|
+
f
|
186
|
+
end
|
189
187
|
|
190
188
|
def current_thread_backend
|
191
189
|
Thread.current[:xml_mini_backend]
|
@@ -205,5 +203,5 @@ module ActiveSupport
|
|
205
203
|
end
|
206
204
|
end
|
207
205
|
|
208
|
-
XmlMini.backend =
|
206
|
+
XmlMini.backend = "REXML"
|
209
207
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM
|
1
|
+
raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java")
|
2
2
|
|
3
|
-
require
|
3
|
+
require "jruby"
|
4
4
|
include Java
|
5
5
|
|
6
|
-
require
|
6
|
+
require "active_support/core_ext/object/blank"
|
7
7
|
|
8
8
|
java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
|
9
9
|
java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
|
@@ -16,7 +16,7 @@ module ActiveSupport
|
|
16
16
|
module XmlMini_JDOM #:nodoc:
|
17
17
|
extend self
|
18
18
|
|
19
|
-
CONTENT_KEY =
|
19
|
+
CONTENT_KEY = "__content__".freeze
|
20
20
|
|
21
21
|
NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
|
22
22
|
DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
|
@@ -46,136 +46,136 @@ module ActiveSupport
|
|
46
46
|
xml_string_reader = StringReader.new(data)
|
47
47
|
xml_input_source = InputSource.new(xml_string_reader)
|
48
48
|
doc = @dbf.new_document_builder.parse(xml_input_source)
|
49
|
-
merge_element!({CONTENT_KEY =>
|
49
|
+
merge_element!({ CONTENT_KEY => "" }, doc.document_element, XmlMini.depth)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def delete_empty(hash)
|
68
|
-
hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ''
|
69
|
-
end
|
55
|
+
# Convert an XML element and merge into the hash
|
56
|
+
#
|
57
|
+
# hash::
|
58
|
+
# Hash to merge the converted element into.
|
59
|
+
# element::
|
60
|
+
# XML element to merge into hash
|
61
|
+
def merge_element!(hash, element, depth)
|
62
|
+
raise "Document too deep!" if depth == 0
|
63
|
+
delete_empty(hash)
|
64
|
+
merge!(hash, element.tag_name, collapse(element, depth))
|
65
|
+
end
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
# The document element to be collapsed.
|
75
|
-
def collapse(element, depth)
|
76
|
-
hash = get_attributes(element)
|
67
|
+
def delete_empty(hash)
|
68
|
+
hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ""
|
69
|
+
end
|
77
70
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
71
|
+
# Actually converts an XML document element into a data structure.
|
72
|
+
#
|
73
|
+
# element::
|
74
|
+
# The document element to be collapsed.
|
75
|
+
def collapse(element, depth)
|
76
|
+
hash = get_attributes(element)
|
77
|
+
|
78
|
+
child_nodes = element.child_nodes
|
79
|
+
if child_nodes.length > 0
|
80
|
+
(0...child_nodes.length).each do |i|
|
81
|
+
child = child_nodes.item(i)
|
82
|
+
merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
|
83
|
+
end
|
84
|
+
merge_texts!(hash, element) unless empty_content?(element)
|
85
|
+
hash
|
86
|
+
else
|
87
|
+
merge_texts!(hash, element)
|
83
88
|
end
|
84
|
-
merge_texts!(hash, element) unless empty_content?(element)
|
85
|
-
hash
|
86
|
-
else
|
87
|
-
merge_texts!(hash, element)
|
88
89
|
end
|
89
|
-
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
91
|
+
# Merge all the texts of an element into the hash
|
92
|
+
#
|
93
|
+
# hash::
|
94
|
+
# Hash to add the converted element to.
|
95
|
+
# element::
|
96
|
+
# XML element whose texts are to me merged into the hash
|
97
|
+
def merge_texts!(hash, element)
|
98
|
+
delete_empty(hash)
|
99
|
+
text_children = texts(element)
|
100
|
+
if text_children.join.empty?
|
101
|
+
hash
|
102
|
+
else
|
103
|
+
# must use value to prevent double-escaping
|
104
|
+
merge!(hash, CONTENT_KEY, text_children.join)
|
105
|
+
end
|
105
106
|
end
|
106
|
-
end
|
107
107
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
108
|
+
# Adds a new key/value pair to an existing Hash. If the key to be added
|
109
|
+
# already exists and the existing value associated with key is not
|
110
|
+
# an Array, it will be wrapped in an Array. Then the new value is
|
111
|
+
# appended to that Array.
|
112
|
+
#
|
113
|
+
# hash::
|
114
|
+
# Hash to add key/value pair to.
|
115
|
+
# key::
|
116
|
+
# Key to be added.
|
117
|
+
# value::
|
118
|
+
# Value to be associated with key.
|
119
|
+
def merge!(hash, key, value)
|
120
|
+
if hash.has_key?(key)
|
121
|
+
if hash[key].instance_of?(Array)
|
122
|
+
hash[key] << value
|
123
|
+
else
|
124
|
+
hash[key] = [hash[key], value]
|
125
|
+
end
|
126
|
+
elsif value.instance_of?(Array)
|
127
|
+
hash[key] = [value]
|
123
128
|
else
|
124
|
-
hash[key] =
|
129
|
+
hash[key] = value
|
125
130
|
end
|
126
|
-
|
127
|
-
hash[key] = [value]
|
128
|
-
else
|
129
|
-
hash[key] = value
|
131
|
+
hash
|
130
132
|
end
|
131
|
-
hash
|
132
|
-
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
134
|
+
# Converts the attributes array of an XML element into a hash.
|
135
|
+
# Returns an empty Hash if node has no attributes.
|
136
|
+
#
|
137
|
+
# element::
|
138
|
+
# XML element to extract attributes from.
|
139
|
+
def get_attributes(element)
|
140
|
+
attribute_hash = {}
|
141
|
+
attributes = element.attributes
|
142
|
+
(0...attributes.length).each do |i|
|
143
|
+
attribute_hash[CONTENT_KEY] ||= ""
|
144
|
+
attribute_hash[attributes.item(i).name] = attributes.item(i).value
|
145
|
+
end
|
146
|
+
attribute_hash
|
145
147
|
end
|
146
|
-
attribute_hash
|
147
|
-
end
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
149
|
+
# Determines if a document element has text content
|
150
|
+
#
|
151
|
+
# element::
|
152
|
+
# XML element to be checked.
|
153
|
+
def texts(element)
|
154
|
+
texts = []
|
155
|
+
child_nodes = element.child_nodes
|
156
|
+
(0...child_nodes.length).each do |i|
|
157
|
+
item = child_nodes.item(i)
|
158
|
+
if item.node_type == Node.TEXT_NODE
|
159
|
+
texts << item.get_data
|
160
|
+
end
|
160
161
|
end
|
162
|
+
texts
|
161
163
|
end
|
162
|
-
texts
|
163
|
-
end
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
165
|
+
# Determines if a document element has text content
|
166
|
+
#
|
167
|
+
# element::
|
168
|
+
# XML element to be checked.
|
169
|
+
def empty_content?(element)
|
170
|
+
text = ""
|
171
|
+
child_nodes = element.child_nodes
|
172
|
+
(0...child_nodes.length).each do |i|
|
173
|
+
item = child_nodes.item(i)
|
174
|
+
if item.node_type == Node.TEXT_NODE
|
175
|
+
text << item.get_data.strip
|
176
|
+
end
|
176
177
|
end
|
178
|
+
text.strip.length == 0
|
177
179
|
end
|
178
|
-
text.strip.length == 0
|
179
|
-
end
|
180
180
|
end
|
181
181
|
end
|