omg-activesupport 8.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +86 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/lib/active_support/actionable_error.rb +50 -0
- data/lib/active_support/all.rb +5 -0
- data/lib/active_support/array_inquirer.rb +50 -0
- data/lib/active_support/backtrace_cleaner.rb +163 -0
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +53 -0
- data/lib/active_support/broadcast_logger.rb +251 -0
- data/lib/active_support/builder.rb +8 -0
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +134 -0
- data/lib/active_support/cache/file_store.rb +244 -0
- data/lib/active_support/cache/mem_cache_store.rb +290 -0
- data/lib/active_support/cache/memory_store.rb +262 -0
- data/lib/active_support/cache/null_store.rb +62 -0
- data/lib/active_support/cache/redis_cache_store.rb +492 -0
- data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
- data/lib/active_support/cache/strategy/local_cache.rb +201 -0
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +1104 -0
- data/lib/active_support/callbacks.rb +944 -0
- data/lib/active_support/class_attribute.rb +26 -0
- data/lib/active_support/code_generator.rb +79 -0
- data/lib/active_support/concern.rb +217 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +72 -0
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +225 -0
- data/lib/active_support/configurable.rb +159 -0
- data/lib/active_support/configuration_file.rb +60 -0
- data/lib/active_support/core_ext/array/access.rb +100 -0
- data/lib/active_support/core_ext/array/conversions.rb +213 -0
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +31 -0
- data/lib/active_support/core_ext/array/grouping.rb +109 -0
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +48 -0
- data/lib/active_support/core_ext/array.rb +9 -0
- data/lib/active_support/core_ext/benchmark.rb +13 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
- data/lib/active_support/core_ext/big_decimal.rb +3 -0
- data/lib/active_support/core_ext/class/attribute.rb +122 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/class/subclasses.rb +24 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/acts_like.rb +10 -0
- data/lib/active_support/core_ext/date/blank.rb +18 -0
- data/lib/active_support/core_ext/date/calculations.rb +161 -0
- data/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/lib/active_support/core_ext/date/zones.rb +8 -0
- data/lib/active_support/core_ext/date.rb +7 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +58 -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 +16 -0
- data/lib/active_support/core_ext/date_time/blank.rb +18 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +106 -0
- data/lib/active_support/core_ext/date_time.rb +7 -0
- data/lib/active_support/core_ext/digest/uuid.rb +76 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +267 -0
- data/lib/active_support/core_ext/erb/util.rb +201 -0
- data/lib/active_support/core_ext/file/atomic.rb +72 -0
- data/lib/active_support/core_ext/file.rb +3 -0
- data/lib/active_support/core_ext/hash/conversions.rb +262 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +42 -0
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
- data/lib/active_support/core_ext/hash/keys.rb +143 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/lib/active_support/core_ext/hash/slice.rb +27 -0
- data/lib/active_support/core_ext/hash.rb +10 -0
- data/lib/active_support/core_ext/integer/inflections.rb +31 -0
- data/lib/active_support/core_ext/integer/multiple.rb +12 -0
- data/lib/active_support/core_ext/integer/time.rb +22 -0
- data/lib/active_support/core_ext/integer.rb +5 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/load_error.rb +9 -0
- data/lib/active_support/core_ext/module/aliasing.rb +31 -0
- data/lib/active_support/core_ext/module/anonymous.rb +30 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +49 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +225 -0
- data/lib/active_support/core_ext/module/deprecation.rb +25 -0
- data/lib/active_support/core_ext/module/introspection.rb +62 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +17 -0
- data/lib/active_support/core_ext/module.rb +13 -0
- data/lib/active_support/core_ext/name_error.rb +59 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +75 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/time.rb +66 -0
- data/lib/active_support/core_ext/numeric.rb +5 -0
- data/lib/active_support/core_ext/object/acts_like.rb +45 -0
- data/lib/active_support/core_ext/object/blank.rb +199 -0
- data/lib/active_support/core_ext/object/conversions.rb +6 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
- data/lib/active_support/core_ext/object/duplicable.rb +69 -0
- data/lib/active_support/core_ext/object/inclusion.rb +37 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
- data/lib/active_support/core_ext/object/json.rb +260 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -0
- data/lib/active_support/core_ext/object/to_query.rb +87 -0
- data/lib/active_support/core_ext/object/try.rb +158 -0
- data/lib/active_support/core_ext/object/with.rb +46 -0
- data/lib/active_support/core_ext/object/with_options.rb +101 -0
- data/lib/active_support/core_ext/object.rb +17 -0
- data/lib/active_support/core_ext/pathname/blank.rb +20 -0
- data/lib/active_support/core_ext/pathname/existence.rb +23 -0
- data/lib/active_support/core_ext/pathname.rb +4 -0
- data/lib/active_support/core_ext/range/compare_range.rb +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +62 -0
- data/lib/active_support/core_ext/range/each.rb +24 -0
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +14 -0
- data/lib/active_support/core_ext/securerandom.rb +41 -0
- data/lib/active_support/core_ext/string/access.rb +95 -0
- data/lib/active_support/core_ext/string/behavior.rb +8 -0
- data/lib/active_support/core_ext/string/conversions.rb +60 -0
- data/lib/active_support/core_ext/string/exclude.rb +13 -0
- data/lib/active_support/core_ext/string/filters.rb +151 -0
- data/lib/active_support/core_ext/string/indent.rb +45 -0
- data/lib/active_support/core_ext/string/inflections.rb +300 -0
- data/lib/active_support/core_ext/string/inquiry.rb +16 -0
- data/lib/active_support/core_ext/string/multibyte.rb +58 -0
- data/lib/active_support/core_ext/string/output_safety.rb +228 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/string/strip.rb +27 -0
- data/lib/active_support/core_ext/string/zones.rb +16 -0
- data/lib/active_support/core_ext/string.rb +15 -0
- 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/thread/backtrace/location.rb +12 -0
- data/lib/active_support/core_ext/time/acts_like.rb +10 -0
- data/lib/active_support/core_ext/time/calculations.rb +386 -0
- data/lib/active_support/core_ext/time/compatibility.rb +32 -0
- data/lib/active_support/core_ext/time/conversions.rb +75 -0
- data/lib/active_support/core_ext/time/zones.rb +97 -0
- data/lib/active_support/core_ext/time.rb +7 -0
- data/lib/active_support/core_ext.rb +5 -0
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +233 -0
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/delegation.rb +202 -0
- data/lib/active_support/dependencies/autoload.rb +72 -0
- 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 +98 -0
- data/lib/active_support/deprecation/behaviors.rb +148 -0
- data/lib/active_support/deprecation/constant_accessor.rb +74 -0
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/method_wrappers.rb +68 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
- data/lib/active_support/deprecation/reporting.rb +179 -0
- data/lib/active_support/deprecation.rb +81 -0
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +112 -0
- 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 +64 -0
- data/lib/active_support/duration.rb +520 -0
- data/lib/active_support/encrypted_configuration.rb +126 -0
- data/lib/active_support/encrypted_file.rb +133 -0
- data/lib/active_support/environment_inquirer.rb +40 -0
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +265 -0
- data/lib/active_support/evented_file_update_checker.rb +182 -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 +150 -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 +164 -0
- data/lib/active_support/fork_tracker.rb +43 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +40 -0
- data/lib/active_support/hash_with_indifferent_access.rb +445 -0
- data/lib/active_support/html_safe_translation.rb +56 -0
- data/lib/active_support/i18n.rb +17 -0
- data/lib/active_support/i18n_railtie.rb +138 -0
- data/lib/active_support/inflections.rb +72 -0
- data/lib/active_support/inflector/inflections.rb +273 -0
- data/lib/active_support/inflector/methods.rb +387 -0
- data/lib/active_support/inflector/transliterate.rb +149 -0
- data/lib/active_support/inflector.rb +9 -0
- data/lib/active_support/isolated_execution_state.rb +75 -0
- data/lib/active_support/json/decoding.rb +76 -0
- data/lib/active_support/json/encoding.rb +120 -0
- data/lib/active_support/json.rb +4 -0
- data/lib/active_support/key_generator.rb +66 -0
- data/lib/active_support/lazy_load_hooks.rb +107 -0
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +141 -0
- data/lib/active_support/log_subscriber/test_helper.rb +106 -0
- data/lib/active_support/log_subscriber.rb +192 -0
- data/lib/active_support/logger.rb +55 -0
- data/lib/active_support/logger_silence.rb +21 -0
- data/lib/active_support/logger_thread_safe_level.rb +47 -0
- data/lib/active_support/message_encryptor.rb +374 -0
- data/lib/active_support/message_encryptors.rb +141 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +305 -0
- data/lib/active_support/message_pack/serializer.rb +63 -0
- data/lib/active_support/message_pack.rb +50 -0
- data/lib/active_support/message_verifier.rb +368 -0
- data/lib/active_support/message_verifiers.rb +135 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +146 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +59 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +178 -0
- data/lib/active_support/multibyte/unicode.rb +42 -0
- data/lib/active_support/multibyte.rb +23 -0
- data/lib/active_support/notifications/fanout.rb +446 -0
- data/lib/active_support/notifications/instrumenter.rb +240 -0
- data/lib/active_support/notifications.rb +281 -0
- data/lib/active_support/number_helper/number_converter.rb +190 -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 +60 -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 +479 -0
- data/lib/active_support/option_merger.rb +38 -0
- data/lib/active_support/ordered_hash.rb +50 -0
- data/lib/active_support/ordered_options.rb +147 -0
- data/lib/active_support/parameter_filter.rb +157 -0
- data/lib/active_support/proxy_object.rb +20 -0
- data/lib/active_support/rails.rb +26 -0
- data/lib/active_support/railtie.rb +161 -0
- data/lib/active_support/reloader.rb +138 -0
- data/lib/active_support/rescuable.rb +176 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +35 -0
- data/lib/active_support/subscriber.rb +146 -0
- data/lib/active_support/syntax_error_proxy.rb +60 -0
- data/lib/active_support/tagged_logging.rb +152 -0
- data/lib/active_support/test_case.rb +304 -0
- data/lib/active_support/testing/assertions.rb +332 -0
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +51 -0
- data/lib/active_support/testing/constant_stubbing.rb +54 -0
- data/lib/active_support/testing/declarative.rb +28 -0
- data/lib/active_support/testing/deprecation.rb +82 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +121 -0
- data/lib/active_support/testing/method_call_assertions.rb +69 -0
- data/lib/active_support/testing/parallelization/server.rb +85 -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 +81 -0
- data/lib/active_support/testing/setup_and_teardown.rb +57 -0
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/strict_warnings.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +27 -0
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +269 -0
- data/lib/active_support/time.rb +20 -0
- data/lib/active_support/time_with_zone.rb +609 -0
- data/lib/active_support/values/time_zone.rb +614 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/xml_mini/jdom.rb +175 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
- data/lib/active_support/xml_mini/nokogiri.rb +83 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
- data/lib/active_support/xml_mini/rexml.rb +137 -0
- data/lib/active_support/xml_mini.rb +211 -0
- data/lib/active_support.rb +144 -0
- metadata +526 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module ActiveSupport
|
8
|
+
# Look for and parse JSON strings that look like ISO 8601 times.
|
9
|
+
mattr_accessor :parse_json_times
|
10
|
+
|
11
|
+
module JSON
|
12
|
+
# matches YAML-formatted dates
|
13
|
+
DATE_REGEX = /\A\d{4}-\d{2}-\d{2}\z/
|
14
|
+
DATETIME_REGEX = /\A(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?)\z/
|
15
|
+
|
16
|
+
class << self
|
17
|
+
# Parses a JSON string (JavaScript Object Notation) into a hash.
|
18
|
+
# See http://www.json.org for more info.
|
19
|
+
#
|
20
|
+
# ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
|
21
|
+
# => {"team" => "rails", "players" => "36"}
|
22
|
+
def decode(json)
|
23
|
+
data = ::JSON.parse(json, quirks_mode: true)
|
24
|
+
|
25
|
+
if ActiveSupport.parse_json_times
|
26
|
+
convert_dates_from(data)
|
27
|
+
else
|
28
|
+
data
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_method :load, :decode
|
32
|
+
|
33
|
+
# Returns the class of the error that will be raised when there is an
|
34
|
+
# error in decoding JSON. Using this method means you won't directly
|
35
|
+
# depend on the ActiveSupport's JSON implementation, in case it changes
|
36
|
+
# in the future.
|
37
|
+
#
|
38
|
+
# begin
|
39
|
+
# obj = ActiveSupport::JSON.decode(some_string)
|
40
|
+
# rescue ActiveSupport::JSON.parse_error
|
41
|
+
# Rails.logger.warn("Attempted to decode invalid JSON: #{some_string}")
|
42
|
+
# end
|
43
|
+
def parse_error
|
44
|
+
::JSON::ParserError
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def convert_dates_from(data)
|
49
|
+
case data
|
50
|
+
when nil
|
51
|
+
nil
|
52
|
+
when DATE_REGEX
|
53
|
+
begin
|
54
|
+
Date.parse(data)
|
55
|
+
rescue ArgumentError
|
56
|
+
data
|
57
|
+
end
|
58
|
+
when DATETIME_REGEX
|
59
|
+
begin
|
60
|
+
Time.zone.parse(data)
|
61
|
+
rescue ArgumentError
|
62
|
+
data
|
63
|
+
end
|
64
|
+
when Array
|
65
|
+
data.map! { |d| convert_dates_from(d) }
|
66
|
+
when Hash
|
67
|
+
data.transform_values! do |value|
|
68
|
+
convert_dates_from(value)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
data
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/json"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
class << self
|
8
|
+
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
|
9
|
+
:time_precision, :time_precision=,
|
10
|
+
:escape_html_entities_in_json, :escape_html_entities_in_json=,
|
11
|
+
:json_encoder, :json_encoder=,
|
12
|
+
to: :'ActiveSupport::JSON::Encoding'
|
13
|
+
end
|
14
|
+
|
15
|
+
module JSON
|
16
|
+
# Dumps objects in JSON (JavaScript Object Notation).
|
17
|
+
# See http://www.json.org for more info.
|
18
|
+
#
|
19
|
+
# ActiveSupport::JSON.encode({ team: 'rails', players: '36' })
|
20
|
+
# # => "{\"team\":\"rails\",\"players\":\"36\"}"
|
21
|
+
class << self
|
22
|
+
def encode(value, options = nil)
|
23
|
+
Encoding.json_encoder.new(options).encode(value)
|
24
|
+
end
|
25
|
+
alias_method :dump, :encode
|
26
|
+
end
|
27
|
+
|
28
|
+
module Encoding # :nodoc:
|
29
|
+
class JSONGemEncoder # :nodoc:
|
30
|
+
attr_reader :options
|
31
|
+
|
32
|
+
def initialize(options = nil)
|
33
|
+
@options = options || {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Encode the given object into a JSON string
|
37
|
+
def encode(value)
|
38
|
+
unless options.empty?
|
39
|
+
value = value.as_json(options.dup.freeze)
|
40
|
+
end
|
41
|
+
json = stringify(jsonify(value))
|
42
|
+
|
43
|
+
# Rails does more escaping than the JSON gem natively does (we
|
44
|
+
# escape \u2028 and \u2029 and optionally >, <, & to work around
|
45
|
+
# certain browser problems).
|
46
|
+
if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json)
|
47
|
+
json.gsub!(">", '\u003e')
|
48
|
+
json.gsub!("<", '\u003c')
|
49
|
+
json.gsub!("&", '\u0026')
|
50
|
+
end
|
51
|
+
json.gsub!("\u2028", '\u2028')
|
52
|
+
json.gsub!("\u2029", '\u2029')
|
53
|
+
json
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
# Convert an object into a "JSON-ready" representation composed of
|
58
|
+
# primitives like Hash, Array, String, Symbol, Numeric,
|
59
|
+
# and +true+/+false+/+nil+.
|
60
|
+
# Recursively calls #as_json to the object to recursively build a
|
61
|
+
# fully JSON-ready object.
|
62
|
+
#
|
63
|
+
# This allows developers to implement #as_json without having to
|
64
|
+
# worry about what base types of objects they are allowed to return
|
65
|
+
# or having to remember to call #as_json recursively.
|
66
|
+
#
|
67
|
+
# Note: the +options+ hash passed to +object.to_json+ is only passed
|
68
|
+
# to +object.as_json+, not any of this method's recursive +#as_json+
|
69
|
+
# calls.
|
70
|
+
def jsonify(value)
|
71
|
+
case value
|
72
|
+
when String, Integer, Symbol, nil, true, false
|
73
|
+
value
|
74
|
+
when Numeric
|
75
|
+
value.as_json
|
76
|
+
when Hash
|
77
|
+
result = {}
|
78
|
+
value.each do |k, v|
|
79
|
+
k = k.to_s unless Symbol === k || String === k
|
80
|
+
result[k] = jsonify(v)
|
81
|
+
end
|
82
|
+
result
|
83
|
+
when Array
|
84
|
+
value.map { |v| jsonify(v) }
|
85
|
+
else
|
86
|
+
jsonify value.as_json
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Encode a "jsonified" Ruby data structure using the JSON gem
|
91
|
+
def stringify(jsonified)
|
92
|
+
::JSON.generate(jsonified, quirks_mode: true, max_nesting: false)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class << self
|
97
|
+
# If true, use ISO 8601 format for dates and times. Otherwise, fall back
|
98
|
+
# to the Active Support legacy format.
|
99
|
+
attr_accessor :use_standard_json_time_format
|
100
|
+
|
101
|
+
# If true, encode >, <, & as escaped unicode sequences (e.g. > as \u003e)
|
102
|
+
# as a safety measure.
|
103
|
+
attr_accessor :escape_html_entities_in_json
|
104
|
+
|
105
|
+
# Sets the precision of encoded time values.
|
106
|
+
# Defaults to 3 (equivalent to millisecond precision)
|
107
|
+
attr_accessor :time_precision
|
108
|
+
|
109
|
+
# Sets the encoder used by \Rails to encode Ruby objects into JSON strings
|
110
|
+
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
|
111
|
+
attr_accessor :json_encoder
|
112
|
+
end
|
113
|
+
|
114
|
+
self.use_standard_json_time_format = true
|
115
|
+
self.escape_html_entities_in_json = true
|
116
|
+
self.json_encoder = JSONGemEncoder
|
117
|
+
self.time_precision = 3
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
4
|
+
require "openssl"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
# = Key Generator
|
8
|
+
#
|
9
|
+
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2.
|
10
|
+
# It can be used to derive a number of keys for various purposes from a given secret.
|
11
|
+
# This lets \Rails applications have a single secure secret, but avoid reusing that
|
12
|
+
# key in multiple incompatible contexts.
|
13
|
+
class KeyGenerator
|
14
|
+
class << self
|
15
|
+
def hash_digest_class=(klass)
|
16
|
+
if klass.kind_of?(Class) && klass < OpenSSL::Digest
|
17
|
+
@hash_digest_class = klass
|
18
|
+
else
|
19
|
+
raise ArgumentError, "#{klass} is expected to be an OpenSSL::Digest subclass"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def hash_digest_class
|
24
|
+
@hash_digest_class ||= OpenSSL::Digest::SHA1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(secret, options = {})
|
29
|
+
@secret = secret
|
30
|
+
# The default iterations are higher than required for our key derivation uses
|
31
|
+
# on the off chance someone uses this for password storage
|
32
|
+
@iterations = options[:iterations] || 2**16
|
33
|
+
# Also allow configuration here so people can use this to build a rotation
|
34
|
+
# scheme when switching the digest class.
|
35
|
+
@hash_digest_class = options[:hash_digest_class] || self.class.hash_digest_class
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a derived key suitable for use. The default +key_size+ is chosen
|
39
|
+
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
|
40
|
+
# i.e. <tt>OpenSSL::Digest::SHA1#block_length</tt>
|
41
|
+
def generate_key(salt, key_size = 64)
|
42
|
+
OpenSSL::PKCS5.pbkdf2_hmac(@secret, salt, @iterations, key_size, @hash_digest_class.new)
|
43
|
+
end
|
44
|
+
|
45
|
+
def inspect # :nodoc:
|
46
|
+
"#<#{self.class.name}:#{'%#016x' % (object_id << 1)}>"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# = Caching Key Generator
|
51
|
+
#
|
52
|
+
# CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
|
53
|
+
# re-executing the key generation process when it's called using the same +salt+ and
|
54
|
+
# +key_size+.
|
55
|
+
class CachingKeyGenerator
|
56
|
+
def initialize(key_generator)
|
57
|
+
@key_generator = key_generator
|
58
|
+
@cache_keys = Concurrent::Map.new
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns a derived key suitable for use.
|
62
|
+
def generate_key(*args)
|
63
|
+
@cache_keys[args.join("|")] ||= @key_generator.generate_key(*args)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# = Lazy Load Hooks
|
5
|
+
#
|
6
|
+
# LazyLoadHooks allows \Rails to lazily load a lot of components and thus
|
7
|
+
# making the app boot faster. Because of this feature now there is no need to
|
8
|
+
# require +ActiveRecord::Base+ at boot time purely to apply
|
9
|
+
# configuration. Instead a hook is registered that applies configuration once
|
10
|
+
# +ActiveRecord::Base+ is loaded. Here +ActiveRecord::Base+ is
|
11
|
+
# used as example but this feature can be applied elsewhere too.
|
12
|
+
#
|
13
|
+
# Here is an example where on_load method is called to register a hook.
|
14
|
+
#
|
15
|
+
# initializer 'active_record.initialize_timezone' do
|
16
|
+
# ActiveSupport.on_load(:active_record) do
|
17
|
+
# self.time_zone_aware_attributes = true
|
18
|
+
# self.default_timezone = :utc
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# When the entirety of +ActiveRecord::Base+ has been
|
23
|
+
# evaluated then run_load_hooks is invoked. The very last line of
|
24
|
+
# +ActiveRecord::Base+ is:
|
25
|
+
#
|
26
|
+
# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
27
|
+
#
|
28
|
+
# run_load_hooks will then execute all the hooks that were registered
|
29
|
+
# with the on_load method. In the case of the above example, it will
|
30
|
+
# execute the block of code that is in the +initializer+.
|
31
|
+
#
|
32
|
+
# Registering a hook that has already run results in that hook executing
|
33
|
+
# immediately. This allows hooks to be nested for code that relies on
|
34
|
+
# multiple lazily loaded components:
|
35
|
+
#
|
36
|
+
# initializer "action_text.renderer" do
|
37
|
+
# ActiveSupport.on_load(:action_controller_base) do
|
38
|
+
# ActiveSupport.on_load(:action_text_content) do
|
39
|
+
# self.default_renderer = Class.new(ActionController::Base).renderer
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
module LazyLoadHooks
|
44
|
+
def self.extended(base) # :nodoc:
|
45
|
+
base.class_eval do
|
46
|
+
@load_hooks = Hash.new { |h, k| h[k] = [] }
|
47
|
+
@loaded = Hash.new { |h, k| h[k] = [] }
|
48
|
+
@run_once = Hash.new { |h, k| h[k] = [] }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Declares a block that will be executed when a \Rails component is fully
|
53
|
+
# loaded. If the component has already loaded, the block is executed
|
54
|
+
# immediately.
|
55
|
+
#
|
56
|
+
# Options:
|
57
|
+
#
|
58
|
+
# * <tt>:yield</tt> - Yields the object that run_load_hooks to +block+.
|
59
|
+
# * <tt>:run_once</tt> - Given +block+ will run only once.
|
60
|
+
def on_load(name, options = {}, &block)
|
61
|
+
@loaded[name].each do |base|
|
62
|
+
execute_hook(name, base, options, block)
|
63
|
+
end
|
64
|
+
|
65
|
+
@load_hooks[name] << [block, options]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Executes all blocks registered to +name+ via on_load, using +base+ as the
|
69
|
+
# evaluation context.
|
70
|
+
#
|
71
|
+
# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
72
|
+
#
|
73
|
+
# In the case of the above example, it will execute all hooks registered
|
74
|
+
# for +:active_record+ within the class +ActiveRecord::Base+.
|
75
|
+
def run_load_hooks(name, base = Object)
|
76
|
+
@loaded[name] << base
|
77
|
+
@load_hooks[name].each do |hook, options|
|
78
|
+
execute_hook(name, base, options, hook)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
def with_execution_control(name, block, once)
|
84
|
+
unless @run_once[name].include?(block)
|
85
|
+
@run_once[name] << block if once
|
86
|
+
|
87
|
+
yield
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute_hook(name, base, options, block)
|
92
|
+
with_execution_control(name, block, options[:run_once]) do
|
93
|
+
if options[:yield]
|
94
|
+
block.call(base)
|
95
|
+
else
|
96
|
+
if base.is_a?(Module)
|
97
|
+
base.class_eval(&block)
|
98
|
+
else
|
99
|
+
base.instance_eval(&block)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
extend LazyLoadHooks
|
107
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
{
|
4
|
+
en: {
|
5
|
+
number: {
|
6
|
+
nth: {
|
7
|
+
ordinals: lambda do |_key, options|
|
8
|
+
number = options[:number]
|
9
|
+
case number
|
10
|
+
when 1; "st"
|
11
|
+
when 2; "nd"
|
12
|
+
when 3; "rd"
|
13
|
+
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
|
14
|
+
else
|
15
|
+
num_modulo = number.to_i.abs % 100
|
16
|
+
num_modulo %= 10 if num_modulo > 13
|
17
|
+
case num_modulo
|
18
|
+
when 1; "st"
|
19
|
+
when 2; "nd"
|
20
|
+
when 3; "rd"
|
21
|
+
else "th"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end,
|
25
|
+
|
26
|
+
ordinalized: lambda do |_key, options|
|
27
|
+
number = options[:number]
|
28
|
+
"#{number}#{ActiveSupport::Inflector.ordinal(number)}"
|
29
|
+
end
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -0,0 +1,141 @@
|
|
1
|
+
en:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
# Use the strftime parameters for formats.
|
5
|
+
# When no format has been given, it uses default.
|
6
|
+
# You can provide other formats here if you like!
|
7
|
+
default: "%Y-%m-%d"
|
8
|
+
short: "%b %d"
|
9
|
+
long: "%B %d, %Y"
|
10
|
+
|
11
|
+
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
12
|
+
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
13
|
+
|
14
|
+
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
15
|
+
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
16
|
+
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
17
|
+
# Used in date_select and datetime_select.
|
18
|
+
order:
|
19
|
+
- year
|
20
|
+
- month
|
21
|
+
- day
|
22
|
+
|
23
|
+
time:
|
24
|
+
formats:
|
25
|
+
default: "%a, %d %b %Y %H:%M:%S %z"
|
26
|
+
short: "%d %b %H:%M"
|
27
|
+
long: "%B %d, %Y %H:%M"
|
28
|
+
am: "am"
|
29
|
+
pm: "pm"
|
30
|
+
|
31
|
+
# Used in array.to_sentence.
|
32
|
+
support:
|
33
|
+
array:
|
34
|
+
words_connector: ", "
|
35
|
+
two_words_connector: " and "
|
36
|
+
last_word_connector: ", and "
|
37
|
+
number:
|
38
|
+
# Used in NumberHelper.number_to_delimited()
|
39
|
+
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
40
|
+
format:
|
41
|
+
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
|
42
|
+
separator: "."
|
43
|
+
# Delimits thousands (e.g. 1,000,000 is a million) (always in groups of three)
|
44
|
+
delimiter: ","
|
45
|
+
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
46
|
+
precision: 3
|
47
|
+
# Determine how rounding is performed (see BigDecimal::mode)
|
48
|
+
round_mode: default
|
49
|
+
# If set to true, precision will mean the number of significant digits instead
|
50
|
+
# of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2)
|
51
|
+
significant: false
|
52
|
+
# If set, the zeros after the decimal separator will always be stripped (e.g.: 1.200 will be 1.2)
|
53
|
+
strip_insignificant_zeros: false
|
54
|
+
|
55
|
+
# Used in NumberHelper.number_to_currency()
|
56
|
+
currency:
|
57
|
+
format:
|
58
|
+
# Where is the currency sign? %u is the currency unit, %n is the number (default: $5.00)
|
59
|
+
format: "%u%n"
|
60
|
+
negative_format: "-%u%n"
|
61
|
+
unit: "$"
|
62
|
+
# These six are to override number.format and are optional
|
63
|
+
separator: "."
|
64
|
+
delimiter: ","
|
65
|
+
precision: 2
|
66
|
+
# round_mode:
|
67
|
+
significant: false
|
68
|
+
strip_insignificant_zeros: false
|
69
|
+
|
70
|
+
# Used in NumberHelper.number_to_percentage()
|
71
|
+
percentage:
|
72
|
+
format:
|
73
|
+
# These five are to override number.format and are optional
|
74
|
+
# separator:
|
75
|
+
delimiter: ""
|
76
|
+
# precision:
|
77
|
+
# significant: false
|
78
|
+
# strip_insignificant_zeros: false
|
79
|
+
format: "%n%"
|
80
|
+
|
81
|
+
# Used in NumberHelper.number_to_rounded()
|
82
|
+
precision:
|
83
|
+
format:
|
84
|
+
# These five are to override number.format and are optional
|
85
|
+
# separator:
|
86
|
+
delimiter: ""
|
87
|
+
# precision:
|
88
|
+
# significant: false
|
89
|
+
# strip_insignificant_zeros: false
|
90
|
+
|
91
|
+
# Used in NumberHelper.number_to_human_size() and NumberHelper.number_to_human()
|
92
|
+
human:
|
93
|
+
format:
|
94
|
+
# These six are to override number.format and are optional
|
95
|
+
# separator:
|
96
|
+
delimiter: ""
|
97
|
+
precision: 3
|
98
|
+
# round_mode:
|
99
|
+
significant: true
|
100
|
+
strip_insignificant_zeros: true
|
101
|
+
# Used in number_to_human_size()
|
102
|
+
storage_units:
|
103
|
+
# Storage units output formatting.
|
104
|
+
# %u is the storage unit, %n is the number (default: 2 MB)
|
105
|
+
format: "%n %u"
|
106
|
+
units:
|
107
|
+
byte:
|
108
|
+
one: "Byte"
|
109
|
+
other: "Bytes"
|
110
|
+
kb: "KB"
|
111
|
+
mb: "MB"
|
112
|
+
gb: "GB"
|
113
|
+
tb: "TB"
|
114
|
+
pb: "PB"
|
115
|
+
eb: "EB"
|
116
|
+
zb: "ZB"
|
117
|
+
# Used in NumberHelper.number_to_human()
|
118
|
+
decimal_units:
|
119
|
+
format: "%n %u"
|
120
|
+
# Decimal units output formatting
|
121
|
+
# By default we will only quantify some of the exponents
|
122
|
+
# but the commented ones might be defined or overridden
|
123
|
+
# by the user.
|
124
|
+
units:
|
125
|
+
# femto: Quadrillionth
|
126
|
+
# pico: Trillionth
|
127
|
+
# nano: Billionth
|
128
|
+
# micro: Millionth
|
129
|
+
# mili: Thousandth
|
130
|
+
# centi: Hundredth
|
131
|
+
# deci: Tenth
|
132
|
+
unit: ""
|
133
|
+
# ten:
|
134
|
+
# one: Ten
|
135
|
+
# other: Tens
|
136
|
+
# hundred: Hundred
|
137
|
+
thousand: Thousand
|
138
|
+
million: Million
|
139
|
+
billion: Billion
|
140
|
+
trillion: Trillion
|
141
|
+
quadrillion: Quadrillion
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/log_subscriber"
|
4
|
+
require "active_support/logger"
|
5
|
+
require "active_support/notifications"
|
6
|
+
|
7
|
+
module ActiveSupport
|
8
|
+
class LogSubscriber
|
9
|
+
# Provides some helpers to deal with testing log subscribers by setting up
|
10
|
+
# notifications. Take for instance Active Record subscriber tests:
|
11
|
+
#
|
12
|
+
# class SyncLogSubscriberTest < ActiveSupport::TestCase
|
13
|
+
# include ActiveSupport::LogSubscriber::TestHelper
|
14
|
+
#
|
15
|
+
# setup do
|
16
|
+
# ActiveRecord::LogSubscriber.attach_to(:active_record)
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def test_basic_query_logging
|
20
|
+
# Developer.all.to_a
|
21
|
+
# wait
|
22
|
+
# assert_equal 1, @logger.logged(:debug).size
|
23
|
+
# assert_match(/Developer Load/, @logger.logged(:debug).last)
|
24
|
+
# assert_match(/SELECT \* FROM "developers"/, @logger.logged(:debug).last)
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# All you need to do is to ensure that your log subscriber is added to
|
29
|
+
# Rails::Subscriber, as in the second line of the code above. The test
|
30
|
+
# helpers are responsible for setting up the queue and subscriptions, and
|
31
|
+
# turning colors in logs off.
|
32
|
+
#
|
33
|
+
# The messages are available in the @logger instance, which is a logger with
|
34
|
+
# limited powers (it actually does not send anything to your output), and
|
35
|
+
# you can collect them doing @logger.logged(level), where level is the level
|
36
|
+
# used in logging, like info, debug, warn, and so on.
|
37
|
+
module TestHelper
|
38
|
+
def setup # :nodoc:
|
39
|
+
@logger = MockLogger.new
|
40
|
+
@notifier = ActiveSupport::Notifications::Fanout.new
|
41
|
+
|
42
|
+
ActiveSupport::LogSubscriber.colorize_logging = false
|
43
|
+
|
44
|
+
@old_notifier = ActiveSupport::Notifications.notifier
|
45
|
+
set_logger(@logger)
|
46
|
+
ActiveSupport::Notifications.notifier = @notifier
|
47
|
+
end
|
48
|
+
|
49
|
+
def teardown # :nodoc:
|
50
|
+
set_logger(nil)
|
51
|
+
ActiveSupport::Notifications.notifier = @old_notifier
|
52
|
+
end
|
53
|
+
|
54
|
+
class MockLogger
|
55
|
+
include ActiveSupport::Logger::Severity
|
56
|
+
|
57
|
+
attr_reader :flush_count
|
58
|
+
attr_accessor :level
|
59
|
+
|
60
|
+
def initialize(level = DEBUG)
|
61
|
+
@flush_count = 0
|
62
|
+
@level = level
|
63
|
+
@logged = Hash.new { |h, k| h[k] = [] }
|
64
|
+
end
|
65
|
+
|
66
|
+
def method_missing(level, message = nil)
|
67
|
+
if block_given?
|
68
|
+
@logged[level] << yield
|
69
|
+
else
|
70
|
+
@logged[level] << message
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def logged(level)
|
75
|
+
@logged[level].compact.map { |l| l.to_s.strip }
|
76
|
+
end
|
77
|
+
|
78
|
+
def flush
|
79
|
+
@flush_count += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
ActiveSupport::Logger::Severity.constants.each do |severity|
|
83
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
84
|
+
def #{severity.downcase}?
|
85
|
+
#{severity} >= @level
|
86
|
+
end
|
87
|
+
EOT
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Wait notifications to be published.
|
92
|
+
def wait
|
93
|
+
@notifier.wait
|
94
|
+
end
|
95
|
+
|
96
|
+
# Overwrite if you use another logger in your log subscriber.
|
97
|
+
#
|
98
|
+
# def logger
|
99
|
+
# ActiveRecord::Base.logger = @logger
|
100
|
+
# end
|
101
|
+
def set_logger(logger)
|
102
|
+
ActiveSupport::LogSubscriber.logger = logger
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|