activesupport 5.1.7 → 5.2.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 +303 -617
- data/README.rdoc +1 -1
- data/lib/active_support.rb +3 -12
- data/lib/active_support/all.rb +2 -0
- data/lib/active_support/array_inquirer.rb +2 -0
- data/lib/active_support/backtrace_cleaner.rb +2 -0
- data/lib/active_support/benchmarkable.rb +2 -0
- data/lib/active_support/builder.rb +2 -0
- data/lib/active_support/cache.rb +127 -58
- data/lib/active_support/cache/file_store.rb +4 -3
- data/lib/active_support/cache/mem_cache_store.rb +12 -4
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/cache/null_store.rb +2 -0
- data/lib/active_support/cache/redis_cache_store.rb +404 -0
- data/lib/active_support/cache/strategy/local_cache.rb +9 -2
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
- data/lib/active_support/callbacks.rb +26 -37
- data/lib/active_support/concern.rb +3 -1
- data/lib/active_support/concurrency/share_lock.rb +2 -0
- data/lib/active_support/configurable.rb +2 -0
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/core_ext/array.rb +2 -0
- data/lib/active_support/core_ext/array/access.rb +4 -2
- data/lib/active_support/core_ext/array/conversions.rb +2 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +2 -0
- data/lib/active_support/core_ext/array/inquiry.rb +2 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
- data/lib/active_support/core_ext/array/wrap.rb +2 -0
- data/lib/active_support/core_ext/benchmark.rb +2 -0
- data/lib/active_support/core_ext/big_decimal.rb +2 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
- data/lib/active_support/core_ext/class.rb +2 -0
- data/lib/active_support/core_ext/class/attribute.rb +34 -16
- data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
- data/lib/active_support/core_ext/class/subclasses.rb +1 -2
- data/lib/active_support/core_ext/date.rb +2 -0
- data/lib/active_support/core_ext/date/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date/blank.rb +2 -0
- data/lib/active_support/core_ext/date/calculations.rb +2 -0
- data/lib/active_support/core_ext/date/conversions.rb +10 -9
- data/lib/active_support/core_ext/date/zones.rb +2 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +42 -16
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
- data/lib/active_support/core_ext/date_time.rb +2 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date_time/blank.rb +2 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +6 -4
- data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
- data/lib/active_support/core_ext/digest/uuid.rb +3 -1
- data/lib/active_support/core_ext/enumerable.rb +3 -1
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/file/atomic.rb +2 -0
- data/lib/active_support/core_ext/hash.rb +2 -0
- data/lib/active_support/core_ext/hash/compact.rb +2 -0
- data/lib/active_support/core_ext/hash/conversions.rb +2 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
- data/lib/active_support/core_ext/hash/except.rb +2 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
- data/lib/active_support/core_ext/hash/keys.rb +2 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
- data/lib/active_support/core_ext/integer.rb +2 -0
- data/lib/active_support/core_ext/integer/inflections.rb +2 -0
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +7 -14
- data/lib/active_support/core_ext/kernel.rb +2 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +2 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/load_error.rb +2 -7
- data/lib/active_support/core_ext/marshal.rb +2 -0
- data/lib/active_support/core_ext/module.rb +3 -0
- data/lib/active_support/core_ext/module/aliasing.rb +2 -0
- data/lib/active_support/core_ext/module/anonymous.rb +2 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
- data/lib/active_support/core_ext/module/concerning.rb +2 -0
- data/lib/active_support/core_ext/module/delegation.rb +29 -24
- data/lib/active_support/core_ext/module/deprecation.rb +2 -0
- data/lib/active_support/core_ext/module/introspection.rb +2 -0
- data/lib/active_support/core_ext/module/reachable.rb +3 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +5 -23
- data/lib/active_support/core_ext/name_error.rb +2 -0
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
- data/lib/active_support/core_ext/numeric/time.rb +7 -15
- data/lib/active_support/core_ext/object.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +2 -0
- data/lib/active_support/core_ext/object/conversions.rb +2 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
- data/lib/active_support/core_ext/object/duplicable.rb +10 -8
- data/lib/active_support/core_ext/object/inclusion.rb +2 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
- data/lib/active_support/core_ext/object/json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +2 -0
- data/lib/active_support/core_ext/object/to_query.rb +4 -5
- data/lib/active_support/core_ext/object/try.rb +2 -0
- data/lib/active_support/core_ext/object/with_options.rb +3 -1
- data/lib/active_support/core_ext/range.rb +3 -0
- data/lib/active_support/core_ext/range/conversions.rb +9 -1
- data/lib/active_support/core_ext/range/each.rb +5 -1
- data/lib/active_support/core_ext/range/include_range.rb +2 -0
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/regexp.rb +2 -0
- data/lib/active_support/core_ext/securerandom.rb +2 -0
- data/lib/active_support/core_ext/string.rb +2 -0
- data/lib/active_support/core_ext/string/access.rb +2 -0
- data/lib/active_support/core_ext/string/behavior.rb +2 -0
- data/lib/active_support/core_ext/string/conversions.rb +2 -0
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +2 -0
- data/lib/active_support/core_ext/string/indent.rb +2 -0
- data/lib/active_support/core_ext/string/inflections.rb +26 -12
- data/lib/active_support/core_ext/string/inquiry.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +2 -0
- data/lib/active_support/core_ext/string/output_safety.rb +6 -7
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +2 -0
- data/lib/active_support/core_ext/string/zones.rb +2 -0
- data/lib/active_support/core_ext/time.rb +2 -0
- data/lib/active_support/core_ext/time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/time/calculations.rb +23 -15
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +2 -0
- data/lib/active_support/core_ext/time/zones.rb +6 -4
- data/lib/active_support/core_ext/uri.rb +4 -1
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies.rb +15 -25
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +2 -0
- data/lib/active_support/deprecation.rb +4 -2
- data/lib/active_support/deprecation/behaviors.rb +23 -8
- data/lib/active_support/deprecation/constant_accessor.rb +3 -1
- data/lib/active_support/deprecation/instance_delegator.rb +2 -0
- data/lib/active_support/deprecation/method_wrappers.rb +2 -7
- data/lib/active_support/deprecation/proxy_wrappers.rb +4 -1
- data/lib/active_support/deprecation/reporting.rb +4 -2
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/duration.rb +8 -14
- data/lib/active_support/duration/iso8601_parser.rb +4 -2
- data/lib/active_support/duration/iso8601_serializer.rb +4 -2
- data/lib/active_support/encrypted_configuration.rb +48 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +2 -0
- data/lib/active_support/execution_wrapper.rb +2 -0
- data/lib/active_support/executor.rb +2 -0
- data/lib/active_support/file_update_checker.rb +2 -0
- data/lib/active_support/gem_version.rb +5 -3
- data/lib/active_support/gzip.rb +2 -0
- data/lib/active_support/hash_with_indifferent_access.rb +33 -1
- data/lib/active_support/i18n.rb +3 -1
- data/lib/active_support/i18n_railtie.rb +5 -11
- data/lib/active_support/inflections.rb +2 -0
- data/lib/active_support/inflector.rb +2 -0
- data/lib/active_support/inflector/inflections.rb +19 -3
- data/lib/active_support/inflector/methods.rb +40 -23
- data/lib/active_support/inflector/transliterate.rb +17 -8
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/json/decoding.rb +2 -0
- data/lib/active_support/json/encoding.rb +2 -0
- data/lib/active_support/key_generator.rb +3 -1
- data/lib/active_support/lazy_load_hooks.rb +2 -0
- data/lib/active_support/log_subscriber.rb +3 -2
- data/lib/active_support/log_subscriber/test_helper.rb +2 -0
- data/lib/active_support/logger.rb +2 -0
- data/lib/active_support/logger_silence.rb +3 -2
- data/lib/active_support/logger_thread_safe_level.rb +2 -0
- data/lib/active_support/message_encryptor.rb +94 -22
- data/lib/active_support/message_verifier.rb +78 -7
- data/lib/active_support/messages/metadata.rb +71 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte.rb +2 -0
- data/lib/active_support/multibyte/chars.rb +2 -0
- data/lib/active_support/multibyte/unicode.rb +3 -1
- data/lib/active_support/notifications.rb +2 -0
- data/lib/active_support/notifications/fanout.rb +2 -0
- data/lib/active_support/notifications/instrumenter.rb +2 -0
- data/lib/active_support/number_helper.rb +2 -0
- data/lib/active_support/number_helper/number_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
- data/lib/active_support/number_helper/rounding_helper.rb +5 -3
- data/lib/active_support/option_merger.rb +2 -0
- data/lib/active_support/ordered_hash.rb +2 -0
- data/lib/active_support/ordered_options.rb +4 -2
- data/lib/active_support/per_thread_registry.rb +2 -0
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +2 -0
- data/lib/active_support/railtie.rb +27 -8
- data/lib/active_support/reloader.rb +7 -5
- data/lib/active_support/rescuable.rb +3 -2
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +2 -0
- data/lib/active_support/subscriber.rb +2 -0
- data/lib/active_support/tagged_logging.rb +2 -0
- data/lib/active_support/test_case.rb +2 -1
- data/lib/active_support/testing/assertions.rb +6 -4
- data/lib/active_support/testing/autorun.rb +2 -0
- data/lib/active_support/testing/constant_lookup.rb +2 -0
- data/lib/active_support/testing/declarative.rb +2 -0
- data/lib/active_support/testing/deprecation.rb +2 -0
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +5 -5
- data/lib/active_support/testing/method_call_assertions.rb +2 -0
- data/lib/active_support/testing/setup_and_teardown.rb +2 -0
- data/lib/active_support/testing/stream.rb +2 -0
- data/lib/active_support/testing/tagged_logging.rb +2 -0
- data/lib/active_support/testing/time_helpers.rb +31 -2
- data/lib/active_support/time.rb +2 -0
- data/lib/active_support/time_with_zone.rb +38 -0
- data/lib/active_support/values/time_zone.rb +20 -12
- data/lib/active_support/version.rb +2 -0
- data/lib/active_support/xml_mini.rb +2 -0
- data/lib/active_support/xml_mini/jdom.rb +4 -2
- data/lib/active_support/xml_mini/libxml.rb +3 -1
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
- data/lib/active_support/xml_mini/nokogiri.rb +3 -1
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
- data/lib/active_support/xml_mini/rexml.rb +3 -1
- metadata +19 -15
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/duration"
|
2
4
|
require "active_support/core_ext/time/calculations"
|
3
5
|
require "active_support/core_ext/time/acts_like"
|
@@ -5,19 +7,9 @@ require "active_support/core_ext/date/calculations"
|
|
5
7
|
require "active_support/core_ext/date/acts_like"
|
6
8
|
|
7
9
|
class Numeric
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# These methods use Time#advance for precise date calculations when using from_now, ago, etc.
|
11
|
-
# as well as adding or subtracting their results from a Time object. For example:
|
12
|
-
#
|
13
|
-
# # equivalent to Time.current.advance(months: 1)
|
14
|
-
# 1.month.from_now
|
15
|
-
#
|
16
|
-
# # equivalent to Time.current.advance(years: 2)
|
17
|
-
# 2.years.from_now
|
10
|
+
# Returns a Duration instance matching the number of seconds provided.
|
18
11
|
#
|
19
|
-
# #
|
20
|
-
# (4.months + 5.years).from_now
|
12
|
+
# 2.seconds # => 2 seconds
|
21
13
|
def seconds
|
22
14
|
ActiveSupport::Duration.seconds(self)
|
23
15
|
end
|
@@ -64,10 +56,10 @@ class Numeric
|
|
64
56
|
alias :fortnight :fortnights
|
65
57
|
|
66
58
|
# Returns the number of milliseconds equivalent to the seconds provided.
|
67
|
-
# Used with the standard time durations
|
68
|
-
# so we can feed them to JavaScript functions like getTime().
|
59
|
+
# Used with the standard time durations.
|
69
60
|
#
|
70
|
-
# 2.in_milliseconds # =>
|
61
|
+
# 2.in_milliseconds # => 2000
|
62
|
+
# 1.hour.in_milliseconds # => 3600000
|
71
63
|
def in_milliseconds
|
72
64
|
self * 1000
|
73
65
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Object
|
2
4
|
# A duck-type assistant method. For example, Active Support extends Date
|
3
5
|
# to define an <tt>acts_like_date?</tt> method, and extends Time to define
|
@@ -5,6 +7,15 @@ class Object
|
|
5
7
|
# <tt>x.acts_like?(:date)</tt> to do duck-type-safe comparisons, since classes that
|
6
8
|
# we want to act like Time simply need to define an <tt>acts_like_time?</tt> method.
|
7
9
|
def acts_like?(duck)
|
8
|
-
|
10
|
+
case duck
|
11
|
+
when :time
|
12
|
+
respond_to? :acts_like_time?
|
13
|
+
when :date
|
14
|
+
respond_to? :acts_like_date?
|
15
|
+
when :string
|
16
|
+
respond_to? :acts_like_string?
|
17
|
+
else
|
18
|
+
respond_to? :"acts_like_#{duck}?"
|
19
|
+
end
|
9
20
|
end
|
10
21
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
4
|
# Most objects are cloneable, but not all. For example you can't dup methods:
|
3
5
|
#
|
@@ -106,8 +108,8 @@ require "bigdecimal"
|
|
106
108
|
class BigDecimal
|
107
109
|
# BigDecimals are duplicable:
|
108
110
|
#
|
109
|
-
#
|
110
|
-
#
|
111
|
+
# BigDecimal.new("1.2").duplicable? # => true
|
112
|
+
# BigDecimal.new("1.2").dup # => #<BigDecimal:...,'0.12E1',18(18)>
|
111
113
|
def duplicable?
|
112
114
|
true
|
113
115
|
end
|
@@ -128,10 +130,10 @@ class Complex
|
|
128
130
|
Complex(1).dup
|
129
131
|
rescue TypeError
|
130
132
|
|
131
|
-
# Complexes are not duplicable
|
133
|
+
# Complexes are not duplicable:
|
132
134
|
#
|
133
|
-
#
|
134
|
-
#
|
135
|
+
# Complex(1).duplicable? # => false
|
136
|
+
# Complex(1).dup # => TypeError: can't copy Complex
|
135
137
|
def duplicable?
|
136
138
|
false
|
137
139
|
end
|
@@ -143,10 +145,10 @@ class Rational
|
|
143
145
|
Rational(1).dup
|
144
146
|
rescue TypeError
|
145
147
|
|
146
|
-
# Rationals are not duplicable
|
148
|
+
# Rationals are not duplicable:
|
147
149
|
#
|
148
|
-
#
|
149
|
-
#
|
150
|
+
# Rational(1).duplicable? # => false
|
151
|
+
# Rational(1).dup # => TypeError: can't copy Rational
|
150
152
|
def duplicable?
|
151
153
|
false
|
152
154
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Hack to load json gem first so we can overwrite its to_json.
|
2
4
|
require "json"
|
3
5
|
require "bigdecimal"
|
@@ -133,6 +135,12 @@ module Enumerable
|
|
133
135
|
end
|
134
136
|
end
|
135
137
|
|
138
|
+
class IO
|
139
|
+
def as_json(options = nil) #:nodoc:
|
140
|
+
to_s
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
136
144
|
class Range
|
137
145
|
def as_json(options = nil) #:nodoc:
|
138
146
|
to_s
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "cgi"
|
2
4
|
|
3
5
|
class Object
|
@@ -73,14 +75,11 @@ class Hash
|
|
73
75
|
#
|
74
76
|
# This method is also aliased as +to_param+.
|
75
77
|
def to_query(namespace = nil)
|
76
|
-
|
78
|
+
collect do |key, value|
|
77
79
|
unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
|
78
80
|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
79
81
|
end
|
80
|
-
end.compact
|
81
|
-
|
82
|
-
query.sort! unless namespace.to_s.include?("[]")
|
83
|
-
query.join("&")
|
82
|
+
end.compact.sort! * "&"
|
84
83
|
end
|
85
84
|
|
86
85
|
alias_method :to_param, :to_query
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/option_merger"
|
2
4
|
|
3
5
|
class Object
|
@@ -60,7 +62,7 @@ class Object
|
|
60
62
|
#
|
61
63
|
# validates :content, length: { minimum: 50 }, if: -> { content.present? }
|
62
64
|
#
|
63
|
-
# Hence the inherited default for
|
65
|
+
# Hence the inherited default for +if+ key is ignored.
|
64
66
|
#
|
65
67
|
# NOTE: You cannot call class methods implicitly inside of with_options.
|
66
68
|
# You can access these methods using the class name instead:
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/range/conversions"
|
2
4
|
require "active_support/core_ext/range/include_range"
|
5
|
+
require "active_support/core_ext/range/include_time_with_zone"
|
3
6
|
require "active_support/core_ext/range/overlaps"
|
4
7
|
require "active_support/core_ext/range/each"
|
@@ -1,6 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport::RangeWithFormat
|
2
4
|
RANGE_FORMATS = {
|
3
|
-
db:
|
5
|
+
db: -> (start, stop) do
|
6
|
+
case start
|
7
|
+
when String then "BETWEEN '#{start}' AND '#{stop}'"
|
8
|
+
else
|
9
|
+
"BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'"
|
10
|
+
end
|
11
|
+
end
|
4
12
|
}
|
5
13
|
|
6
14
|
# Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
|
1
5
|
module ActiveSupport
|
2
6
|
module EachTimeWithZone #:nodoc:
|
3
7
|
def each(&block)
|
@@ -13,7 +17,7 @@ module ActiveSupport
|
|
13
17
|
private
|
14
18
|
|
15
19
|
def ensure_iteration_allowed
|
16
|
-
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(
|
20
|
+
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(TimeWithZone)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module IncludeTimeWithZone #:nodoc:
|
7
|
+
# Extends the default Range#include? to support ActiveSupport::TimeWithZone.
|
8
|
+
#
|
9
|
+
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
10
|
+
#
|
11
|
+
def include?(value)
|
12
|
+
if first.is_a?(TimeWithZone)
|
13
|
+
cover?(value)
|
14
|
+
elsif last.is_a?(TimeWithZone)
|
15
|
+
cover?(value)
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Range.prepend(ActiveSupport::IncludeTimeWithZone)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/inflector/methods"
|
2
4
|
require "active_support/inflector/transliterate"
|
3
5
|
|
@@ -92,6 +94,8 @@ class String
|
|
92
94
|
ActiveSupport::Inflector.camelize(self, true)
|
93
95
|
when :lower
|
94
96
|
ActiveSupport::Inflector.camelize(self, false)
|
97
|
+
else
|
98
|
+
raise ArgumentError, "Invalid option, use either :upper or :lower."
|
95
99
|
end
|
96
100
|
end
|
97
101
|
alias_method :camelcase, :camelize
|
@@ -100,12 +104,17 @@ class String
|
|
100
104
|
# a nicer looking title. +titleize+ is meant for creating pretty output. It is not
|
101
105
|
# used in the Rails internals.
|
102
106
|
#
|
107
|
+
# The trailing '_id','Id'.. can be kept and capitalized by setting the
|
108
|
+
# optional parameter +keep_id_suffix+ to true.
|
109
|
+
# By default, this parameter is false.
|
110
|
+
#
|
103
111
|
# +titleize+ is also aliased as +titlecase+.
|
104
112
|
#
|
105
|
-
# 'man from the boondocks'.titleize
|
106
|
-
# 'x-men: the last stand'.titleize
|
107
|
-
|
108
|
-
|
113
|
+
# 'man from the boondocks'.titleize # => "Man From The Boondocks"
|
114
|
+
# 'x-men: the last stand'.titleize # => "X Men: The Last Stand"
|
115
|
+
# 'string_ending_with_id'.titleize(keep_id_suffix: true) # => "String Ending With Id"
|
116
|
+
def titleize(keep_id_suffix: false)
|
117
|
+
ActiveSupport::Inflector.titleize(self, keep_id_suffix: keep_id_suffix)
|
109
118
|
end
|
110
119
|
alias_method :titlecase, :titleize
|
111
120
|
|
@@ -165,7 +174,7 @@ class String
|
|
165
174
|
# <%= link_to(@person.name, person_path) %>
|
166
175
|
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
|
167
176
|
#
|
168
|
-
# To preserve the case of the characters in a string, use the
|
177
|
+
# To preserve the case of the characters in a string, use the +preserve_case+ argument.
|
169
178
|
#
|
170
179
|
# class Person
|
171
180
|
# def to_param
|
@@ -202,7 +211,7 @@ class String
|
|
202
211
|
ActiveSupport::Inflector.classify(self)
|
203
212
|
end
|
204
213
|
|
205
|
-
# Capitalizes the first word, turns underscores into spaces, and strips a
|
214
|
+
# Capitalizes the first word, turns underscores into spaces, and (by default)strips a
|
206
215
|
# trailing '_id' if present.
|
207
216
|
# Like +titleize+, this is meant for creating pretty output.
|
208
217
|
#
|
@@ -210,12 +219,17 @@ class String
|
|
210
219
|
# optional parameter +capitalize+ to false.
|
211
220
|
# By default, this parameter is true.
|
212
221
|
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
|
218
|
-
|
222
|
+
# The trailing '_id' can be kept and capitalized by setting the
|
223
|
+
# optional parameter +keep_id_suffix+ to true.
|
224
|
+
# By default, this parameter is false.
|
225
|
+
#
|
226
|
+
# 'employee_salary'.humanize # => "Employee salary"
|
227
|
+
# 'author_id'.humanize # => "Author"
|
228
|
+
# 'author_id'.humanize(capitalize: false) # => "author"
|
229
|
+
# '_id'.humanize # => "Id"
|
230
|
+
# 'author_id'.humanize(keep_id_suffix: true) # => "Author Id"
|
231
|
+
def humanize(capitalize: true, keep_id_suffix: false)
|
232
|
+
ActiveSupport::Inflector.humanize(self, capitalize: capitalize, keep_id_suffix: keep_id_suffix)
|
219
233
|
end
|
220
234
|
|
221
235
|
# Converts just the first character to uppercase.
|