activesupport 4.2.0 → 5.2.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 +5 -5
- data/CHANGELOG.md +366 -232
- data/MIT-LICENSE +2 -2
- data/README.rdoc +4 -5
- data/lib/active_support.rb +17 -7
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +7 -5
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache.rb +271 -177
- data/lib/active_support/cache/file_store.rb +41 -35
- data/lib/active_support/cache/mem_cache_store.rb +97 -88
- data/lib/active_support/cache/memory_store.rb +27 -30
- data/lib/active_support/cache/null_store.rb +7 -8
- data/lib/active_support/cache/redis_cache_store.rb +454 -0
- data/lib/active_support/cache/strategy/local_cache.rb +67 -34
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/callbacks.rb +654 -560
- data/lib/active_support/concern.rb +5 -3
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- data/lib/active_support/concurrency/share_lock.rb +227 -0
- data/lib/active_support/configurable.rb +8 -5
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/core_ext/array.rb +9 -6
- data/lib/active_support/core_ext/array/access.rb +29 -1
- data/lib/active_support/core_ext/array/conversions.rb +22 -18
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +11 -18
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +5 -3
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
- data/lib/active_support/core_ext/class.rb +4 -3
- data/lib/active_support/core_ext/class/attribute.rb +41 -22
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +20 -8
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +14 -0
- data/lib/active_support/core_ext/date/calculations.rb +11 -9
- data/lib/active_support/core_ext/date/conversions.rb +31 -23
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +179 -56
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +12 -12
- data/lib/active_support/core_ext/date_time.rb +7 -4
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +58 -20
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -12
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/enumerable.rb +107 -28
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/hash.rb +11 -9
- data/lib/active_support/core_ext/hash/compact.rb +24 -15
- data/lib/active_support/core_ext/hash/conversions.rb +63 -43
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/except.rb +11 -8
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +33 -27
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +8 -8
- data/lib/active_support/core_ext/hash/transform_values.rb +16 -7
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +11 -33
- data/lib/active_support/core_ext/kernel.rb +6 -5
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +5 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -83
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/load_error.rb +3 -22
- data/lib/active_support/core_ext/marshal.rb +13 -10
- data/lib/active_support/core_ext/module.rb +14 -11
- data/lib/active_support/core_ext/module/aliasing.rb +6 -44
- data/lib/active_support/core_ext/module/anonymous.rb +12 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
- data/lib/active_support/core_ext/module/attribute_accessors.rb +43 -40
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +121 -39
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +9 -9
- data/lib/active_support/core_ext/module/reachable.rb +5 -2
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/name_error.rb +22 -2
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +79 -74
- data/lib/active_support/core_ext/numeric/inquiry.rb +28 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -38
- data/lib/active_support/core_ext/object.rb +14 -13
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +29 -4
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
- data/lib/active_support/core_ext/object/duplicable.rb +98 -45
- data/lib/active_support/core_ext/object/inclusion.rb +5 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +49 -19
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +6 -4
- data/lib/active_support/core_ext/object/try.rb +70 -22
- data/lib/active_support/core_ext/object/with_options.rb +16 -3
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/range/conversions.rb +27 -7
- data/lib/active_support/core_ext/range/each.rb +19 -17
- data/lib/active_support/core_ext/range/include_range.rb +21 -19
- 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 +6 -0
- data/lib/active_support/core_ext/securerandom.rb +25 -0
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/string/access.rb +9 -7
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +8 -5
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +10 -8
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +61 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +15 -7
- data/lib/active_support/core_ext/string/output_safety.rb +35 -35
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +4 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -2
- data/lib/active_support/core_ext/time.rb +7 -5
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +101 -51
- data/lib/active_support/core_ext/time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/time/conversions.rb +20 -13
- data/lib/active_support/core_ext/time/zones.rb +41 -7
- data/lib/active_support/core_ext/uri.rb +5 -4
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies.rb +143 -160
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/deprecation/behaviors.rb +41 -12
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/instance_delegator.rb +17 -2
- data/lib/active_support/deprecation/method_wrappers.rb +54 -21
- data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration.rb +326 -30
- data/lib/active_support/duration/iso8601_parser.rb +125 -0
- data/lib/active_support/duration/iso8601_serializer.rb +55 -0
- data/lib/active_support/encrypted_configuration.rb +49 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +205 -0
- data/lib/active_support/execution_wrapper.rb +128 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +63 -37
- data/lib/active_support/gem_version.rb +4 -2
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +130 -30
- data/lib/active_support/i18n.rb +8 -6
- data/lib/active_support/i18n_railtie.rb +34 -14
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/inflector/inflections.rb +61 -12
- data/lib/active_support/inflector/methods.rb +161 -136
- data/lib/active_support/inflector/transliterate.rb +48 -27
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/json/decoding.rb +16 -13
- data/lib/active_support/json/encoding.rb +15 -57
- data/lib/active_support/key_generator.rb +25 -25
- data/lib/active_support/lazy_load_hooks.rb +50 -20
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber.rb +13 -10
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/logger.rb +54 -3
- data/lib/active_support/logger_silence.rb +12 -7
- data/lib/active_support/logger_thread_safe_level.rb +33 -0
- data/lib/active_support/message_encryptor.rb +173 -51
- data/lib/active_support/message_verifier.rb +150 -17
- 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 +4 -2
- data/lib/active_support/multibyte/chars.rb +37 -24
- data/lib/active_support/multibyte/unicode.rb +100 -96
- data/lib/active_support/notifications.rb +11 -7
- data/lib/active_support/notifications/fanout.rb +10 -8
- data/lib/active_support/notifications/instrumenter.rb +27 -7
- data/lib/active_support/number_helper.rb +94 -68
- data/lib/active_support/number_helper/number_converter.rb +13 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -9
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +9 -3
- data/lib/active_support/number_helper/number_to_human_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +9 -8
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +13 -4
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +23 -56
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/option_merger.rb +3 -1
- data/lib/active_support/ordered_hash.rb +6 -4
- data/lib/active_support/ordered_options.rb +22 -4
- data/lib/active_support/per_thread_registry.rb +13 -6
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +16 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +131 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +17 -6
- data/lib/active_support/string_inquirer.rb +11 -3
- data/lib/active_support/subscriber.rb +15 -14
- data/lib/active_support/tagged_logging.rb +14 -11
- data/lib/active_support/test_case.rb +18 -46
- data/lib/active_support/testing/assertions.rb +137 -20
- data/lib/active_support/testing/autorun.rb +4 -2
- data/lib/active_support/testing/constant_lookup.rb +2 -1
- data/lib/active_support/testing/declarative.rb +3 -1
- data/lib/active_support/testing/deprecation.rb +14 -10
- data/lib/active_support/testing/file_fixtures.rb +36 -0
- data/lib/active_support/testing/isolation.rb +34 -25
- data/lib/active_support/testing/method_call_assertions.rb +43 -0
- data/lib/active_support/testing/setup_and_teardown.rb +12 -3
- data/lib/active_support/testing/stream.rb +44 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +96 -27
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +195 -53
- data/lib/active_support/values/time_zone.rb +200 -61
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini.rb +69 -51
- data/lib/active_support/xml_mini/jdom.rb +116 -113
- data/lib/active_support/xml_mini/libxml.rb +17 -16
- data/lib/active_support/xml_mini/libxmlsax.rb +16 -18
- data/lib/active_support/xml_mini/nokogiri.rb +15 -15
- data/lib/active_support/xml_mini/nokogirisax.rb +15 -16
- data/lib/active_support/xml_mini/rexml.rb +17 -16
- metadata +55 -43
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -14
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
- data/lib/active_support/core_ext/date_time/zones.rb +0 -6
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -11
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/itself.rb +0 -15
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -86
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# Alias of <tt>to_s</tt>.
|
@@ -38,7 +40,7 @@ class Array
|
|
38
40
|
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
39
41
|
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
40
42
|
def to_param
|
41
|
-
collect
|
43
|
+
collect(&:to_param).join "/"
|
42
44
|
end
|
43
45
|
|
44
46
|
# Converts an array into a string suitable for use as a URL query string,
|
@@ -51,7 +53,7 @@ class Array
|
|
51
53
|
if empty?
|
52
54
|
nil.to_query(prefix)
|
53
55
|
else
|
54
|
-
collect { |value| value.to_query(prefix) }.join
|
56
|
+
collect { |value| value.to_query(prefix) }.join "&"
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -77,7 +79,7 @@ class Hash
|
|
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.sort! *
|
82
|
+
end.compact.sort! * "&"
|
81
83
|
end
|
82
84
|
|
83
85
|
alias_method :to_param, :to_query
|
@@ -1,4 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
module Tryable #:nodoc:
|
7
|
+
def try(*a, &b)
|
8
|
+
try!(*a, &b) if a.empty? || respond_to?(a.first)
|
9
|
+
end
|
10
|
+
|
11
|
+
def try!(*a, &b)
|
12
|
+
if a.empty? && block_given?
|
13
|
+
if b.arity == 0
|
14
|
+
instance_eval(&b)
|
15
|
+
else
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
else
|
19
|
+
public_send(*a, &b)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
1
25
|
class Object
|
26
|
+
include ActiveSupport::Tryable
|
27
|
+
|
28
|
+
##
|
29
|
+
# :method: try
|
30
|
+
#
|
31
|
+
# :call-seq:
|
32
|
+
# try(*a, &b)
|
33
|
+
#
|
2
34
|
# Invokes the public method whose name goes as first argument just like
|
3
35
|
# +public_send+ does, except that if the receiver does not respond to it the
|
4
36
|
# call returns +nil+ rather than raising an exception.
|
@@ -21,11 +53,11 @@ class Object
|
|
21
53
|
#
|
22
54
|
# +try+ will also return +nil+ if the receiver does not respond to the method:
|
23
55
|
#
|
24
|
-
# @person.try(:non_existing_method)
|
56
|
+
# @person.try(:non_existing_method) # => nil
|
25
57
|
#
|
26
58
|
# instead of
|
27
59
|
#
|
28
|
-
# @person.non_existing_method if @person.respond_to?(:non_existing_method)
|
60
|
+
# @person.non_existing_method if @person.respond_to?(:non_existing_method) # => nil
|
29
61
|
#
|
30
62
|
# +try+ returns +nil+ when called on +nil+ regardless of whether it responds
|
31
63
|
# to the method:
|
@@ -56,27 +88,40 @@ class Object
|
|
56
88
|
#
|
57
89
|
# Please also note that +try+ is defined on +Object+. Therefore, it won't work
|
58
90
|
# with instances of classes that do not have +Object+ among their ancestors,
|
59
|
-
# like direct subclasses of +BasicObject+.
|
60
|
-
# +SimpleDelegator+ will delegate +try+ to the target instead of calling it on
|
61
|
-
# the delegator itself.
|
62
|
-
def try(*a, &b)
|
63
|
-
try!(*a, &b) if a.empty? || respond_to?(a.first)
|
64
|
-
end
|
91
|
+
# like direct subclasses of +BasicObject+.
|
65
92
|
|
66
|
-
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
93
|
+
##
|
94
|
+
# :method: try!
|
95
|
+
#
|
96
|
+
# :call-seq:
|
97
|
+
# try!(*a, &b)
|
98
|
+
#
|
99
|
+
# Same as #try, but raises a +NoMethodError+ exception if the receiver is
|
100
|
+
# not +nil+ and does not implement the tried method.
|
101
|
+
#
|
102
|
+
# "a".try!(:upcase) # => "A"
|
103
|
+
# nil.try!(:upcase) # => nil
|
104
|
+
# 123.try!(:upcase) # => NoMethodError: undefined method `upcase' for 123:Integer
|
105
|
+
end
|
106
|
+
|
107
|
+
class Delegator
|
108
|
+
include ActiveSupport::Tryable
|
109
|
+
|
110
|
+
##
|
111
|
+
# :method: try
|
112
|
+
#
|
113
|
+
# :call-seq:
|
114
|
+
# try(a*, &b)
|
115
|
+
#
|
116
|
+
# See Object#try
|
117
|
+
|
118
|
+
##
|
119
|
+
# :method: try!
|
120
|
+
#
|
121
|
+
# :call-seq:
|
122
|
+
# try!(a*, &b)
|
123
|
+
#
|
124
|
+
# See Object#try!
|
80
125
|
end
|
81
126
|
|
82
127
|
class NilClass
|
@@ -94,6 +139,9 @@ class NilClass
|
|
94
139
|
nil
|
95
140
|
end
|
96
141
|
|
142
|
+
# Calling +try!+ on +nil+ always returns +nil+.
|
143
|
+
#
|
144
|
+
# nil.try!(:name) # => nil
|
97
145
|
def try!(*args)
|
98
146
|
nil
|
99
147
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/option_merger"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# An elegant way to factor duplication out of options passed to a series of
|
@@ -7,7 +9,7 @@ class Object
|
|
7
9
|
# provided. Each method called on the block variable must take an options
|
8
10
|
# hash as its final argument.
|
9
11
|
#
|
10
|
-
# Without <tt>with_options
|
12
|
+
# Without <tt>with_options</tt>, this code contains duplication:
|
11
13
|
#
|
12
14
|
# class Account < ActiveRecord::Base
|
13
15
|
# has_many :customers, dependent: :destroy
|
@@ -60,7 +62,18 @@ 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.
|
66
|
+
#
|
67
|
+
# NOTE: You cannot call class methods implicitly inside of with_options.
|
68
|
+
# You can access these methods using the class name instead:
|
69
|
+
#
|
70
|
+
# class Phone < ActiveRecord::Base
|
71
|
+
# enum phone_number_type: [home: 0, office: 1, mobile: 2]
|
72
|
+
#
|
73
|
+
# with_options presence: true do
|
74
|
+
# validates :phone_number_type, inclusion: { in: Phone.phone_number_types.keys }
|
75
|
+
# end
|
76
|
+
# end
|
64
77
|
#
|
65
78
|
def with_options(options, &block)
|
66
79
|
option_merger = ActiveSupport::OptionMerger.new(self, options)
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/range/conversions"
|
4
|
+
require "active_support/core_ext/range/include_range"
|
5
|
+
require "active_support/core_ext/range/include_time_with_zone"
|
6
|
+
require "active_support/core_ext/range/overlaps"
|
7
|
+
require "active_support/core_ext/range/each"
|
@@ -1,19 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport::RangeWithFormat
|
2
4
|
RANGE_FORMATS = {
|
3
|
-
:
|
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.
|
15
|
+
#
|
16
|
+
# range = (1..100) # => 1..100
|
7
17
|
#
|
8
|
-
#
|
9
|
-
|
18
|
+
# range.to_s # => "1..100"
|
19
|
+
# range.to_s(:db) # => "BETWEEN '1' AND '100'"
|
20
|
+
#
|
21
|
+
# == Adding your own range formats to to_s
|
22
|
+
# You can add your own formats to the Range::RANGE_FORMATS hash.
|
23
|
+
# Use the format name as the hash key and a Proc instance.
|
24
|
+
#
|
25
|
+
# # config/initializers/range_formats.rb
|
26
|
+
# Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_s(:db)} and #{stop.to_s(:db)}" }
|
27
|
+
def to_s(format = :default)
|
10
28
|
if formatter = RANGE_FORMATS[format]
|
11
29
|
formatter.call(first, last)
|
12
30
|
else
|
13
|
-
|
31
|
+
super()
|
14
32
|
end
|
15
33
|
end
|
16
34
|
|
17
35
|
alias_method :to_default_s, :to_s
|
18
|
-
alias_method :
|
36
|
+
alias_method :to_formatted_s, :to_s
|
19
37
|
end
|
38
|
+
|
39
|
+
Range.prepend(ActiveSupport::RangeWithFormat)
|
@@ -1,23 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "active_support/time_with_zone"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def step_with_time_with_zone(n = 1, &block)
|
12
|
-
ensure_iteration_allowed
|
13
|
-
step_without_time_with_zone(n, &block)
|
14
|
-
end
|
15
|
-
alias_method_chain :step, :time_with_zone
|
5
|
+
module ActiveSupport
|
6
|
+
module EachTimeWithZone #:nodoc:
|
7
|
+
def each(&block)
|
8
|
+
ensure_iteration_allowed
|
9
|
+
super
|
10
|
+
end
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
raise TypeError, "can't iterate from #{first.class}"
|
12
|
+
def step(n = 1, &block)
|
13
|
+
ensure_iteration_allowed
|
14
|
+
super
|
21
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ensure_iteration_allowed
|
20
|
+
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(TimeWithZone)
|
21
|
+
end
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
Range.prepend(ActiveSupport::EachTimeWithZone)
|
@@ -1,23 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
3
|
+
module ActiveSupport
|
4
|
+
module IncludeWithRange #:nodoc:
|
5
|
+
# Extends the default Range#include? to support range comparisons.
|
6
|
+
# (1..5).include?(1..5) # => true
|
7
|
+
# (1..5).include?(2..3) # => true
|
8
|
+
# (1..5).include?(2..6) # => false
|
9
|
+
#
|
10
|
+
# The native Range#include? behavior is untouched.
|
11
|
+
# ('a'..'f').include?('c') # => true
|
12
|
+
# (5..9).include?(11) # => false
|
13
|
+
def include?(value)
|
14
|
+
if value.is_a?(::Range)
|
15
|
+
# 1...10 includes 1..9 but it does not include 1..10.
|
16
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
17
|
+
super(value.first) && value.last.send(operator, last)
|
18
|
+
else
|
19
|
+
super
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
|
-
|
22
|
-
alias_method_chain :include?, :range
|
23
23
|
end
|
24
|
+
|
25
|
+
Range.prepend(ActiveSupport::IncludeWithRange)
|
@@ -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)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
|
5
|
+
module SecureRandom
|
6
|
+
BASE58_ALPHABET = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"]
|
7
|
+
# SecureRandom.base58 generates a random base58 string.
|
8
|
+
#
|
9
|
+
# The argument _n_ specifies the length, of the random string to be generated.
|
10
|
+
#
|
11
|
+
# If _n_ is not specified or is +nil+, 16 is assumed. It may be larger in the future.
|
12
|
+
#
|
13
|
+
# The result may contain alphanumeric characters except 0, O, I and l
|
14
|
+
#
|
15
|
+
# p SecureRandom.base58 # => "4kUgL2pdQMSCQtjE"
|
16
|
+
# p SecureRandom.base58(24) # => "77TMHrHJFvFDwodq8w7Ev2m7"
|
17
|
+
#
|
18
|
+
def self.base58(n = 16)
|
19
|
+
SecureRandom.random_bytes(n).unpack("C*").map do |byte|
|
20
|
+
idx = byte % 64
|
21
|
+
idx = SecureRandom.random_number(58) if idx >= 58
|
22
|
+
BASE58_ALPHABET[idx]
|
23
|
+
end.join
|
24
|
+
end
|
25
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/string/conversions"
|
4
|
+
require "active_support/core_ext/string/filters"
|
5
|
+
require "active_support/core_ext/string/multibyte"
|
6
|
+
require "active_support/core_ext/string/starts_ends_with"
|
7
|
+
require "active_support/core_ext/string/inflections"
|
8
|
+
require "active_support/core_ext/string/access"
|
9
|
+
require "active_support/core_ext/string/behavior"
|
10
|
+
require "active_support/core_ext/string/output_safety"
|
11
|
+
require "active_support/core_ext/string/exclude"
|
12
|
+
require "active_support/core_ext/string/strip"
|
13
|
+
require "active_support/core_ext/string/inquiry"
|
14
|
+
require "active_support/core_ext/string/indent"
|
15
|
+
require "active_support/core_ext/string/zones"
|