activesupport 4.0.12 → 7.0.2.4
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 +249 -501
- data/MIT-LICENSE +2 -2
- data/README.rdoc +10 -5
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +41 -13
- data/lib/active_support/benchmarkable.rb +7 -15
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +96 -74
- data/lib/active_support/cache/mem_cache_store.rb +211 -103
- data/lib/active_support/cache/memory_store.rb +90 -58
- data/lib/active_support/cache/null_store.rb +19 -7
- data/lib/active_support/cache/redis_cache_store.rb +468 -0
- data/lib/active_support/cache/strategy/local_cache.rb +86 -83
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +580 -241
- data/lib/active_support/callbacks.rb +812 -425
- data/lib/active_support/code_generator.rb +65 -0
- data/lib/active_support/concern.rb +103 -14
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +33 -0
- data/lib/active_support/concurrency/share_lock.rb +226 -0
- data/lib/active_support/configurable.rb +21 -19
- data/lib/active_support/configuration_file.rb +51 -0
- data/lib/active_support/core_ext/array/access.rb +47 -1
- data/lib/active_support/core_ext/array/conversions.rb +35 -44
- data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +26 -16
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +10 -7
- data/lib/active_support/core_ext/benchmark.rb +5 -3
- data/lib/active_support/core_ext/big_decimal/conversions.rb +9 -26
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +52 -49
- data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
- data/lib/active_support/core_ext/class/subclasses.rb +25 -26
- data/lib/active_support/core_ext/class.rb +4 -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 +31 -18
- data/lib/active_support/core_ext/date/conversions.rb +43 -32
- data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/date/zones.rb +5 -34
- data/lib/active_support/core_ext/date.rb +7 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +198 -66
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +31 -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 +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +79 -38
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +31 -26
- data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/date_time.rb +8 -4
- data/lib/active_support/core_ext/digest/uuid.rb +79 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +249 -17
- data/lib/active_support/core_ext/file/atomic.rb +41 -32
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/conversions.rb +71 -49
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +14 -5
- data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
- data/lib/active_support/core_ext/hash/keys.rb +39 -56
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +8 -23
- data/lib/active_support/core_ext/hash.rb +10 -8
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +3 -1
- data/lib/active_support/core_ext/integer/time.rb +11 -33
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +9 -78
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +5 -4
- data/lib/active_support/core_ext/load_error.rb +5 -21
- 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 -8
- data/lib/active_support/core_ext/module/attribute_accessors.rb +186 -44
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +157 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +172 -45
- data/lib/active_support/core_ext/module/deprecation.rb +3 -3
- data/lib/active_support/core_ext/module/introspection.rb +23 -38
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +13 -10
- data/lib/active_support/core_ext/name_error.rb +45 -4
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -127
- data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
- data/lib/active_support/core_ext/numeric/time.rb +37 -50
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/object/acts_like.rb +41 -6
- data/lib/active_support/core_ext/object/blank.rb +70 -20
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +19 -10
- data/lib/active_support/core_ext/object/duplicable.rb +17 -47
- data/lib/active_support/core_ext/object/inclusion.rb +18 -15
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +244 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +21 -8
- data/lib/active_support/core_ext/object/try.rb +106 -26
- data/lib/active_support/core_ext/object/with_options.rb +64 -5
- data/lib/active_support/core_ext/object.rb +14 -12
- data/lib/active_support/core_ext/pathname/existence.rb +21 -0
- data/lib/active_support/core_ext/pathname.rb +3 -0
- data/lib/active_support/core_ext/range/compare_range.rb +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +37 -15
- data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/range/each.rb +18 -17
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +7 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/regexp.rb +10 -1
- data/lib/active_support/core_ext/securerandom.rb +45 -0
- data/lib/active_support/core_ext/string/access.rb +42 -51
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +18 -13
- data/lib/active_support/core_ext/string/exclude.rb +5 -3
- data/lib/active_support/core_ext/string/filters.rb +97 -7
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +106 -25
- data/lib/active_support/core_ext/string/inquiry.rb +4 -1
- data/lib/active_support/core_ext/string/multibyte.rb +18 -9
- data/lib/active_support/core_ext/string/output_safety.rb +227 -54
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
- data/lib/active_support/core_ext/string/strip.rb +6 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -1
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +178 -116
- data/lib/active_support/core_ext/time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/time/conversions.rb +37 -25
- data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/time/zones.rb +44 -42
- data/lib/active_support/core_ext/time.rb +8 -5
- data/lib/active_support/core_ext/uri.rb +4 -25
- data/lib/active_support/core_ext.rb +4 -2
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +226 -0
- data/lib/active_support/dependencies/autoload.rb +3 -1
- data/lib/active_support/dependencies/interlock.rb +49 -0
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +71 -696
- data/lib/active_support/deprecation/behaviors.rb +65 -16
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/disallowed.rb +56 -0
- data/lib/active_support/deprecation/instance_delegator.rb +16 -2
- data/lib/active_support/deprecation/method_wrappers.rb +62 -21
- data/lib/active_support/deprecation/proxy_wrappers.rb +82 -31
- data/lib/active_support/deprecation/reporting.rb +81 -18
- data/lib/active_support/deprecation.rb +19 -11
- data/lib/active_support/descendants_tracker.rb +192 -34
- data/lib/active_support/digest.rb +22 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +67 -0
- data/lib/active_support/duration.rb +437 -39
- data/lib/active_support/encrypted_configuration.rb +56 -0
- data/lib/active_support/encrypted_file.rb +117 -0
- data/lib/active_support/environment_inquirer.rb +20 -0
- data/lib/active_support/error_reporter.rb +117 -0
- data/lib/active_support/evented_file_update_checker.rb +170 -0
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +53 -0
- data/lib/active_support/execution_wrapper.rb +151 -0
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +62 -37
- data/lib/active_support/fork_tracker.rb +71 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +207 -54
- data/lib/active_support/html_safe_translation.rb +43 -0
- data/lib/active_support/i18n.rb +10 -6
- data/lib/active_support/i18n_railtie.rb +48 -19
- data/lib/active_support/inflections.rb +19 -12
- data/lib/active_support/inflector/inflections.rb +97 -37
- data/lib/active_support/inflector/methods.rb +192 -157
- data/lib/active_support/inflector/transliterate.rb +83 -33
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/isolated_execution_state.rb +64 -0
- data/lib/active_support/json/decoding.rb +37 -42
- data/lib/active_support/json/encoding.rb +93 -293
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +30 -47
- data/lib/active_support/lazy_load_hooks.rb +54 -21
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +10 -4
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +61 -18
- data/lib/active_support/logger.rb +40 -4
- data/lib/active_support/logger_silence.rb +17 -20
- data/lib/active_support/logger_thread_safe_level.rb +69 -0
- data/lib/active_support/message_encryptor.rb +178 -55
- data/lib/active_support/message_verifier.rb +195 -26
- data/lib/active_support/messages/metadata.rb +80 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotator.rb +57 -0
- data/lib/active_support/multibyte/chars.rb +45 -92
- data/lib/active_support/multibyte/unicode.rb +44 -377
- data/lib/active_support/multibyte.rb +5 -3
- data/lib/active_support/notifications/fanout.rb +177 -44
- data/lib/active_support/notifications/instrumenter.rb +117 -17
- data/lib/active_support/notifications.rb +106 -39
- data/lib/active_support/number_helper/number_converter.rb +181 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +59 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
- data/lib/active_support/number_helper/rounding_helper.rb +46 -0
- data/lib/active_support/number_helper.rb +152 -394
- data/lib/active_support/option_merger.rb +18 -5
- data/lib/active_support/ordered_hash.rb +8 -6
- data/lib/active_support/ordered_options.rb +43 -7
- data/lib/active_support/parameter_filter.rb +138 -0
- data/lib/active_support/per_thread_registry.rb +24 -11
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +10 -11
- data/lib/active_support/railtie.rb +118 -12
- data/lib/active_support/reloader.rb +130 -0
- data/lib/active_support/rescuable.rb +112 -57
- data/lib/active_support/ruby_features.rb +7 -0
- data/lib/active_support/secure_compare_rotator.rb +51 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +11 -4
- data/lib/active_support/subscriber.rb +109 -39
- data/lib/active_support/tagged_logging.rb +54 -17
- data/lib/active_support/test_case.rb +121 -37
- data/lib/active_support/testing/assertions.rb +177 -39
- data/lib/active_support/testing/autorun.rb +5 -3
- data/lib/active_support/testing/constant_lookup.rb +3 -6
- data/lib/active_support/testing/declarative.rb +10 -22
- data/lib/active_support/testing/deprecation.rb +65 -11
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +56 -87
- data/lib/active_support/testing/method_call_assertions.rb +70 -0
- data/lib/active_support/testing/parallelization/server.rb +82 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +55 -0
- data/lib/active_support/testing/parallelize_executor.rb +76 -0
- data/lib/active_support/testing/setup_and_teardown.rb +30 -10
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/tagged_logging.rb +6 -4
- data/lib/active_support/testing/time_helpers.rb +246 -0
- data/lib/active_support/time.rb +13 -13
- data/lib/active_support/time_with_zone.rb +315 -90
- data/lib/active_support/values/time_zone.rb +306 -135
- data/lib/active_support/version.rb +6 -7
- data/lib/active_support/xml_mini/jdom.rb +117 -115
- data/lib/active_support/xml_mini/libxml.rb +22 -21
- data/lib/active_support/xml_mini/libxmlsax.rb +17 -19
- data/lib/active_support/xml_mini/nokogiri.rb +19 -19
- data/lib/active_support/xml_mini/nokogirisax.rb +16 -17
- data/lib/active_support/xml_mini/rexml.rb +25 -17
- data/lib/active_support/xml_mini.rb +67 -56
- data/lib/active_support.rb +58 -3
- metadata +125 -66
- data/lib/active_support/basic_object.rb +0 -11
- data/lib/active_support/buffered_logger.rb +0 -21
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
- data/lib/active_support/core_ext/array/uniq_by.rb +0 -19
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -40
- data/lib/active_support/core_ext/date_time/zones.rb +0 -24
- data/lib/active_support/core_ext/hash/diff.rb +0 -14
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/logger.rb +0 -67
- data/lib/active_support/core_ext/marshal.rb +0 -21
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/module/reachable.rb +0 -8
- data/lib/active_support/core_ext/object/to_json.rb +0 -27
- data/lib/active_support/core_ext/proc.rb +0 -17
- data/lib/active_support/core_ext/range/include_range.rb +0 -23
- data/lib/active_support/core_ext/string/encoding.rb +0 -8
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -79
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
- data/lib/active_support/file_watcher.rb +0 -36
- data/lib/active_support/json/variable.rb +0 -18
- data/lib/active_support/testing/pending.rb +0 -14
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,170 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
# returns the attribute value.
|
8
|
-
#
|
9
|
-
# class Person
|
10
|
-
# cattr_reader :hair_colors
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# Person.class_variable_set("@@hair_colors", [:brown, :black])
|
14
|
-
# Person.hair_colors # => [:brown, :black]
|
15
|
-
# Person.new.hair_colors # => [:brown, :black]
|
16
|
-
#
|
17
|
-
# The attribute name must be a valid method name in Ruby.
|
18
|
-
#
|
19
|
-
# class Person
|
20
|
-
# cattr_reader :"1_Badname "
|
21
|
-
# end
|
22
|
-
# # => NameError: invalid attribute name
|
23
|
-
#
|
24
|
-
# If you want to opt out the instance reader method, you can pass <tt>instance_reader: false</tt>
|
25
|
-
# or <tt>instance_accessor: false</tt>.
|
26
|
-
#
|
27
|
-
# class Person
|
28
|
-
# cattr_reader :hair_colors, instance_reader: false
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# Person.new.hair_colors # => NoMethodError
|
32
|
-
def cattr_reader(*syms)
|
33
|
-
options = syms.extract_options!
|
34
|
-
syms.each do |sym|
|
35
|
-
raise NameError.new("invalid class attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
36
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
37
|
-
unless defined? @@#{sym}
|
38
|
-
@@#{sym} = nil
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.#{sym}
|
42
|
-
@@#{sym}
|
43
|
-
end
|
44
|
-
EOS
|
45
|
-
|
46
|
-
unless options[:instance_reader] == false || options[:instance_accessor] == false
|
47
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
48
|
-
def #{sym}
|
49
|
-
@@#{sym}
|
50
|
-
end
|
51
|
-
EOS
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Defines a class attribute if it's not defined and creates a writer method to allow
|
57
|
-
# assignment to the attribute.
|
58
|
-
#
|
59
|
-
# class Person
|
60
|
-
# cattr_writer :hair_colors
|
61
|
-
# end
|
62
|
-
#
|
63
|
-
# Person.hair_colors = [:brown, :black]
|
64
|
-
# Person.class_variable_get("@@hair_colors") # => [:brown, :black]
|
65
|
-
# Person.new.hair_colors = [:blonde, :red]
|
66
|
-
# Person.class_variable_get("@@hair_colors") # => [:blonde, :red]
|
67
|
-
#
|
68
|
-
# The attribute name must be a valid method name in Ruby.
|
69
|
-
#
|
70
|
-
# class Person
|
71
|
-
# cattr_writer :"1_Badname "
|
72
|
-
# end
|
73
|
-
# # => NameError: invalid attribute name
|
74
|
-
#
|
75
|
-
# If you want to opt out the instance writer method, pass <tt>instance_writer: false</tt>
|
76
|
-
# or <tt>instance_accessor: false</tt>.
|
77
|
-
#
|
78
|
-
# class Person
|
79
|
-
# cattr_writer :hair_colors, instance_writer: false
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# Person.new.hair_colors = [:blonde, :red] # => NoMethodError
|
83
|
-
#
|
84
|
-
# Also, you can pass a block to set up the attribute with a default value.
|
85
|
-
#
|
86
|
-
# class Person
|
87
|
-
# cattr_writer :hair_colors do
|
88
|
-
# [:brown, :black, :blonde, :red]
|
89
|
-
# end
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# Person.class_variable_get("@@hair_colors") # => [:brown, :black, :blonde, :red]
|
93
|
-
def cattr_writer(*syms)
|
94
|
-
options = syms.extract_options!
|
95
|
-
syms.each do |sym|
|
96
|
-
raise NameError.new("invalid class attribute name: #{sym}") unless sym =~ /^[_A-Za-z]\w*$/
|
97
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
98
|
-
unless defined? @@#{sym}
|
99
|
-
@@#{sym} = nil
|
100
|
-
end
|
101
|
-
|
102
|
-
def self.#{sym}=(obj)
|
103
|
-
@@#{sym} = obj
|
104
|
-
end
|
105
|
-
EOS
|
106
|
-
|
107
|
-
unless options[:instance_writer] == false || options[:instance_accessor] == false
|
108
|
-
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
109
|
-
def #{sym}=(obj)
|
110
|
-
@@#{sym} = obj
|
111
|
-
end
|
112
|
-
EOS
|
113
|
-
end
|
114
|
-
send("#{sym}=", yield) if block_given?
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Defines both class and instance accessors for class attributes.
|
119
|
-
#
|
120
|
-
# class Person
|
121
|
-
# cattr_accessor :hair_colors
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# Person.hair_colors = [:brown, :black, :blonde, :red]
|
125
|
-
# Person.hair_colors # => [:brown, :black, :blonde, :red]
|
126
|
-
# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
|
127
|
-
#
|
128
|
-
# If a subclass changes the value then that would also change the value for
|
129
|
-
# parent class. Similarly if parent class changes the value then that would
|
130
|
-
# change the value of subclasses too.
|
131
|
-
#
|
132
|
-
# class Male < Person
|
133
|
-
# end
|
134
|
-
#
|
135
|
-
# Male.hair_colors << :blue
|
136
|
-
# Person.hair_colors # => [:brown, :black, :blonde, :red, :blue]
|
137
|
-
#
|
138
|
-
# To opt out of the instance writer method, pass <tt>instance_writer: false</tt>.
|
139
|
-
# To opt out of the instance reader method, pass <tt>instance_reader: false</tt>.
|
140
|
-
#
|
141
|
-
# class Person
|
142
|
-
# cattr_accessor :hair_colors, instance_writer: false, instance_reader: false
|
143
|
-
# end
|
144
|
-
#
|
145
|
-
# Person.new.hair_colors = [:brown] # => NoMethodError
|
146
|
-
# Person.new.hair_colors # => NoMethodError
|
147
|
-
#
|
148
|
-
# Or pass <tt>instance_accessor: false</tt>, to opt out both instance methods.
|
149
|
-
#
|
150
|
-
# class Person
|
151
|
-
# cattr_accessor :hair_colors, instance_accessor: false
|
152
|
-
# end
|
153
|
-
#
|
154
|
-
# Person.new.hair_colors = [:brown] # => NoMethodError
|
155
|
-
# Person.new.hair_colors # => NoMethodError
|
156
|
-
#
|
157
|
-
# Also you can pass a block to set up the attribute with a default value.
|
158
|
-
#
|
159
|
-
# class Person
|
160
|
-
# cattr_accessor :hair_colors do
|
161
|
-
# [:brown, :black, :blonde, :red]
|
162
|
-
# end
|
163
|
-
# end
|
164
|
-
#
|
165
|
-
# Person.class_variable_get("@@hair_colors") #=> [:brown, :black, :blonde, :red]
|
166
|
-
def cattr_accessor(*syms, &blk)
|
167
|
-
cattr_reader(*syms)
|
168
|
-
cattr_writer(*syms, &blk)
|
169
|
-
end
|
170
|
-
end
|
3
|
+
# cattr_* became mattr_* aliases in 7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d,
|
4
|
+
# but we keep this around for libraries that directly require it knowing they
|
5
|
+
# want cattr_*. No need to deprecate.
|
6
|
+
require "active_support/core_ext/module/attribute_accessors"
|
@@ -1,42 +1,41 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/module/reachable'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
begin
|
6
|
-
ObjectSpace.each_object(Class.new) {}
|
3
|
+
require "active_support/ruby_features"
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
class Class
|
6
|
+
if ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
7
|
+
# Returns an array with all classes that are < than its receiver.
|
8
|
+
#
|
9
|
+
# class C; end
|
10
|
+
# C.descendants # => []
|
11
|
+
#
|
12
|
+
# class B < C; end
|
13
|
+
# C.descendants # => [B]
|
14
|
+
#
|
15
|
+
# class A < B; end
|
16
|
+
# C.descendants # => [B, A]
|
17
|
+
#
|
18
|
+
# class D < C; end
|
19
|
+
# C.descendants # => [B, A, D]
|
20
|
+
def descendants
|
21
|
+
subclasses.concat(subclasses.flat_map(&:descendants))
|
14
22
|
end
|
15
|
-
|
16
|
-
def descendants
|
17
|
-
|
18
|
-
|
19
|
-
descendants.unshift k if k < self
|
23
|
+
else
|
24
|
+
def descendants
|
25
|
+
ObjectSpace.each_object(singleton_class).reject do |k|
|
26
|
+
k.singleton_class? || k == self
|
20
27
|
end
|
21
|
-
descendants.uniq!
|
22
|
-
descendants
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
31
|
# Returns an array with the direct children of +self+.
|
27
32
|
#
|
28
|
-
# Integer.subclasses # => [Fixnum, Bignum]
|
29
|
-
#
|
30
33
|
# class Foo; end
|
31
34
|
# class Bar < Foo; end
|
32
35
|
# class Baz < Bar; end
|
33
36
|
#
|
34
37
|
# Foo.subclasses # => [Bar]
|
35
38
|
def subclasses
|
36
|
-
|
37
|
-
|
38
|
-
subclasses << k unless chain.any? { |c| c > k }
|
39
|
-
end
|
40
|
-
subclasses
|
41
|
-
end
|
39
|
+
descendants.select { |descendant| descendant.superclass == self }
|
40
|
+
end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
|
42
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/class/attribute"
|
4
|
+
require "active_support/core_ext/class/subclasses"
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
require "active_support/duration"
|
5
|
+
require "active_support/core_ext/object/acts_like"
|
6
|
+
require "active_support/core_ext/date/zones"
|
7
|
+
require "active_support/core_ext/time/zones"
|
8
|
+
require "active_support/core_ext/date_and_time/calculations"
|
7
9
|
|
8
10
|
class Date
|
9
11
|
include DateAndTime::Calculations
|
@@ -15,7 +17,7 @@ class Date
|
|
15
17
|
# If <tt>Date.beginning_of_week</tt> has not been set for the current request, returns the week start specified in <tt>config.beginning_of_week</tt>.
|
16
18
|
# If no config.beginning_of_week was specified, returns :monday.
|
17
19
|
def beginning_of_week
|
18
|
-
|
20
|
+
::ActiveSupport::IsolatedExecutionState[:beginning_of_week] || beginning_of_week_default || :monday
|
19
21
|
end
|
20
22
|
|
21
23
|
# Sets <tt>Date.beginning_of_week</tt> to a week start (e.g. :monday) for current request/thread.
|
@@ -23,10 +25,10 @@ class Date
|
|
23
25
|
# This method accepts any of the following day symbols:
|
24
26
|
# :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday
|
25
27
|
def beginning_of_week=(week_start)
|
26
|
-
|
28
|
+
::ActiveSupport::IsolatedExecutionState[:beginning_of_week] = find_beginning_of_week!(week_start)
|
27
29
|
end
|
28
30
|
|
29
|
-
# Returns week start day symbol (e.g. :monday), or raises an ArgumentError for invalid day symbol.
|
31
|
+
# Returns week start day symbol (e.g. :monday), or raises an +ArgumentError+ for invalid day symbol.
|
30
32
|
def find_beginning_of_week!(week_start)
|
31
33
|
raise ArgumentError, "Invalid beginning of week: #{week_start}" unless ::Date::DAYS_INTO_WEEK.key?(week_start)
|
32
34
|
week_start
|
@@ -69,13 +71,23 @@ class Date
|
|
69
71
|
alias :at_midnight :beginning_of_day
|
70
72
|
alias :at_beginning_of_day :beginning_of_day
|
71
73
|
|
74
|
+
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the middle of the day (12:00)
|
75
|
+
def middle_of_day
|
76
|
+
in_time_zone.middle_of_day
|
77
|
+
end
|
78
|
+
alias :midday :middle_of_day
|
79
|
+
alias :noon :middle_of_day
|
80
|
+
alias :at_midday :middle_of_day
|
81
|
+
alias :at_noon :middle_of_day
|
82
|
+
alias :at_middle_of_day :middle_of_day
|
83
|
+
|
72
84
|
# Converts Date to a Time (or DateTime if necessary) with the time portion set to the end of the day (23:59:59)
|
73
85
|
def end_of_day
|
74
86
|
in_time_zone.end_of_day
|
75
87
|
end
|
76
88
|
alias :at_end_of_day :end_of_day
|
77
89
|
|
78
|
-
def plus_with_duration(other)
|
90
|
+
def plus_with_duration(other) # :nodoc:
|
79
91
|
if ActiveSupport::Duration === other
|
80
92
|
other.since(self)
|
81
93
|
else
|
@@ -85,7 +97,7 @@ class Date
|
|
85
97
|
alias_method :plus_without_duration, :+
|
86
98
|
alias_method :+, :plus_with_duration
|
87
99
|
|
88
|
-
def minus_with_duration(other)
|
100
|
+
def minus_with_duration(other) # :nodoc:
|
89
101
|
if ActiveSupport::Duration === other
|
90
102
|
plus_with_duration(-other)
|
91
103
|
else
|
@@ -98,12 +110,13 @@ class Date
|
|
98
110
|
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
|
99
111
|
# any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
|
100
112
|
def advance(options)
|
101
|
-
options = options.dup
|
102
113
|
d = self
|
103
|
-
|
104
|
-
d = d >> options
|
105
|
-
d = d
|
106
|
-
d = d +
|
114
|
+
|
115
|
+
d = d >> options[:years] * 12 if options[:years]
|
116
|
+
d = d >> options[:months] if options[:months]
|
117
|
+
d = d + options[:weeks] * 7 if options[:weeks]
|
118
|
+
d = d + options[:days] if options[:days]
|
119
|
+
|
107
120
|
d
|
108
121
|
end
|
109
122
|
|
@@ -119,11 +132,11 @@ class Date
|
|
119
132
|
options.fetch(:day, day)
|
120
133
|
)
|
121
134
|
end
|
122
|
-
|
135
|
+
|
123
136
|
# Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
|
124
137
|
def compare_with_coercion(other)
|
125
138
|
if other.is_a?(Time)
|
126
|
-
|
139
|
+
to_datetime <=> other
|
127
140
|
else
|
128
141
|
compare_without_coercion(other)
|
129
142
|
end
|
@@ -1,44 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
require "active_support/inflector/methods"
|
5
|
+
require "active_support/core_ext/date/zones"
|
6
|
+
require "active_support/core_ext/module/redefine_method"
|
5
7
|
|
6
8
|
class Date
|
7
9
|
DATE_FORMATS = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
10
|
+
short: "%d %b",
|
11
|
+
long: "%B %d, %Y",
|
12
|
+
db: "%Y-%m-%d",
|
13
|
+
inspect: "%Y-%m-%d",
|
14
|
+
number: "%Y%m%d",
|
15
|
+
long_ordinal: lambda { |date|
|
13
16
|
day_format = ActiveSupport::Inflector.ordinalize(date.day)
|
14
17
|
date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007"
|
15
18
|
},
|
16
|
-
:
|
19
|
+
rfc822: "%d %b %Y",
|
20
|
+
iso8601: lambda { |date| date.iso8601 }
|
17
21
|
}
|
18
22
|
|
19
|
-
# Ruby 1.9 has Date#to_time which converts to localtime only.
|
20
|
-
remove_method :to_time
|
21
|
-
|
22
|
-
# Ruby 1.9 has Date#xmlschema which converts to a string without the time
|
23
|
-
# component. This removal may generate an issue on FreeBSD, that's why we
|
24
|
-
# need to use remove_possible_method here
|
25
|
-
remove_possible_method :xmlschema
|
26
|
-
|
27
23
|
# Convert to a formatted string. See DATE_FORMATS for predefined formats.
|
28
24
|
#
|
29
|
-
# This method is aliased to <tt>
|
25
|
+
# This method is aliased to <tt>to_formatted_s</tt>.
|
30
26
|
#
|
31
27
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
32
28
|
#
|
29
|
+
# date.to_fs(:db) # => "2007-11-10"
|
33
30
|
# date.to_formatted_s(:db) # => "2007-11-10"
|
34
|
-
# date.to_s(:db) # => "2007-11-10"
|
35
31
|
#
|
36
|
-
# date.
|
37
|
-
# date.
|
38
|
-
# date.
|
39
|
-
# date.
|
32
|
+
# date.to_fs(:short) # => "10 Nov"
|
33
|
+
# date.to_fs(:number) # => "20071110"
|
34
|
+
# date.to_fs(:long) # => "November 10, 2007"
|
35
|
+
# date.to_fs(:long_ordinal) # => "November 10th, 2007"
|
36
|
+
# date.to_fs(:rfc822) # => "10 Nov 2007"
|
37
|
+
# date.to_fs(:iso8601) # => "2007-11-10"
|
40
38
|
#
|
41
|
-
# == Adding your own date formats to
|
39
|
+
# == Adding your own date formats to to_fs
|
42
40
|
# You can add your own formats to the Date::DATE_FORMATS hash.
|
43
41
|
# Use the format name as the hash key and either a strftime string
|
44
42
|
# or Proc instance that takes a date argument as the value.
|
@@ -46,7 +44,7 @@ class Date
|
|
46
44
|
# # config/initializers/date_formats.rb
|
47
45
|
# Date::DATE_FORMATS[:month_and_year] = '%B %Y'
|
48
46
|
# Date::DATE_FORMATS[:short_ordinal] = ->(date) { date.strftime("%B #{date.day.ordinalize}") }
|
49
|
-
def
|
47
|
+
def to_fs(format = :default)
|
50
48
|
if formatter = DATE_FORMATS[format]
|
51
49
|
if formatter.respond_to?(:call)
|
52
50
|
formatter.call(self).to_s
|
@@ -57,29 +55,42 @@ class Date
|
|
57
55
|
to_default_s
|
58
56
|
end
|
59
57
|
end
|
58
|
+
alias_method :to_formatted_s, :to_fs
|
60
59
|
alias_method :to_default_s, :to_s
|
61
|
-
alias_method :to_s, :to_formatted_s
|
62
60
|
|
63
61
|
# Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
|
64
62
|
def readable_inspect
|
65
|
-
strftime(
|
63
|
+
strftime("%a, %d %b %Y")
|
66
64
|
end
|
67
65
|
alias_method :default_inspect, :inspect
|
68
66
|
alias_method :inspect, :readable_inspect
|
69
67
|
|
68
|
+
silence_redefinition_of_method :to_time
|
69
|
+
|
70
70
|
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
|
71
71
|
# The timezone can be either :local or :utc (default :local).
|
72
72
|
#
|
73
73
|
# date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
|
74
74
|
#
|
75
|
-
# date.to_time # =>
|
76
|
-
# date.to_time(:local) # =>
|
75
|
+
# date.to_time # => 2007-11-10 00:00:00 0800
|
76
|
+
# date.to_time(:local) # => 2007-11-10 00:00:00 0800
|
77
77
|
#
|
78
|
-
# date.to_time(:utc) # =>
|
78
|
+
# date.to_time(:utc) # => 2007-11-10 00:00:00 UTC
|
79
|
+
#
|
80
|
+
# NOTE: The :local timezone is Ruby's *process* timezone, i.e. ENV['TZ'].
|
81
|
+
# If the *application's* timezone is needed, then use +in_time_zone+ instead.
|
79
82
|
def to_time(form = :local)
|
80
|
-
|
83
|
+
raise ArgumentError, "Expected :local or :utc, got #{form.inspect}." unless [:local, :utc].include?(form)
|
84
|
+
::Time.public_send(form, year, month, day)
|
81
85
|
end
|
82
86
|
|
87
|
+
silence_redefinition_of_method :xmlschema
|
88
|
+
|
89
|
+
# Returns a string which represents the time in used time zone as DateTime
|
90
|
+
# defined by XML Schema:
|
91
|
+
#
|
92
|
+
# date = Date.new(2015, 05, 23) # => Sat, 23 May 2015
|
93
|
+
# date.xmlschema # => "2015-05-23T00:00:00+04:00"
|
83
94
|
def xmlschema
|
84
95
|
in_time_zone.xmlschema
|
85
96
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
class Date
|
6
|
+
NOT_SET = Object.new # :nodoc:
|
7
|
+
def to_s(format = NOT_SET) # :nodoc:
|
8
|
+
if formatter = DATE_FORMATS[format]
|
9
|
+
ActiveSupport::Deprecation.warn(
|
10
|
+
"Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
|
11
|
+
)
|
12
|
+
if formatter.respond_to?(:call)
|
13
|
+
formatter.call(self).to_s
|
14
|
+
else
|
15
|
+
strftime(formatter)
|
16
|
+
end
|
17
|
+
elsif format == NOT_SET
|
18
|
+
to_default_s
|
19
|
+
else
|
20
|
+
ActiveSupport::Deprecation.warn(
|
21
|
+
"Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
|
22
|
+
)
|
23
|
+
to_default_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,37 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/time/zones'
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
# Converts Date to a TimeWithZone in the current zone if <tt>Time.zone</tt> or
|
8
|
-
# <tt>Time.zone_default</tt> is set, otherwise converts Date to a Time via
|
9
|
-
# Date#to_time.
|
10
|
-
def to_time_in_current_zone
|
11
|
-
ActiveSupport::Deprecation.warn 'Date#to_time_in_current_zone is deprecated. Use Date#in_time_zone instead', caller
|
12
|
-
|
13
|
-
if ::Time.zone
|
14
|
-
::Time.zone.local(year, month, day)
|
15
|
-
else
|
16
|
-
to_time
|
17
|
-
end
|
18
|
-
end
|
3
|
+
require "date"
|
4
|
+
require "active_support/core_ext/date_and_time/zones"
|
19
5
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
# Time.zone = 'Hawaii' # => 'Hawaii'
|
24
|
-
# Date.new(2000).in_time_zone # => Sat, 01 Jan 2000 00:00:00 HST -10:00
|
25
|
-
#
|
26
|
-
# You can also pass in a TimeZone instance or string that identifies a TimeZone as an argument,
|
27
|
-
# and the conversion will be based on that zone instead of <tt>Time.zone</tt>.
|
28
|
-
#
|
29
|
-
# Date.new(2000).in_time_zone('Alaska') # => Sat, 01 Jan 2000 00:00:00 AKST -09:00
|
30
|
-
def in_time_zone(zone = ::Time.zone)
|
31
|
-
if zone
|
32
|
-
::Time.find_zone!(zone).local(year, month, day)
|
33
|
-
else
|
34
|
-
to_time
|
35
|
-
end
|
36
|
-
end
|
6
|
+
class Date
|
7
|
+
include DateAndTime::Zones
|
37
8
|
end
|
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/date/calculations'
|
3
|
-
require 'active_support/core_ext/date/conversions'
|
4
|
-
require 'active_support/core_ext/date/zones'
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
3
|
+
require "active_support/core_ext/date/acts_like"
|
4
|
+
require "active_support/core_ext/date/blank"
|
5
|
+
require "active_support/core_ext/date/calculations"
|
6
|
+
require "active_support/core_ext/date/conversions"
|
7
|
+
require "active_support/core_ext/date/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
8
|
+
require "active_support/core_ext/date/zones"
|