activesupport 5.0.7.2 → 5.1.7
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 +4 -4
- data/CHANGELOG.md +464 -694
- 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 +41 -48
- data/lib/active_support/cache/file_store.rb +11 -20
- data/lib/active_support/cache/mem_cache_store.rb +30 -40
- data/lib/active_support/cache/memory_store.rb +13 -13
- data/lib/active_support/cache/null_store.rb +4 -4
- data/lib/active_support/cache/strategy/local_cache.rb +13 -22
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +4 -5
- data/lib/active_support/callbacks.rb +649 -584
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- 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 +1 -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 +20 -10
- data/lib/active_support/core_ext/date_time/compatibility.rb +2 -2
- 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 +23 -12
- 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 +6 -6
- 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/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 +85 -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 +34 -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 +8 -5
- data/lib/active_support/core_ext/object/try.rb +1 -1
- data/lib/active_support/core_ext/object/with_options.rb +12 -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 +46 -29
- data/lib/active_support/core_ext/time/conversions.rb +15 -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 -46
- data/lib/active_support/dependencies/interlock.rb +1 -1
- data/lib/active_support/deprecation.rb +9 -8
- data/lib/active_support/deprecation/behaviors.rb +3 -3
- data/lib/active_support/deprecation/constant_accessor.rb +50 -0
- data/lib/active_support/deprecation/instance_delegator.rb +2 -2
- data/lib/active_support/deprecation/method_wrappers.rb +10 -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 +221 -28
- 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 -55
- 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 +2 -2
- data/lib/active_support/gzip.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +40 -28
- data/lib/active_support/i18n.rb +5 -5
- data/lib/active_support/i18n_railtie.rb +14 -9
- 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 +52 -51
- 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 +2 -2
- data/lib/active_support/log_subscriber.rb +9 -7
- 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 +77 -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 +7 -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 +5 -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 +8 -10
- 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 +12 -32
- data/lib/active_support/number_helper/rounding_helper.rb +64 -0
- 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 +6 -6
- 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 +2 -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 +15 -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 -11
- data/lib/active_support/time.rb +12 -12
- data/lib/active_support/time_with_zone.rb +16 -14
- data/lib/active_support/values/time_zone.rb +100 -31
- 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 +12 -11
- data/lib/active_support/xml_mini/libxmlsax.rb +13 -14
- data/lib/active_support/xml_mini/nokogiri.rb +10 -10
- data/lib/active_support/xml_mini/nokogirisax.rb +12 -13
- data/lib/active_support/xml_mini/rexml.rb +9 -9
- metadata +8 -9
- 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
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/inflector/methods"
|
2
|
+
require "active_support/inflector/transliterate"
|
3
3
|
|
4
4
|
# String inflections define new methods on the String class to transform names for different purposes.
|
5
5
|
# For instance, you can figure out the name of a table from the name of a class.
|
@@ -31,7 +31,7 @@ class String
|
|
31
31
|
def pluralize(count = nil, locale = :en)
|
32
32
|
locale = count if count.is_a?(Symbol)
|
33
33
|
if count == 1
|
34
|
-
|
34
|
+
dup
|
35
35
|
else
|
36
36
|
ActiveSupport::Inflector.pluralize(self, locale)
|
37
37
|
end
|
@@ -67,7 +67,7 @@ class String
|
|
67
67
|
end
|
68
68
|
|
69
69
|
# +safe_constantize+ tries to find a declared constant with the name specified
|
70
|
-
# in the string. It returns nil when the name is not in CamelCase
|
70
|
+
# in the string. It returns +nil+ when the name is not in CamelCase
|
71
71
|
# or is not initialized. See ActiveSupport::Inflector.safe_constantize
|
72
72
|
#
|
73
73
|
# 'Module'.safe_constantize # => Module
|
@@ -128,10 +128,10 @@ class String
|
|
128
128
|
|
129
129
|
# Removes the module part from the constant expression in the string.
|
130
130
|
#
|
131
|
-
# '
|
132
|
-
# 'Inflections'.demodulize
|
133
|
-
# '::Inflections'.demodulize
|
134
|
-
# ''.demodulize
|
131
|
+
# 'ActiveSupport::Inflector::Inflections'.demodulize # => "Inflections"
|
132
|
+
# 'Inflections'.demodulize # => "Inflections"
|
133
|
+
# '::Inflections'.demodulize # => "Inflections"
|
134
|
+
# ''.demodulize # => ''
|
135
135
|
#
|
136
136
|
# See also +deconstantize+.
|
137
137
|
def demodulize
|
@@ -164,7 +164,7 @@ class String
|
|
164
164
|
#
|
165
165
|
# <%= link_to(@person.name, person_path) %>
|
166
166
|
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
167
|
-
#
|
167
|
+
#
|
168
168
|
# To preserve the case of the characters in a string, use the `preserve_case` argument.
|
169
169
|
#
|
170
170
|
# class Person
|
@@ -178,11 +178,7 @@ class String
|
|
178
178
|
#
|
179
179
|
# <%= link_to(@person.name, person_path) %>
|
180
180
|
# # => <a href="/person/1-Donald-E-Knuth">Donald E. Knuth</a>
|
181
|
-
def parameterize(
|
182
|
-
unless sep == :unused
|
183
|
-
ActiveSupport::Deprecation.warn("Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '#{sep}'` instead.")
|
184
|
-
separator = sep
|
185
|
-
end
|
181
|
+
def parameterize(separator: "-", preserve_case: false)
|
186
182
|
ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case)
|
187
183
|
end
|
188
184
|
|
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "erb"
|
2
|
+
require "active_support/core_ext/kernel/singleton_class"
|
3
|
+
require "active_support/multibyte/unicode"
|
3
4
|
|
4
5
|
class ERB
|
5
6
|
module Util
|
6
|
-
HTML_ESCAPE = {
|
7
|
-
JSON_ESCAPE = {
|
7
|
+
HTML_ESCAPE = { "&" => "&", ">" => ">", "<" => "<", '"' => """, "'" => "'" }
|
8
|
+
JSON_ESCAPE = { "&" => '\u0026', ">" => '\u003e', "<" => '\u003c', "\u2028" => '\u2028', "\u2029" => '\u2029' }
|
8
9
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+)|(#[xX][\dA-Fa-f]+));)/
|
9
10
|
JSON_ESCAPE_REGEXP = /[\u2028\u2029&><]/u
|
10
11
|
|
@@ -144,25 +145,23 @@ module ActiveSupport #:nodoc:
|
|
144
145
|
# Raised when <tt>ActiveSupport::SafeBuffer#safe_concat</tt> is called on unsafe buffers.
|
145
146
|
class SafeConcatError < StandardError
|
146
147
|
def initialize
|
147
|
-
super
|
148
|
+
super "Could not concatenate to the buffer because it is not html safe."
|
148
149
|
end
|
149
150
|
end
|
150
151
|
|
151
152
|
def [](*args)
|
152
153
|
if args.size < 2
|
153
154
|
super
|
154
|
-
|
155
|
-
|
156
|
-
new_safe_buffer = super
|
157
|
-
|
158
|
-
if new_safe_buffer
|
159
|
-
new_safe_buffer.instance_variable_set :@html_safe, true
|
160
|
-
end
|
155
|
+
elsif html_safe?
|
156
|
+
new_safe_buffer = super
|
161
157
|
|
162
|
-
|
163
|
-
|
164
|
-
to_str[*args]
|
158
|
+
if new_safe_buffer
|
159
|
+
new_safe_buffer.instance_variable_set :@html_safe, true
|
165
160
|
end
|
161
|
+
|
162
|
+
new_safe_buffer
|
163
|
+
else
|
164
|
+
to_str[*args]
|
166
165
|
end
|
167
166
|
end
|
168
167
|
|
@@ -171,7 +170,7 @@ module ActiveSupport #:nodoc:
|
|
171
170
|
original_concat(value)
|
172
171
|
end
|
173
172
|
|
174
|
-
def initialize(str =
|
173
|
+
def initialize(str = "")
|
175
174
|
@html_safe = true
|
176
175
|
super
|
177
176
|
end
|
@@ -201,7 +200,7 @@ module ActiveSupport #:nodoc:
|
|
201
200
|
def %(args)
|
202
201
|
case args
|
203
202
|
when Hash
|
204
|
-
escaped_args = Hash[args.map { |k,arg| [k, html_escape_interpolated_argument(arg)] }]
|
203
|
+
escaped_args = Hash[args.map { |k, arg| [k, html_escape_interpolated_argument(arg)] }]
|
205
204
|
else
|
206
205
|
escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) }
|
207
206
|
end
|
@@ -242,9 +241,9 @@ module ActiveSupport #:nodoc:
|
|
242
241
|
|
243
242
|
private
|
244
243
|
|
245
|
-
|
246
|
-
|
247
|
-
|
244
|
+
def html_escape_interpolated_argument(arg)
|
245
|
+
(!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
|
246
|
+
end
|
248
247
|
end
|
249
248
|
end
|
250
249
|
|
@@ -18,6 +18,6 @@ class String
|
|
18
18
|
# Technically, it looks for the least indented non-empty line
|
19
19
|
# in the whole string, and removes that amount of leading whitespace.
|
20
20
|
def strip_heredoc
|
21
|
-
gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/,
|
21
|
+
gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".freeze)
|
22
22
|
end
|
23
23
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/core_ext/string/conversions"
|
2
|
+
require "active_support/core_ext/time/zones"
|
3
3
|
|
4
4
|
class String
|
5
5
|
# Converts String to a TimeWithZone in the current zone if Time.zone or Time.zone_default
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "active_support/core_ext/time/acts_like"
|
2
|
+
require "active_support/core_ext/time/calculations"
|
3
|
+
require "active_support/core_ext/time/compatibility"
|
4
|
+
require "active_support/core_ext/time/conversions"
|
5
|
+
require "active_support/core_ext/time/zones"
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "active_support/duration"
|
2
|
+
require "active_support/core_ext/time/conversions"
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
require "active_support/core_ext/time/zones"
|
5
|
+
require "active_support/core_ext/date_and_time/calculations"
|
6
|
+
require "active_support/core_ext/date/calculations"
|
7
7
|
|
8
8
|
class Time
|
9
9
|
include DateAndTime::Calculations
|
@@ -53,6 +53,29 @@ class Time
|
|
53
53
|
end
|
54
54
|
alias_method :at_without_coercion, :at
|
55
55
|
alias_method :at, :at_with_coercion
|
56
|
+
|
57
|
+
# Creates a +Time+ instance from an RFC 3339 string.
|
58
|
+
#
|
59
|
+
# Time.rfc3339('1999-12-31T14:00:00-10:00') # => 2000-01-01 00:00:00 -1000
|
60
|
+
#
|
61
|
+
# If the time or offset components are missing then an +ArgumentError+ will be raised.
|
62
|
+
#
|
63
|
+
# Time.rfc3339('1999-12-31') # => ArgumentError: invalid date
|
64
|
+
def rfc3339(str)
|
65
|
+
parts = Date._rfc3339(str)
|
66
|
+
|
67
|
+
raise ArgumentError, "invalid date" if parts.empty?
|
68
|
+
|
69
|
+
Time.new(
|
70
|
+
parts.fetch(:year),
|
71
|
+
parts.fetch(:mon),
|
72
|
+
parts.fetch(:mday),
|
73
|
+
parts.fetch(:hour),
|
74
|
+
parts.fetch(:min),
|
75
|
+
parts.fetch(:sec) + parts.fetch(:sec_fraction, 0),
|
76
|
+
parts.fetch(:offset)
|
77
|
+
)
|
78
|
+
end
|
56
79
|
end
|
57
80
|
|
58
81
|
# Returns the number of seconds since 00:00:00.
|
@@ -61,7 +84,7 @@ class Time
|
|
61
84
|
# Time.new(2012, 8, 29, 12, 34, 56).seconds_since_midnight # => 45296.0
|
62
85
|
# Time.new(2012, 8, 29, 23, 59, 59).seconds_since_midnight # => 86399.0
|
63
86
|
def seconds_since_midnight
|
64
|
-
to_i - change(:
|
87
|
+
to_i - change(hour: 0).to_i + (usec / 1.0e+6)
|
65
88
|
end
|
66
89
|
|
67
90
|
# Returns the number of seconds until 23:59:59.
|
@@ -104,7 +127,7 @@ class Time
|
|
104
127
|
raise ArgumentError, "Can't change both :nsec and :usec at the same time: #{options.inspect}" if options[:usec]
|
105
128
|
new_usec = Rational(new_nsec, 1000)
|
106
129
|
else
|
107
|
-
new_usec
|
130
|
+
new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
|
108
131
|
end
|
109
132
|
|
110
133
|
if utc?
|
@@ -112,7 +135,7 @@ class Time
|
|
112
135
|
elsif zone
|
113
136
|
::Time.local(new_year, new_month, new_day, new_hour, new_min, new_sec, new_usec)
|
114
137
|
else
|
115
|
-
raise ArgumentError,
|
138
|
+
raise ArgumentError, "argument out of range" if new_usec >= 1000000
|
116
139
|
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec + (new_usec.to_r / 1000000), utc_offset)
|
117
140
|
end
|
118
141
|
end
|
@@ -141,7 +164,7 @@ class Time
|
|
141
164
|
|
142
165
|
d = to_date.advance(options)
|
143
166
|
d = d.gregorian if d.julian?
|
144
|
-
time_advanced_by_date = change(:
|
167
|
+
time_advanced_by_date = change(year: d.year, month: d.month, day: d.day)
|
145
168
|
seconds_to_advance = \
|
146
169
|
options.fetch(:seconds, 0) +
|
147
170
|
options.fetch(:minutes, 0) * 60 +
|
@@ -169,7 +192,7 @@ class Time
|
|
169
192
|
|
170
193
|
# Returns a new Time representing the start of the day (0:00)
|
171
194
|
def beginning_of_day
|
172
|
-
change(:
|
195
|
+
change(hour: 0)
|
173
196
|
end
|
174
197
|
alias :midnight :beginning_of_day
|
175
198
|
alias :at_midnight :beginning_of_day
|
@@ -177,7 +200,7 @@ class Time
|
|
177
200
|
|
178
201
|
# Returns a new Time representing the middle of the day (12:00)
|
179
202
|
def middle_of_day
|
180
|
-
change(:
|
203
|
+
change(hour: 12)
|
181
204
|
end
|
182
205
|
alias :midday :middle_of_day
|
183
206
|
alias :noon :middle_of_day
|
@@ -188,50 +211,45 @@ class Time
|
|
188
211
|
# Returns a new Time representing the end of the day, 23:59:59.999999
|
189
212
|
def end_of_day
|
190
213
|
change(
|
191
|
-
:
|
192
|
-
:
|
193
|
-
:
|
194
|
-
:
|
214
|
+
hour: 23,
|
215
|
+
min: 59,
|
216
|
+
sec: 59,
|
217
|
+
usec: Rational(999999999, 1000)
|
195
218
|
)
|
196
219
|
end
|
197
220
|
alias :at_end_of_day :end_of_day
|
198
221
|
|
199
222
|
# Returns a new Time representing the start of the hour (x:00)
|
200
223
|
def beginning_of_hour
|
201
|
-
change(:
|
224
|
+
change(min: 0)
|
202
225
|
end
|
203
226
|
alias :at_beginning_of_hour :beginning_of_hour
|
204
227
|
|
205
228
|
# Returns a new Time representing the end of the hour, x:59:59.999999
|
206
229
|
def end_of_hour
|
207
230
|
change(
|
208
|
-
:
|
209
|
-
:
|
210
|
-
:
|
231
|
+
min: 59,
|
232
|
+
sec: 59,
|
233
|
+
usec: Rational(999999999, 1000)
|
211
234
|
)
|
212
235
|
end
|
213
236
|
alias :at_end_of_hour :end_of_hour
|
214
237
|
|
215
238
|
# Returns a new Time representing the start of the minute (x:xx:00)
|
216
239
|
def beginning_of_minute
|
217
|
-
change(:
|
240
|
+
change(sec: 0)
|
218
241
|
end
|
219
242
|
alias :at_beginning_of_minute :beginning_of_minute
|
220
243
|
|
221
244
|
# Returns a new Time representing the end of the minute, x:xx:59.999999
|
222
245
|
def end_of_minute
|
223
246
|
change(
|
224
|
-
:
|
225
|
-
:
|
247
|
+
sec: 59,
|
248
|
+
usec: Rational(999999999, 1000)
|
226
249
|
)
|
227
250
|
end
|
228
251
|
alias :at_end_of_minute :end_of_minute
|
229
252
|
|
230
|
-
# Returns a Range representing the whole day of the current time.
|
231
|
-
def all_day
|
232
|
-
beginning_of_day..end_of_day
|
233
|
-
end
|
234
|
-
|
235
253
|
def plus_with_duration(other) #:nodoc:
|
236
254
|
if ActiveSupport::Duration === other
|
237
255
|
other.since(self)
|
@@ -286,5 +304,4 @@ class Time
|
|
286
304
|
end
|
287
305
|
alias_method :eql_without_coercion, :eql?
|
288
306
|
alias_method :eql?, :eql_with_coercion
|
289
|
-
|
290
307
|
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_support/inflector/methods"
|
2
|
+
require "active_support/values/time_zone"
|
3
3
|
|
4
4
|
class Time
|
5
5
|
DATE_FORMATS = {
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
6
|
+
db: "%Y-%m-%d %H:%M:%S",
|
7
|
+
number: "%Y%m%d%H%M%S",
|
8
|
+
nsec: "%Y%m%d%H%M%S%9N",
|
9
|
+
usec: "%Y%m%d%H%M%S%6N",
|
10
|
+
time: "%H:%M",
|
11
|
+
short: "%d %b %H:%M",
|
12
|
+
long: "%B %d, %Y %H:%M",
|
13
|
+
long_ordinal: lambda { |time|
|
14
14
|
day_format = ActiveSupport::Inflector.ordinalize(time.day)
|
15
15
|
time.strftime("%B #{day_format}, %Y %H:%M")
|
16
16
|
},
|
17
|
-
:
|
17
|
+
rfc822: lambda { |time|
|
18
18
|
offset_format = time.formatted_offset(false)
|
19
19
|
time.strftime("%a, %d %b %Y %H:%M:%S #{offset_format}")
|
20
20
|
},
|
21
|
-
:
|
21
|
+
iso8601: lambda { |time| time.iso8601 }
|
22
22
|
}
|
23
23
|
|
24
24
|
# Converts to a formatted string. See DATE_FORMATS for built-in formats.
|
@@ -64,4 +64,7 @@ class Time
|
|
64
64
|
def formatted_offset(colon = true, alternate_utc_string = nil)
|
65
65
|
utc? && alternate_utc_string || ActiveSupport::TimeZone.seconds_to_utc_offset(utc_offset, colon)
|
66
66
|
end
|
67
|
+
|
68
|
+
# Aliased to +xmlschema+ for compatibility with +DateTime+
|
69
|
+
alias_method :rfc3339, :xmlschema
|
67
70
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
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"
|
4
4
|
|
5
5
|
class Time
|
6
6
|
include DateAndTime::Zones
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "uri"
|
2
2
|
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
|
3
3
|
parser = URI::Parser.new
|
4
4
|
|
@@ -10,7 +10,7 @@ unless str == parser.unescape(parser.escape(str))
|
|
10
10
|
# YK: My initial experiments say yes, but let's be sure please
|
11
11
|
enc = str.encoding
|
12
12
|
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
13
|
-
str.gsub(escaped) { |match| [match[1, 2].hex].pack(
|
13
|
+
str.gsub(escaped) { |match| [match[1, 2].hex].pack("C") }.force_encoding(enc)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require 'active_support/core_ext/string/starts_ends_with'
|
1
|
+
require "set"
|
2
|
+
require "thread"
|
3
|
+
require "concurrent/map"
|
4
|
+
require "pathname"
|
5
|
+
require "active_support/core_ext/module/aliasing"
|
6
|
+
require "active_support/core_ext/module/attribute_accessors"
|
7
|
+
require "active_support/core_ext/module/introspection"
|
8
|
+
require "active_support/core_ext/module/anonymous"
|
9
|
+
require "active_support/core_ext/object/blank"
|
10
|
+
require "active_support/core_ext/kernel/reporting"
|
11
|
+
require "active_support/core_ext/load_error"
|
12
|
+
require "active_support/core_ext/name_error"
|
13
|
+
require "active_support/core_ext/string/starts_ends_with"
|
15
14
|
require "active_support/dependencies/interlock"
|
16
|
-
require
|
15
|
+
require "active_support/inflector"
|
17
16
|
|
18
17
|
module ActiveSupport #:nodoc:
|
19
18
|
module Dependencies #:nodoc:
|
@@ -64,7 +63,7 @@ module ActiveSupport #:nodoc:
|
|
64
63
|
|
65
64
|
# Should we load files or require them?
|
66
65
|
mattr_accessor :mechanism
|
67
|
-
self.mechanism = ENV[
|
66
|
+
self.mechanism = ENV["NO_RELOAD"] ? :require : :load
|
68
67
|
|
69
68
|
# The set of directories from which we may automatically load files. Files
|
70
69
|
# under these directories will be reloaded on each request in development mode,
|
@@ -108,7 +107,7 @@ module ActiveSupport #:nodoc:
|
|
108
107
|
|
109
108
|
def initialize
|
110
109
|
@watching = []
|
111
|
-
@stack = Hash.new { |h,k| h[k] = [] }
|
110
|
+
@stack = Hash.new { |h, k| h[k] = [] }
|
112
111
|
end
|
113
112
|
|
114
113
|
def each(&block)
|
@@ -170,9 +169,9 @@ module ActiveSupport #:nodoc:
|
|
170
169
|
end
|
171
170
|
|
172
171
|
private
|
173
|
-
|
174
|
-
|
175
|
-
|
172
|
+
def pop_modules(modules)
|
173
|
+
modules.each { |mod| @stack[mod].pop }
|
174
|
+
end
|
176
175
|
end
|
177
176
|
|
178
177
|
# An internal stack used to record which constants are loaded by any block.
|
@@ -243,7 +242,7 @@ module ActiveSupport #:nodoc:
|
|
243
242
|
# resolution deterministic for constants with the same relative name in
|
244
243
|
# different namespaces whose evaluation would depend on load order
|
245
244
|
# otherwise.
|
246
|
-
def require_dependency(file_name, message = "No such file to load -- %s")
|
245
|
+
def require_dependency(file_name, message = "No such file to load -- %s.rb")
|
247
246
|
file_name = file_name.to_path if file_name.respond_to?(:to_path)
|
248
247
|
unless file_name.is_a?(String)
|
249
248
|
raise ArgumentError, "the file name must either be a String or implement #to_path -- you passed #{file_name.inspect}"
|
@@ -282,17 +281,17 @@ module ActiveSupport #:nodoc:
|
|
282
281
|
|
283
282
|
private
|
284
283
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
284
|
+
def load(file, wrap = false)
|
285
|
+
result = false
|
286
|
+
load_dependency(file) { result = super }
|
287
|
+
result
|
288
|
+
end
|
290
289
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
290
|
+
def require(file)
|
291
|
+
result = false
|
292
|
+
load_dependency(file) { result = super }
|
293
|
+
result
|
294
|
+
end
|
296
295
|
end
|
297
296
|
|
298
297
|
# Exception file-blaming.
|
@@ -371,7 +370,7 @@ module ActiveSupport #:nodoc:
|
|
371
370
|
load_args = ["#{file_name}.rb"]
|
372
371
|
load_args << const_path unless const_path.nil?
|
373
372
|
|
374
|
-
if !warnings_on_first_load
|
373
|
+
if !warnings_on_first_load || history.include?(expanded)
|
375
374
|
result = load_file(*load_args)
|
376
375
|
else
|
377
376
|
enable_warnings { result = load_file(*load_args) }
|
@@ -504,7 +503,7 @@ module ActiveSupport #:nodoc:
|
|
504
503
|
|
505
504
|
if file_path
|
506
505
|
expanded = File.expand_path(file_path)
|
507
|
-
expanded.sub!(/\.rb\z/,
|
506
|
+
expanded.sub!(/\.rb\z/, "".freeze)
|
508
507
|
|
509
508
|
if loading.include?(expanded)
|
510
509
|
raise "Circular dependency detected while autoloading constant #{qualified_name}"
|
@@ -548,7 +547,7 @@ module ActiveSupport #:nodoc:
|
|
548
547
|
end
|
549
548
|
|
550
549
|
name_error = NameError.new("uninitialized constant #{qualified_name}", const_name)
|
551
|
-
name_error.set_backtrace(caller.reject {|l| l.starts_with? __FILE__ })
|
550
|
+
name_error.set_backtrace(caller.reject { |l| l.starts_with? __FILE__ })
|
552
551
|
raise name_error
|
553
552
|
end
|
554
553
|
|
@@ -592,7 +591,7 @@ module ActiveSupport #:nodoc:
|
|
592
591
|
|
593
592
|
def store(klass)
|
594
593
|
return self unless klass.respond_to?(:name)
|
595
|
-
raise(ArgumentError,
|
594
|
+
raise(ArgumentError, "anonymous classes cannot be cached") if klass.name.empty?
|
596
595
|
@store[klass.name] = klass
|
597
596
|
self
|
598
597
|
end
|
@@ -676,29 +675,29 @@ module ActiveSupport #:nodoc:
|
|
676
675
|
# A module, class, symbol, or string may be provided.
|
677
676
|
def to_constant_name(desc) #:nodoc:
|
678
677
|
case desc
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
678
|
+
when String then desc.sub(/^::/, "")
|
679
|
+
when Symbol then desc.to_s
|
680
|
+
when Module
|
681
|
+
desc.name ||
|
682
|
+
raise(ArgumentError, "Anonymous modules have no name to be referenced by")
|
684
683
|
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
|
685
684
|
end
|
686
685
|
end
|
687
686
|
|
688
687
|
def remove_constant(const) #:nodoc:
|
689
688
|
# Normalize ::Foo, ::Object::Foo, Object::Foo, Object::Object::Foo, etc. as Foo.
|
690
|
-
normalized = const.to_s.sub(/\A::/,
|
691
|
-
normalized.sub!(/\A(Object::)+/,
|
689
|
+
normalized = const.to_s.sub(/\A::/, "")
|
690
|
+
normalized.sub!(/\A(Object::)+/, "")
|
692
691
|
|
693
|
-
constants = normalized.split(
|
692
|
+
constants = normalized.split("::")
|
694
693
|
to_remove = constants.pop
|
695
694
|
|
696
695
|
# Remove the file path from the loaded list.
|
697
696
|
file_path = search_for_file(const.underscore)
|
698
697
|
if file_path
|
699
698
|
expanded = File.expand_path(file_path)
|
700
|
-
expanded.sub!(/\.rb\z/,
|
701
|
-
|
699
|
+
expanded.sub!(/\.rb\z/, "")
|
700
|
+
loaded.delete(expanded)
|
702
701
|
end
|
703
702
|
|
704
703
|
if constants.empty?
|
@@ -711,7 +710,7 @@ module ActiveSupport #:nodoc:
|
|
711
710
|
# here than require the caller to be clever. We check the parent
|
712
711
|
# rather than the very const argument because we do not want to
|
713
712
|
# trigger Kernel#autoloads, see the comment below.
|
714
|
-
parent_name = constants.join(
|
713
|
+
parent_name = constants.join("::")
|
715
714
|
return unless qualified_const_defined?(parent_name)
|
716
715
|
parent = constantize(parent_name)
|
717
716
|
end
|