activesupport 4.0.13 → 5.2.5
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 +412 -444
- data/MIT-LICENSE +2 -2
- data/README.rdoc +8 -4
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +14 -12
- data/lib/active_support/benchmarkable.rb +6 -14
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +67 -51
- data/lib/active_support/cache/mem_cache_store.rb +95 -97
- data/lib/active_support/cache/memory_store.rb +28 -30
- data/lib/active_support/cache/null_store.rb +7 -8
- data/lib/active_support/cache/redis_cache_store.rb +466 -0
- data/lib/active_support/cache/strategy/local_cache.rb +70 -56
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +331 -206
- data/lib/active_support/callbacks.rb +697 -426
- data/lib/active_support/concern.rb +32 -10
- 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/array/access.rb +39 -1
- data/lib/active_support/core_ext/array/conversions.rb +24 -35
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +23 -13
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -5
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -7
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- 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 +41 -23
- data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
- data/lib/active_support/core_ext/class/subclasses.rb +20 -8
- 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 +21 -9
- data/lib/active_support/core_ext/date/conversions.rb +32 -22
- data/lib/active_support/core_ext/date/zones.rb +5 -34
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +199 -57
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +41 -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 +78 -37
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +19 -13
- data/lib/active_support/core_ext/date_time.rb +7 -4
- data/lib/active_support/core_ext/digest/uuid.rb +53 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +113 -29
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/compact.rb +29 -0
- 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/except.rb +12 -3
- data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
- data/lib/active_support/core_ext/hash/keys.rb +50 -38
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +12 -6
- data/lib/active_support/core_ext/hash/transform_values.rb +32 -0
- data/lib/active_support/core_ext/hash.rb +11 -8
- 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/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +5 -74
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +6 -4
- data/lib/active_support/core_ext/load_error.rb +5 -21
- data/lib/active_support/core_ext/marshal.rb +13 -10
- 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 +170 -21
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
- data/lib/active_support/core_ext/module/concerning.rb +134 -0
- data/lib/active_support/core_ext/module/delegation.rb +135 -45
- data/lib/active_support/core_ext/module/deprecation.rb +3 -3
- data/lib/active_support/core_ext/module/introspection.rb +9 -25
- 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/module.rb +14 -10
- data/lib/active_support/core_ext/name_error.rb +22 -2
- 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 +37 -50
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +70 -19
- 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 +100 -34
- 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 +227 -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 +94 -24
- data/lib/active_support/core_ext/object/with_options.rb +45 -5
- data/lib/active_support/core_ext/object.rb +14 -12
- data/lib/active_support/core_ext/range/compare_range.rb +61 -0
- 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 +2 -22
- 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/range.rb +7 -4
- 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/access.rb +41 -39
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +17 -13
- data/lib/active_support/core_ext/string/exclude.rb +5 -3
- data/lib/active_support/core_ext/string/filters.rb +55 -6
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +66 -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 +114 -54
- 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 -1
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +123 -110
- data/lib/active_support/core_ext/time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/time/conversions.rb +23 -14
- data/lib/active_support/core_ext/time/zones.rb +42 -26
- data/lib/active_support/core_ext/time.rb +7 -5
- data/lib/active_support/core_ext/uri.rb +6 -8
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies/autoload.rb +3 -1
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies.rb +196 -166
- data/lib/active_support/deprecation/behaviors.rb +48 -15
- 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 +66 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +14 -11
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +125 -0
- data/lib/active_support/duration/iso8601_serializer.rb +55 -0
- data/lib/active_support/duration.rb +354 -34
- 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 +17 -0
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +158 -35
- data/lib/active_support/i18n.rb +8 -6
- data/lib/active_support/i18n_railtie.rb +38 -20
- data/lib/active_support/inflections.rb +19 -12
- data/lib/active_support/inflector/inflections.rb +79 -30
- data/lib/active_support/inflector/methods.rb +197 -129
- data/lib/active_support/inflector/transliterate.rb +48 -27
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +21 -25
- data/lib/active_support/json/encoding.rb +84 -292
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +26 -28
- data/lib/active_support/lazy_load_hooks.rb +51 -21
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +13 -10
- 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 +34 -0
- data/lib/active_support/message_encryptor.rb +173 -50
- data/lib/active_support/message_verifier.rb +159 -22
- 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/chars.rb +38 -26
- data/lib/active_support/multibyte/unicode.rb +138 -146
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +23 -16
- data/lib/active_support/notifications/instrumenter.rb +29 -8
- data/lib/active_support/notifications.rb +22 -13
- data/lib/active_support/number_helper/number_converter.rb +184 -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 +29 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +59 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +14 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +54 -0
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +125 -391
- 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 +31 -5
- data/lib/active_support/per_thread_registry.rb +19 -11
- 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 +31 -0
- data/lib/active_support/string_inquirer.rb +11 -3
- data/lib/active_support/subscriber.rb +54 -17
- data/lib/active_support/tagged_logging.rb +14 -11
- data/lib/active_support/test_case.rb +42 -37
- data/lib/active_support/testing/assertions.rb +126 -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 +14 -10
- data/lib/active_support/testing/file_fixtures.rb +36 -0
- data/lib/active_support/testing/isolation.rb +55 -86
- data/lib/active_support/testing/method_call_assertions.rb +43 -0
- data/lib/active_support/testing/setup_and_teardown.rb +30 -10
- data/lib/active_support/testing/stream.rb +44 -0
- data/lib/active_support/testing/tagged_logging.rb +5 -3
- data/lib/active_support/testing/time_helpers.rb +200 -0
- data/lib/active_support/time.rb +13 -13
- data/lib/active_support/time_with_zone.rb +223 -73
- data/lib/active_support/values/time_zone.rb +261 -126
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +6 -7
- 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
- data/lib/active_support/xml_mini.rb +69 -51
- data/lib/active_support.rb +29 -3
- metadata +84 -54
- 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/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/debugger.rb +0 -10
- data/lib/active_support/core_ext/logger.rb +0 -67
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- 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/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/MIT-LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2005-
|
1
|
+
Copyright (c) 2005-2018 David Heinemeier Hansson
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -10,18 +10,18 @@ outside of Rails.
|
|
10
10
|
|
11
11
|
The latest version of Active Support can be installed with RubyGems:
|
12
12
|
|
13
|
-
|
13
|
+
$ gem install activesupport
|
14
14
|
|
15
15
|
Source code can be downloaded as part of the Rails project on GitHub:
|
16
16
|
|
17
|
-
* https://github.com/rails/rails/tree/
|
17
|
+
* https://github.com/rails/rails/tree/5-2-stable/activesupport
|
18
18
|
|
19
19
|
|
20
20
|
== License
|
21
21
|
|
22
22
|
Active Support is released under the MIT license:
|
23
23
|
|
24
|
-
*
|
24
|
+
* https://opensource.org/licenses/MIT
|
25
25
|
|
26
26
|
|
27
27
|
== Support
|
@@ -30,6 +30,10 @@ API documentation is at:
|
|
30
30
|
|
31
31
|
* http://api.rubyonrails.org
|
32
32
|
|
33
|
-
Bug reports
|
33
|
+
Bug reports for the Ruby on Rails project can be filed here:
|
34
34
|
|
35
35
|
* https://github.com/rails/rails/issues
|
36
|
+
|
37
|
+
Feature requests should be discussed on the rails-core mailing list here:
|
38
|
+
|
39
|
+
* https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-core
|
data/lib/active_support/all.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# Wrapping an array in an +ArrayInquirer+ gives a friendlier way to check
|
5
|
+
# its string-like contents:
|
6
|
+
#
|
7
|
+
# variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
|
8
|
+
#
|
9
|
+
# variants.phone? # => true
|
10
|
+
# variants.tablet? # => true
|
11
|
+
# variants.desktop? # => false
|
12
|
+
class ArrayInquirer < Array
|
13
|
+
# Passes each element of +candidates+ collection to ArrayInquirer collection.
|
14
|
+
# The method returns true if any element from the ArrayInquirer collection
|
15
|
+
# is equal to the stringified or symbolized form of any element in the +candidates+ collection.
|
16
|
+
#
|
17
|
+
# If +candidates+ collection is not given, method returns true.
|
18
|
+
#
|
19
|
+
# variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet])
|
20
|
+
#
|
21
|
+
# variants.any? # => true
|
22
|
+
# variants.any?(:phone, :tablet) # => true
|
23
|
+
# variants.any?('phone', 'desktop') # => true
|
24
|
+
# variants.any?(:desktop, :watch) # => false
|
25
|
+
def any?(*candidates)
|
26
|
+
if candidates.none?
|
27
|
+
super
|
28
|
+
else
|
29
|
+
candidates.any? do |candidate|
|
30
|
+
include?(candidate.to_sym) || include?(candidate.to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def respond_to_missing?(name, include_private = false)
|
37
|
+
(name[-1] == "?") || super
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(name, *args)
|
41
|
+
if name[-1] == "?"
|
42
|
+
any?(name[0..-2])
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
# Backtraces often include many lines that are not relevant for the context
|
3
5
|
# under review. This makes it hard to find the signal amongst the backtrace
|
@@ -12,20 +14,20 @@ module ActiveSupport
|
|
12
14
|
# is to exclude the output of a noisy library from the backtrace, so that you
|
13
15
|
# can focus on the rest.
|
14
16
|
#
|
15
|
-
# bc = BacktraceCleaner.new
|
16
|
-
# bc.add_filter { |line| line.gsub(Rails.root, '') }
|
17
|
-
# bc.add_silencer { |line| line =~ /
|
18
|
-
# bc.clean(exception.backtrace) #
|
17
|
+
# bc = ActiveSupport::BacktraceCleaner.new
|
18
|
+
# bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
|
19
|
+
# bc.add_silencer { |line| line =~ /puma|rubygems/ } # skip any lines from puma or rubygems
|
20
|
+
# bc.clean(exception.backtrace) # perform the cleanup
|
19
21
|
#
|
20
22
|
# To reconfigure an existing BacktraceCleaner (like the default one in Rails)
|
21
23
|
# and show as much data as possible, you can always call
|
22
24
|
# <tt>BacktraceCleaner#remove_silencers!</tt>, which will restore the
|
23
25
|
# backtrace to a pristine state. If you need to reconfigure an existing
|
24
26
|
# BacktraceCleaner so that it does not filter or modify the paths of any lines
|
25
|
-
# of the backtrace, you can call BacktraceCleaner#remove_filters
|
26
|
-
# methods will give you a completely untouched backtrace.
|
27
|
+
# of the backtrace, you can call <tt>BacktraceCleaner#remove_filters!</tt>
|
28
|
+
# These two methods will give you a completely untouched backtrace.
|
27
29
|
#
|
28
|
-
# Inspired by the Quiet Backtrace gem by
|
30
|
+
# Inspired by the Quiet Backtrace gem by thoughtbot.
|
29
31
|
class BacktraceCleaner
|
30
32
|
def initialize
|
31
33
|
@filters, @silencers = [], []
|
@@ -59,20 +61,20 @@ module ActiveSupport
|
|
59
61
|
# Adds a silencer from the block provided. If the silencer returns +true+
|
60
62
|
# for a given line, it will be excluded from the clean backtrace.
|
61
63
|
#
|
62
|
-
# # Will reject all lines that include the word "
|
63
|
-
# backtrace_cleaner.add_silencer { |line| line =~ /
|
64
|
+
# # Will reject all lines that include the word "puma", like "/gems/puma/server.rb" or "/app/my_puma_server/rb"
|
65
|
+
# backtrace_cleaner.add_silencer { |line| line =~ /puma/ }
|
64
66
|
def add_silencer(&block)
|
65
67
|
@silencers << block
|
66
68
|
end
|
67
69
|
|
68
|
-
#
|
69
|
-
#
|
70
|
+
# Removes all silencers, but leaves in the filters. Useful if your
|
71
|
+
# context of debugging suddenly expands as you suspect a bug in one of
|
70
72
|
# the libraries you use.
|
71
73
|
def remove_silencers!
|
72
74
|
@silencers = []
|
73
75
|
end
|
74
76
|
|
75
|
-
# Removes all filters, but leaves in silencers. Useful if you suddenly
|
77
|
+
# Removes all filters, but leaves in the silencers. Useful if you suddenly
|
76
78
|
# need to see entire filepaths in the backtrace that you had already
|
77
79
|
# filtered out.
|
78
80
|
def remove_filters!
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/benchmark"
|
4
|
+
require "active_support/core_ext/hash/keys"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
7
|
module Benchmarkable
|
@@ -38,22 +40,12 @@ module ActiveSupport
|
|
38
40
|
options[:level] ||= :info
|
39
41
|
|
40
42
|
result = nil
|
41
|
-
ms = Benchmark.ms { result = options[:silence] ? silence { yield } : yield }
|
42
|
-
logger.send(options[:level],
|
43
|
+
ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
|
44
|
+
logger.send(options[:level], "%s (%.1fms)" % [ message, ms ])
|
43
45
|
result
|
44
46
|
else
|
45
47
|
yield
|
46
48
|
end
|
47
49
|
end
|
48
|
-
|
49
|
-
# Silence the logger during the execution of the block.
|
50
|
-
def silence
|
51
|
-
message = "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1."
|
52
|
-
ActiveSupport::Deprecation.warn message
|
53
|
-
old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
|
54
|
-
yield
|
55
|
-
ensure
|
56
|
-
logger.level = old_logger_level if logger
|
57
|
-
end
|
58
50
|
end
|
59
51
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/marshal"
|
4
|
+
require "active_support/core_ext/file/atomic"
|
5
|
+
require "active_support/core_ext/string/conversions"
|
6
|
+
require "uri/common"
|
5
7
|
|
6
8
|
module ActiveSupport
|
7
9
|
module Cache
|
@@ -10,58 +12,48 @@ module ActiveSupport
|
|
10
12
|
# FileStore implements the Strategy::LocalCache strategy which implements
|
11
13
|
# an in-memory cache inside of a block.
|
12
14
|
class FileStore < Store
|
15
|
+
prepend Strategy::LocalCache
|
13
16
|
attr_reader :cache_path
|
14
17
|
|
15
18
|
DIR_FORMATTER = "%03X"
|
16
19
|
FILENAME_MAX_SIZE = 228 # max filename size on file system is 255, minus room for timestamp and random characters appended by Tempfile (used by atomic write)
|
17
|
-
|
20
|
+
FILEPATH_MAX_SIZE = 900 # max is 1024, plus some room
|
21
|
+
EXCLUDED_DIRS = [".", ".."].freeze
|
22
|
+
GITKEEP_FILES = [".gitkeep", ".keep"].freeze
|
18
23
|
|
19
24
|
def initialize(cache_path, options = nil)
|
20
25
|
super(options)
|
21
26
|
@cache_path = cache_path.to_s
|
22
|
-
extend Strategy::LocalCache
|
23
27
|
end
|
24
28
|
|
29
|
+
# Deletes all items from the cache. In this case it deletes all the entries in the specified
|
30
|
+
# file store directory except for .keep or .gitkeep. Be careful which directory is specified in your
|
31
|
+
# config file when using +FileStore+ because everything in that directory will be deleted.
|
25
32
|
def clear(options = nil)
|
26
|
-
root_dirs =
|
27
|
-
FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
|
33
|
+
root_dirs = exclude_from(cache_path, EXCLUDED_DIRS + GITKEEP_FILES)
|
34
|
+
FileUtils.rm_r(root_dirs.collect { |f| File.join(cache_path, f) })
|
35
|
+
rescue Errno::ENOENT
|
28
36
|
end
|
29
37
|
|
38
|
+
# Preemptively iterates through all stored keys and removes the ones which have expired.
|
30
39
|
def cleanup(options = nil)
|
31
40
|
options = merged_options(options)
|
32
41
|
search_dir(cache_path) do |fname|
|
33
|
-
|
34
|
-
|
35
|
-
delete_entry(key, options) if entry && entry.expired?
|
42
|
+
entry = read_entry(fname, options)
|
43
|
+
delete_entry(fname, options) if entry && entry.expired?
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
47
|
+
# Increments an already existing integer value that is stored in the cache.
|
48
|
+
# If the key is not found nothing is done.
|
39
49
|
def increment(name, amount = 1, options = nil)
|
40
|
-
|
41
|
-
lock_file(file_name) do
|
42
|
-
options = merged_options(options)
|
43
|
-
if num = read(name, options)
|
44
|
-
num = num.to_i + amount
|
45
|
-
write(name, num, options)
|
46
|
-
num
|
47
|
-
else
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
end
|
50
|
+
modify_value(name, amount, options)
|
51
51
|
end
|
52
52
|
|
53
|
+
# Decrements an already existing integer value that is stored in the cache.
|
54
|
+
# If the key is not found nothing is done.
|
53
55
|
def decrement(name, amount = 1, options = nil)
|
54
|
-
|
55
|
-
lock_file(file_name) do
|
56
|
-
options = merged_options(options)
|
57
|
-
if num = read(name, options)
|
58
|
-
num = num.to_i - amount
|
59
|
-
write(name, num, options)
|
60
|
-
num
|
61
|
-
else
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
end
|
56
|
+
modify_value(name, -amount, options)
|
65
57
|
end
|
66
58
|
|
67
59
|
def delete_matched(matcher, options = nil)
|
@@ -70,17 +62,16 @@ module ActiveSupport
|
|
70
62
|
matcher = key_matcher(matcher, options)
|
71
63
|
search_dir(cache_path) do |path|
|
72
64
|
key = file_path_key(path)
|
73
|
-
delete_entry(
|
65
|
+
delete_entry(path, options) if key.match(matcher)
|
74
66
|
end
|
75
67
|
end
|
76
68
|
end
|
77
69
|
|
78
|
-
|
70
|
+
private
|
79
71
|
|
80
72
|
def read_entry(key, options)
|
81
|
-
|
82
|
-
|
83
|
-
File.open(file_name) { |f| Marshal.load(f) }
|
73
|
+
if File.exist?(key)
|
74
|
+
File.open(key) { |f| Marshal.load(f) }
|
84
75
|
end
|
85
76
|
rescue => e
|
86
77
|
logger.error("FileStoreError (#{e}): #{e.message}") if logger
|
@@ -88,32 +79,30 @@ module ActiveSupport
|
|
88
79
|
end
|
89
80
|
|
90
81
|
def write_entry(key, entry, options)
|
91
|
-
|
92
|
-
ensure_cache_path(File.dirname(
|
93
|
-
File.atomic_write(
|
82
|
+
return false if options[:unless_exist] && File.exist?(key)
|
83
|
+
ensure_cache_path(File.dirname(key))
|
84
|
+
File.atomic_write(key, cache_path) { |f| Marshal.dump(entry, f) }
|
94
85
|
true
|
95
86
|
end
|
96
87
|
|
97
88
|
def delete_entry(key, options)
|
98
|
-
|
99
|
-
if File.exist?(file_name)
|
89
|
+
if File.exist?(key)
|
100
90
|
begin
|
101
|
-
File.delete(
|
102
|
-
delete_empty_directories(File.dirname(
|
91
|
+
File.delete(key)
|
92
|
+
delete_empty_directories(File.dirname(key))
|
103
93
|
true
|
104
94
|
rescue => e
|
105
95
|
# Just in case the error was caused by another process deleting the file first.
|
106
|
-
raise e if File.exist?(
|
96
|
+
raise e if File.exist?(key)
|
107
97
|
false
|
108
98
|
end
|
109
99
|
end
|
110
100
|
end
|
111
101
|
|
112
|
-
private
|
113
102
|
# Lock a file for a block so only one process can modify it at a time.
|
114
|
-
def lock_file(file_name, &block)
|
103
|
+
def lock_file(file_name, &block)
|
115
104
|
if File.exist?(file_name)
|
116
|
-
File.open(file_name,
|
105
|
+
File.open(file_name, "r+") do |f|
|
117
106
|
begin
|
118
107
|
f.flock File::LOCK_EX
|
119
108
|
yield
|
@@ -127,8 +116,14 @@ module ActiveSupport
|
|
127
116
|
end
|
128
117
|
|
129
118
|
# Translate a key into a file path.
|
130
|
-
def
|
119
|
+
def normalize_key(key, options)
|
120
|
+
key = super
|
131
121
|
fname = URI.encode_www_form_component(key)
|
122
|
+
|
123
|
+
if fname.size > FILEPATH_MAX_SIZE
|
124
|
+
fname = ActiveSupport::Digest.hexdigest(key)
|
125
|
+
end
|
126
|
+
|
132
127
|
hash = Zlib.adler32(fname)
|
133
128
|
hash, dir_1 = hash.divmod(0x1000)
|
134
129
|
dir_2 = hash.modulo(0x1000)
|
@@ -152,7 +147,7 @@ module ActiveSupport
|
|
152
147
|
# Delete empty directories in the cache.
|
153
148
|
def delete_empty_directories(dir)
|
154
149
|
return if File.realpath(dir) == File.realpath(cache_path)
|
155
|
-
if
|
150
|
+
if exclude_from(dir, EXCLUDED_DIRS).empty?
|
156
151
|
Dir.delete(dir) rescue nil
|
157
152
|
delete_empty_directories(File.dirname(dir))
|
158
153
|
end
|
@@ -175,6 +170,27 @@ module ActiveSupport
|
|
175
170
|
end
|
176
171
|
end
|
177
172
|
end
|
173
|
+
|
174
|
+
# Modifies the amount of an already existing integer value that is stored in the cache.
|
175
|
+
# If the key is not found nothing is done.
|
176
|
+
def modify_value(name, amount, options)
|
177
|
+
file_name = normalize_key(name, options)
|
178
|
+
|
179
|
+
lock_file(file_name) do
|
180
|
+
options = merged_options(options)
|
181
|
+
|
182
|
+
if num = read(name, options)
|
183
|
+
num = num.to_i + amount
|
184
|
+
write(name, num, options)
|
185
|
+
num
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# Exclude entries from source directory
|
191
|
+
def exclude_from(source, excludes)
|
192
|
+
Dir.entries(source).reject { |f| excludes.include?(f) }
|
193
|
+
end
|
178
194
|
end
|
179
195
|
end
|
180
196
|
end
|