activesupport 3.1.0 → 5.0.0
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 +7 -0
- data/CHANGELOG.md +798 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +13 -7
- data/lib/active_support/array_inquirer.rb +44 -0
- data/lib/active_support/backtrace_cleaner.rb +38 -34
- data/lib/active_support/benchmarkable.rb +17 -28
- data/lib/active_support/cache/file_store.rb +85 -70
- data/lib/active_support/cache/mem_cache_store.rb +75 -66
- data/lib/active_support/cache/memory_store.rb +31 -23
- data/lib/active_support/cache/null_store.rb +41 -0
- data/lib/active_support/cache/strategy/local_cache.rb +73 -70
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +44 -0
- data/lib/active_support/cache.rb +360 -294
- data/lib/active_support/callbacks.rb +563 -393
- data/lib/active_support/concern.rb +42 -34
- data/lib/active_support/concurrency/latch.rb +19 -0
- data/lib/active_support/concurrency/share_lock.rb +186 -0
- data/lib/active_support/configurable.rb +70 -12
- data/lib/active_support/core_ext/array/access.rb +53 -9
- data/lib/active_support/core_ext/array/conversions.rb +109 -62
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +39 -32
- data/lib/active_support/core_ext/array/inquiry.rb +17 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -0
- data/lib/active_support/core_ext/array/wrap.rb +16 -18
- data/lib/active_support/core_ext/array.rb +2 -2
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -36
- data/lib/active_support/core_ext/class/attribute.rb +47 -34
- data/lib/active_support/core_ext/class/attribute_accessors.rb +4 -79
- data/lib/active_support/core_ext/class/subclasses.rb +12 -7
- data/lib/active_support/core_ext/class.rb +0 -3
- data/lib/active_support/core_ext/date/blank.rb +12 -0
- data/lib/active_support/core_ext/date/calculations.rb +57 -167
- data/lib/active_support/core_ext/date/conversions.rb +31 -42
- data/lib/active_support/core_ext/date/zones.rb +2 -10
- data/lib/active_support/core_ext/date.rb +5 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +335 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +1 -0
- data/lib/active_support/core_ext/date_time/blank.rb +12 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +132 -65
- data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +36 -34
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/digest/uuid.rb +51 -0
- data/lib/active_support/core_ext/enumerable.rb +81 -74
- data/lib/active_support/core_ext/file/atomic.rb +53 -26
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/hash/compact.rb +20 -0
- data/lib/active_support/core_ext/hash/conversions.rb +175 -70
- data/lib/active_support/core_ext/hash/deep_merge.rb +30 -8
- data/lib/active_support/core_ext/hash/except.rb +11 -12
- data/lib/active_support/core_ext/hash/indifferent_access.rb +7 -8
- data/lib/active_support/core_ext/hash/keys.rb +147 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +22 -14
- data/lib/active_support/core_ext/hash/transform_values.rb +29 -0
- data/lib/active_support/core_ext/hash.rb +2 -2
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/multiple.rb +4 -0
- data/lib/active_support/core_ext/integer/time.rb +12 -22
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -2
- data/lib/active_support/core_ext/kernel/concern.rb +12 -0
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -15
- data/lib/active_support/core_ext/kernel/reporting.rb +12 -62
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/kernel.rb +2 -3
- data/lib/active_support/core_ext/load_error.rb +14 -7
- data/lib/active_support/core_ext/marshal.rb +22 -0
- data/lib/active_support/core_ext/module/aliasing.rb +16 -12
- data/lib/active_support/core_ext/module/anonymous.rb +12 -8
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
- data/lib/active_support/core_ext/module/attribute_accessors.rb +165 -13
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
- data/lib/active_support/core_ext/module/concerning.rb +135 -0
- data/lib/active_support/core_ext/module/delegation.rb +141 -68
- data/lib/active_support/core_ext/module/deprecation.rb +17 -3
- data/lib/active_support/core_ext/module/introspection.rb +9 -31
- data/lib/active_support/core_ext/module/method_transplanting.rb +3 -0
- data/lib/active_support/core_ext/module/qualified_const.rb +70 -0
- data/lib/active_support/core_ext/module/reachable.rb +1 -3
- data/lib/active_support/core_ext/module/remove_method.rb +24 -5
- data/lib/active_support/core_ext/module.rb +3 -3
- data/lib/active_support/core_ext/name_error.rb +15 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
- data/lib/active_support/core_ext/numeric/time.rb +31 -36
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +52 -18
- data/lib/active_support/core_ext/object/deep_dup.rb +53 -0
- data/lib/active_support/core_ext/object/duplicable.rb +12 -20
- data/lib/active_support/core_ext/object/inclusion.rb +13 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/json.rb +205 -0
- data/lib/active_support/core_ext/object/to_param.rb +1 -55
- data/lib/active_support/core_ext/object/to_query.rb +66 -9
- data/lib/active_support/core_ext/object/try.rb +124 -33
- data/lib/active_support/core_ext/object/with_options.rb +37 -11
- data/lib/active_support/core_ext/object.rb +2 -1
- data/lib/active_support/core_ext/range/conversions.rb +17 -7
- data/lib/active_support/core_ext/range/each.rb +21 -0
- data/lib/active_support/core_ext/range/include_range.rb +20 -18
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +1 -2
- data/lib/active_support/core_ext/securerandom.rb +23 -0
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/behavior.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +41 -38
- data/lib/active_support/core_ext/string/exclude.rb +6 -1
- data/lib/active_support/core_ext/string/filters.rb +70 -17
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +139 -59
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +46 -65
- data/lib/active_support/core_ext/string/output_safety.rb +153 -56
- data/lib/active_support/core_ext/string/strip.rb +3 -6
- data/lib/active_support/core_ext/string/zones.rb +14 -0
- data/lib/active_support/core_ext/string.rb +2 -3
- data/lib/active_support/core_ext/struct.rb +3 -0
- data/lib/active_support/core_ext/time/calculations.rb +173 -173
- data/lib/active_support/core_ext/time/compatibility.rb +5 -0
- data/lib/active_support/core_ext/time/conversions.rb +33 -29
- data/lib/active_support/core_ext/time/marshal.rb +2 -56
- data/lib/active_support/core_ext/time/zones.rb +57 -32
- data/lib/active_support/core_ext/time.rb +5 -0
- data/lib/active_support/core_ext/uri.rb +13 -19
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/dependencies/interlock.rb +51 -0
- data/lib/active_support/dependencies.rb +315 -265
- data/lib/active_support/deprecation/behaviors.rb +71 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +59 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +82 -14
- data/lib/active_support/deprecation/reporting.rb +61 -14
- data/lib/active_support/deprecation.rb +38 -13
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration/iso8601_parser.rb +122 -0
- data/lib/active_support/duration/iso8601_serializer.rb +51 -0
- data/lib/active_support/duration.rb +85 -14
- data/lib/active_support/evented_file_update_checker.rb +194 -0
- data/lib/active_support/execution_wrapper.rb +117 -0
- data/lib/active_support/executor.rb +6 -0
- data/lib/active_support/file_update_checker.rb +138 -17
- data/lib/active_support/gem_version.rb +15 -0
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +199 -49
- data/lib/active_support/i18n.rb +6 -2
- data/lib/active_support/i18n_railtie.rb +40 -21
- data/lib/active_support/inflections.rb +22 -13
- data/lib/active_support/inflector/inflections.rb +175 -144
- data/lib/active_support/inflector/methods.rb +328 -91
- data/lib/active_support/inflector/transliterate.rb +51 -37
- data/lib/active_support/json/decoding.rb +31 -22
- data/lib/active_support/json/encoding.rb +88 -248
- data/lib/active_support/key_generator.rb +71 -0
- data/lib/active_support/lazy_load_hooks.rb +27 -25
- data/lib/active_support/locale/en.yml +102 -3
- data/lib/active_support/log_subscriber/test_helper.rb +24 -21
- data/lib/active_support/log_subscriber.rb +36 -49
- data/lib/active_support/logger.rb +106 -0
- data/lib/active_support/logger_silence.rb +28 -0
- data/lib/active_support/logger_thread_safe_level.rb +31 -0
- data/lib/active_support/message_encryptor.rb +72 -36
- data/lib/active_support/message_verifier.rb +96 -24
- data/lib/active_support/multibyte/chars.rb +88 -333
- data/lib/active_support/multibyte/unicode.rb +156 -136
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/notifications/fanout.rb +115 -19
- data/lib/active_support/notifications/instrumenter.rb +52 -15
- data/lib/active_support/notifications.rb +168 -33
- data/lib/active_support/number_helper/number_converter.rb +182 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +44 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +28 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +62 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +12 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +92 -0
- data/lib/active_support/number_helper.rb +368 -0
- data/lib/active_support/option_merger.rb +1 -1
- data/lib/active_support/ordered_hash.rb +18 -183
- data/lib/active_support/ordered_options.rb +44 -24
- data/lib/active_support/per_thread_registry.rb +58 -0
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +25 -34
- data/lib/active_support/reloader.rb +129 -0
- data/lib/active_support/rescuable.rb +98 -48
- data/lib/active_support/security_utils.rb +27 -0
- data/lib/active_support/string_inquirer.rb +14 -9
- data/lib/active_support/subscriber.rb +120 -0
- data/lib/active_support/tagged_logging.rb +78 -0
- data/lib/active_support/test_case.rb +69 -17
- data/lib/active_support/testing/assertions.rb +43 -41
- data/lib/active_support/testing/autorun.rb +12 -0
- data/lib/active_support/testing/constant_lookup.rb +50 -0
- data/lib/active_support/testing/declarative.rb +7 -21
- data/lib/active_support/testing/deprecation.rb +14 -33
- data/lib/active_support/testing/file_fixtures.rb +34 -0
- data/lib/active_support/testing/isolation.rb +53 -95
- data/lib/active_support/testing/method_call_assertions.rb +41 -0
- data/lib/active_support/testing/setup_and_teardown.rb +21 -82
- data/lib/active_support/testing/stream.rb +42 -0
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/testing/time_helpers.rb +134 -0
- data/lib/active_support/time.rb +6 -23
- data/lib/active_support/time_with_zone.rb +239 -92
- data/lib/active_support/values/time_zone.rb +236 -160
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +5 -7
- data/lib/active_support/xml_mini/jdom.rb +19 -13
- data/lib/active_support/xml_mini/libxml.rb +3 -4
- data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
- data/lib/active_support/xml_mini/nokogiri.rb +3 -4
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
- data/lib/active_support/xml_mini/rexml.rb +8 -10
- data/lib/active_support/xml_mini.rb +66 -34
- data/lib/active_support.rb +40 -23
- metadata +185 -134
- data/CHANGELOG +0 -1534
- data/lib/active_support/base64.rb +0 -42
- data/lib/active_support/basic_object.rb +0 -21
- data/lib/active_support/buffered_logger.rb +0 -137
- data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
- data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
- data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -178
- data/lib/active_support/core_ext/date/freeze.rb +0 -31
- data/lib/active_support/core_ext/date_time/zones.rb +0 -21
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/hash/deep_dup.rb +0 -11
- data/lib/active_support/core_ext/hash/diff.rb +0 -13
- data/lib/active_support/core_ext/kernel/requires.rb +0 -28
- data/lib/active_support/core_ext/logger.rb +0 -81
- data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -43
- data/lib/active_support/core_ext/object/to_json.rb +0 -19
- data/lib/active_support/core_ext/proc.rb +0 -14
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/cover.rb +0 -3
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string/encoding.rb +0 -11
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/file_watcher.rb +0 -36
- data/lib/active_support/json/variable.rb +0 -9
- data/lib/active_support/memoizable.rb +0 -105
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/secure_random.rb +0 -6
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/pending.rb +0 -52
- data/lib/active_support/testing/performance/jruby.rb +0 -115
- data/lib/active_support/testing/performance/rubinius.rb +0 -113
- data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
- data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
- data/lib/active_support/testing/performance/ruby.rb +0 -152
- data/lib/active_support/testing/performance.rb +0 -317
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -60
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/acts_like'
|
3
|
+
require 'active_support/core_ext/date_and_time/zones'
|
2
4
|
|
3
5
|
class Time
|
6
|
+
include DateAndTime::Zones
|
4
7
|
class << self
|
5
8
|
attr_accessor :zone_default
|
6
9
|
|
@@ -23,21 +26,37 @@ class Time
|
|
23
26
|
# <tt>current_user.time_zone</tt> just needs to return a string identifying the user's preferred time zone:
|
24
27
|
#
|
25
28
|
# class ApplicationController < ActionController::Base
|
26
|
-
#
|
29
|
+
# around_action :set_time_zone
|
27
30
|
#
|
28
31
|
# def set_time_zone
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
32
|
+
# if logged_in?
|
33
|
+
# Time.use_zone(current_user.time_zone) { yield }
|
34
|
+
# else
|
35
|
+
# yield
|
36
|
+
# end
|
34
37
|
# end
|
35
38
|
# end
|
36
39
|
def zone=(time_zone)
|
37
40
|
Thread.current[:time_zone] = find_zone!(time_zone)
|
38
41
|
end
|
39
42
|
|
40
|
-
# Allows override of <tt>Time.zone</tt> locally inside supplied block;
|
43
|
+
# Allows override of <tt>Time.zone</tt> locally inside supplied block;
|
44
|
+
# resets <tt>Time.zone</tt> to existing value when done.
|
45
|
+
#
|
46
|
+
# class ApplicationController < ActionController::Base
|
47
|
+
# around_action :set_time_zone
|
48
|
+
#
|
49
|
+
# private
|
50
|
+
#
|
51
|
+
# def set_time_zone
|
52
|
+
# Time.use_zone(current_user.timezone) { yield }
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# NOTE: This won't affect any <tt>ActiveSupport::TimeWithZone</tt>
|
57
|
+
# objects that have already been created, e.g. any model timestamp
|
58
|
+
# attributes that have been read before the block will remain in
|
59
|
+
# the application's default timezone.
|
41
60
|
def use_zone(time_zone)
|
42
61
|
new_zone = find_zone!(time_zone)
|
43
62
|
begin
|
@@ -48,39 +67,45 @@ class Time
|
|
48
67
|
end
|
49
68
|
end
|
50
69
|
|
51
|
-
# Returns a TimeZone instance
|
70
|
+
# Returns a TimeZone instance matching the time zone provided.
|
71
|
+
# Accepts the time zone in any format supported by <tt>Time.zone=</tt>.
|
72
|
+
# Raises an +ArgumentError+ for invalid time zones.
|
73
|
+
#
|
74
|
+
# Time.find_zone! "America/New_York" # => #<ActiveSupport::TimeZone @name="America/New_York" ...>
|
75
|
+
# Time.find_zone! "EST" # => #<ActiveSupport::TimeZone @name="EST" ...>
|
76
|
+
# Time.find_zone! -5.hours # => #<ActiveSupport::TimeZone @name="Bogota" ...>
|
77
|
+
# Time.find_zone! nil # => nil
|
78
|
+
# Time.find_zone! false # => false
|
79
|
+
# Time.find_zone! "NOT-A-TIMEZONE" # => ArgumentError: Invalid Timezone: NOT-A-TIMEZONE
|
52
80
|
def find_zone!(time_zone)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
81
|
+
if !time_zone || time_zone.is_a?(ActiveSupport::TimeZone)
|
82
|
+
time_zone
|
83
|
+
else
|
84
|
+
# Look up the timezone based on the identifier (unless we've been
|
85
|
+
# passed a TZInfo::Timezone)
|
86
|
+
unless time_zone.respond_to?(:period_for_local)
|
87
|
+
time_zone = ActiveSupport::TimeZone[time_zone] || TZInfo::Timezone.get(time_zone)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone
|
91
|
+
if time_zone.is_a?(ActiveSupport::TimeZone)
|
92
|
+
time_zone
|
93
|
+
else
|
94
|
+
ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone)
|
95
|
+
end
|
57
96
|
end
|
58
|
-
# Return if a TimeZone instance, or wrap in a TimeZone instance if a TZInfo::Timezone
|
59
|
-
time_zone.is_a?(ActiveSupport::TimeZone) ? time_zone : ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone)
|
60
97
|
rescue TZInfo::InvalidTimezoneIdentifier
|
61
98
|
raise ArgumentError, "Invalid Timezone: #{time_zone}"
|
62
99
|
end
|
63
100
|
|
101
|
+
# Returns a TimeZone instance matching the time zone provided.
|
102
|
+
# Accepts the time zone in any format supported by <tt>Time.zone=</tt>.
|
103
|
+
# Returns +nil+ for invalid time zones.
|
104
|
+
#
|
105
|
+
# Time.find_zone "America/New_York" # => #<ActiveSupport::TimeZone @name="America/New_York" ...>
|
106
|
+
# Time.find_zone "NOT-A-TIMEZONE" # => nil
|
64
107
|
def find_zone(time_zone)
|
65
108
|
find_zone!(time_zone) rescue nil
|
66
109
|
end
|
67
110
|
end
|
68
|
-
|
69
|
-
# Returns the simultaneous time in <tt>Time.zone</tt>.
|
70
|
-
#
|
71
|
-
# Time.zone = 'Hawaii' # => 'Hawaii'
|
72
|
-
# Time.utc(2000).in_time_zone # => Fri, 31 Dec 1999 14:00:00 HST -10:00
|
73
|
-
#
|
74
|
-
# This method is similar to Time#localtime, except that it uses <tt>Time.zone</tt> as the local zone
|
75
|
-
# instead of the operating system's time zone.
|
76
|
-
#
|
77
|
-
# You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,
|
78
|
-
# and the conversion will be based on that zone instead of <tt>Time.zone</tt>.
|
79
|
-
#
|
80
|
-
# Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
|
81
|
-
def in_time_zone(zone = ::Time.zone)
|
82
|
-
return self unless zone
|
83
|
-
|
84
|
-
ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.find_zone!(zone))
|
85
|
-
end
|
86
111
|
end
|
@@ -1,22 +1,16 @@
|
|
1
|
-
|
1
|
+
require 'uri'
|
2
|
+
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
|
3
|
+
parser = URI::Parser.new
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
remove_method :unescape
|
13
|
-
def unescape(str, escaped = /%[a-fA-F\d]{2}/)
|
14
|
-
# TODO: Are we actually sure that ASCII == UTF-8?
|
15
|
-
# YK: My initial experiments say yes, but let's be sure please
|
16
|
-
enc = str.encoding
|
17
|
-
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
18
|
-
str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
|
19
|
-
end
|
5
|
+
unless str == parser.unescape(parser.escape(str))
|
6
|
+
URI::Parser.class_eval do
|
7
|
+
remove_method :unescape
|
8
|
+
def unescape(str, escaped = /%[a-fA-F\d]{2}/)
|
9
|
+
# TODO: Are we actually sure that ASCII == UTF-8?
|
10
|
+
# YK: My initial experiments say yes, but let's be sure please
|
11
|
+
enc = str.encoding
|
12
|
+
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
13
|
+
str.gsub(escaped) { |match| [match[1, 2].hex].pack('C') }.force_encoding(enc)
|
20
14
|
end
|
21
15
|
end
|
22
16
|
end
|
@@ -24,7 +18,7 @@ end
|
|
24
18
|
module URI
|
25
19
|
class << self
|
26
20
|
def parser
|
27
|
-
@parser ||= URI
|
21
|
+
@parser ||= URI::Parser.new
|
28
22
|
end
|
29
23
|
end
|
30
24
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
DEPRECATED_FILES = ["#{File.dirname(__FILE__)}/core_ext/struct.rb"]
|
2
|
+
(Dir["#{File.dirname(__FILE__)}/core_ext/*.rb"] - DEPRECATED_FILES).each do |path|
|
3
|
+
require path
|
3
4
|
end
|
@@ -1,50 +1,77 @@
|
|
1
1
|
require "active_support/inflector/methods"
|
2
|
-
require "active_support/lazy_load_hooks"
|
3
2
|
|
4
3
|
module ActiveSupport
|
4
|
+
# Autoload and eager load conveniences for your library.
|
5
|
+
#
|
6
|
+
# This module allows you to define autoloads based on
|
7
|
+
# Rails conventions (i.e. no need to define the path
|
8
|
+
# it is automatically guessed based on the filename)
|
9
|
+
# and also define a set of constants that needs to be
|
10
|
+
# eager loaded:
|
11
|
+
#
|
12
|
+
# module MyLib
|
13
|
+
# extend ActiveSupport::Autoload
|
14
|
+
#
|
15
|
+
# autoload :Model
|
16
|
+
#
|
17
|
+
# eager_autoload do
|
18
|
+
# autoload :Cache
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# Then your library can be eager loaded by simply calling:
|
23
|
+
#
|
24
|
+
# MyLib.eager_load!
|
5
25
|
module Autoload
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
26
|
+
def self.extended(base) # :nodoc:
|
27
|
+
base.class_eval do
|
28
|
+
@_autoloads = {}
|
29
|
+
@_under_path = nil
|
30
|
+
@_at_path = nil
|
31
|
+
@_eager_autoload = false
|
32
|
+
end
|
33
|
+
end
|
10
34
|
|
11
|
-
def autoload(const_name, path =
|
12
|
-
|
13
|
-
|
35
|
+
def autoload(const_name, path = @_at_path)
|
36
|
+
unless path
|
37
|
+
full = [name, @_under_path, const_name.to_s].compact.join("::")
|
38
|
+
path = Inflector.underscore(full)
|
39
|
+
end
|
14
40
|
|
15
|
-
if
|
16
|
-
|
41
|
+
if @_eager_autoload
|
42
|
+
@_autoloads[const_name] = path
|
17
43
|
end
|
18
|
-
|
44
|
+
|
45
|
+
super const_name, path
|
19
46
|
end
|
20
47
|
|
21
48
|
def autoload_under(path)
|
22
|
-
|
49
|
+
@_under_path, old_path = path, @_under_path
|
23
50
|
yield
|
24
51
|
ensure
|
25
|
-
|
52
|
+
@_under_path = old_path
|
26
53
|
end
|
27
54
|
|
28
55
|
def autoload_at(path)
|
29
|
-
|
56
|
+
@_at_path, old_path = path, @_at_path
|
30
57
|
yield
|
31
58
|
ensure
|
32
|
-
|
59
|
+
@_at_path = old_path
|
33
60
|
end
|
34
61
|
|
35
62
|
def eager_autoload
|
36
|
-
old_eager,
|
63
|
+
old_eager, @_eager_autoload = @_eager_autoload, true
|
37
64
|
yield
|
38
65
|
ensure
|
39
|
-
|
66
|
+
@_eager_autoload = old_eager
|
40
67
|
end
|
41
68
|
|
42
|
-
def
|
43
|
-
|
69
|
+
def eager_load!
|
70
|
+
@_autoloads.each_value { |file| require file }
|
44
71
|
end
|
45
72
|
|
46
73
|
def autoloads
|
47
|
-
|
74
|
+
@_autoloads
|
48
75
|
end
|
49
76
|
end
|
50
77
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'active_support/concurrency/share_lock'
|
2
|
+
|
3
|
+
module ActiveSupport #:nodoc:
|
4
|
+
module Dependencies #:nodoc:
|
5
|
+
class Interlock
|
6
|
+
def initialize # :nodoc:
|
7
|
+
@lock = ActiveSupport::Concurrency::ShareLock.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def loading
|
11
|
+
@lock.exclusive(purpose: :load, compatible: [:load], after_compatible: [:load]) do
|
12
|
+
yield
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def unloading
|
17
|
+
@lock.exclusive(purpose: :unload, compatible: [:load, :unload], after_compatible: [:load, :unload]) do
|
18
|
+
yield
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def start_unloading
|
23
|
+
@lock.start_exclusive(purpose: :unload, compatible: [:load, :unload])
|
24
|
+
end
|
25
|
+
|
26
|
+
def done_unloading
|
27
|
+
@lock.stop_exclusive(compatible: [:load, :unload])
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_running
|
31
|
+
@lock.start_sharing
|
32
|
+
end
|
33
|
+
|
34
|
+
def done_running
|
35
|
+
@lock.stop_sharing
|
36
|
+
end
|
37
|
+
|
38
|
+
def running
|
39
|
+
@lock.sharing do
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def permit_concurrent_loads
|
45
|
+
@lock.yield_shares(compatible: [:load]) do
|
46
|
+
yield
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|