activesupport 5.2.3.rc1 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +183 -469
- data/MIT-LICENSE +1 -1
- data/README.rdoc +1 -1
- data/lib/active_support.rb +1 -1
- data/lib/active_support/backtrace_cleaner.rb +23 -0
- data/lib/active_support/cache.rb +40 -18
- data/lib/active_support/cache/file_store.rb +19 -12
- data/lib/active_support/cache/mem_cache_store.rb +5 -0
- data/lib/active_support/cache/memory_store.rb +5 -0
- data/lib/active_support/cache/null_store.rb +5 -0
- data/lib/active_support/cache/redis_cache_store.rb +28 -4
- data/lib/active_support/callbacks.rb +16 -5
- data/lib/active_support/configurable.rb +4 -8
- data/lib/active_support/core_ext/array.rb +1 -1
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +2 -6
- data/lib/active_support/core_ext/class/attribute.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +6 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +24 -17
- data/lib/active_support/core_ext/date_time/calculations.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +71 -67
- data/lib/active_support/core_ext/hash.rb +0 -2
- data/lib/active_support/core_ext/hash/compact.rb +2 -26
- data/lib/active_support/core_ext/hash/keys.rb +0 -29
- data/lib/active_support/core_ext/hash/slice.rb +3 -25
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -29
- data/lib/active_support/core_ext/integer/multiple.rb +1 -1
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/module.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -5
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +8 -14
- data/lib/active_support/core_ext/module/delegation.rb +27 -7
- data/lib/active_support/core_ext/module/introspection.rb +37 -13
- data/lib/active_support/core_ext/module/reachable.rb +1 -6
- data/lib/active_support/core_ext/module/redefine_method.rb +8 -17
- data/lib/active_support/core_ext/numeric.rb +0 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +124 -128
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -25
- data/lib/active_support/core_ext/object/blank.rb +1 -2
- data/lib/active_support/core_ext/object/duplicable.rb +5 -2
- data/lib/active_support/core_ext/object/json.rb +1 -0
- data/lib/active_support/core_ext/object/try.rb +15 -7
- data/lib/active_support/core_ext/object/with_options.rb +1 -1
- data/lib/active_support/core_ext/range/compare_range.rb +1 -1
- data/lib/active_support/core_ext/range/conversions.rb +31 -29
- data/lib/active_support/core_ext/range/include_range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +0 -4
- data/lib/active_support/core_ext/securerandom.rb +23 -3
- data/lib/active_support/core_ext/string/access.rb +8 -0
- data/lib/active_support/core_ext/string/filters.rb +41 -0
- data/lib/active_support/core_ext/string/multibyte.rb +4 -3
- data/lib/active_support/core_ext/string/output_safety.rb +16 -5
- data/lib/active_support/core_ext/string/strip.rb +3 -1
- data/lib/active_support/core_ext/uri.rb +1 -0
- data/lib/active_support/current_attributes.rb +2 -0
- data/lib/active_support/dependencies.rb +28 -11
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/deprecation/behaviors.rb +1 -1
- data/lib/active_support/deprecation/method_wrappers.rb +4 -5
- data/lib/active_support/deprecation/proxy_wrappers.rb +0 -2
- data/lib/active_support/descendants_tracker.rb +6 -5
- data/lib/active_support/duration.rb +4 -2
- data/lib/active_support/duration/iso8601_parser.rb +2 -3
- data/lib/active_support/duration/iso8601_serializer.rb +3 -4
- data/lib/active_support/encrypted_configuration.rb +0 -4
- data/lib/active_support/evented_file_update_checker.rb +25 -7
- data/lib/active_support/execution_wrapper.rb +1 -0
- data/lib/active_support/gem_version.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +16 -28
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +8 -1
- data/lib/active_support/inflector/inflections.rb +1 -4
- data/lib/active_support/inflector/methods.rb +15 -27
- data/lib/active_support/inflector/transliterate.rb +6 -6
- data/lib/active_support/json/decoding.rb +23 -23
- data/lib/active_support/json/encoding.rb +6 -2
- data/lib/active_support/key_generator.rb +0 -32
- data/lib/active_support/lazy_load_hooks.rb +5 -1
- data/lib/active_support/locale/en.rb +31 -0
- data/lib/active_support/log_subscriber.rb +31 -8
- data/lib/active_support/logger.rb +0 -15
- data/lib/active_support/logger_silence.rb +28 -12
- data/lib/active_support/logger_thread_safe_level.rb +26 -4
- data/lib/active_support/message_encryptor.rb +2 -4
- data/lib/active_support/message_verifier.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +29 -48
- data/lib/active_support/multibyte/unicode.rb +44 -281
- data/lib/active_support/notifications.rb +32 -4
- data/lib/active_support/notifications/fanout.rb +40 -2
- data/lib/active_support/notifications/instrumenter.rb +73 -2
- data/lib/active_support/number_helper.rb +7 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
- data/lib/active_support/parameter_filter.rb +124 -0
- data/lib/active_support/rails.rb +0 -6
- data/lib/active_support/reloader.rb +4 -5
- data/lib/active_support/subscriber.rb +16 -26
- data/lib/active_support/tagged_logging.rb +13 -4
- data/lib/active_support/test_case.rb +91 -0
- data/lib/active_support/testing/assertions.rb +15 -1
- data/lib/active_support/testing/deprecation.rb +0 -1
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +28 -1
- data/lib/active_support/testing/parallelization.rb +109 -0
- data/lib/active_support/testing/stream.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +7 -7
- data/lib/active_support/time_with_zone.rb +15 -5
- data/lib/active_support/values/time_zone.rb +12 -7
- data/lib/active_support/xml_mini.rb +2 -9
- data/lib/active_support/xml_mini/jdom.rb +2 -2
- data/lib/active_support/xml_mini/libxml.rb +2 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -4
- data/lib/active_support/xml_mini/nokogiri.rb +2 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -3
- data/lib/active_support/xml_mini/rexml.rb +2 -2
- metadata +9 -6
- data/lib/active_support/values/unicode_tables.dat +0 -0
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -14,7 +14,7 @@ The latest version of Active Support can be installed with RubyGems:
|
|
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/master/activesupport
|
18
18
|
|
19
19
|
|
20
20
|
== License
|
data/lib/active_support.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright (c) 2005-
|
4
|
+
# Copyright (c) 2005-2019 David Heinemeier Hansson
|
5
5
|
#
|
6
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
7
7
|
# a copy of this software and associated documentation files (the
|
@@ -31,6 +31,9 @@ module ActiveSupport
|
|
31
31
|
class BacktraceCleaner
|
32
32
|
def initialize
|
33
33
|
@filters, @silencers = [], []
|
34
|
+
add_gem_filter
|
35
|
+
add_gem_silencer
|
36
|
+
add_stdlib_silencer
|
34
37
|
end
|
35
38
|
|
36
39
|
# Returns the backtrace after all filters and silencers have been run
|
@@ -82,6 +85,26 @@ module ActiveSupport
|
|
82
85
|
end
|
83
86
|
|
84
87
|
private
|
88
|
+
|
89
|
+
FORMATTED_GEMS_PATTERN = /\A[^\/]+ \([\w.]+\) /
|
90
|
+
|
91
|
+
def add_gem_filter
|
92
|
+
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
|
93
|
+
return if gems_paths.empty?
|
94
|
+
|
95
|
+
gems_regexp = %r{(#{gems_paths.join('|')})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)}
|
96
|
+
gems_result = '\3 (\4) \5'
|
97
|
+
add_filter { |line| line.sub(gems_regexp, gems_result) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def add_gem_silencer
|
101
|
+
add_silencer { |line| FORMATTED_GEMS_PATTERN.match?(line) }
|
102
|
+
end
|
103
|
+
|
104
|
+
def add_stdlib_silencer
|
105
|
+
add_silencer { |line| line.start_with?(RbConfig::CONFIG["rubylibdir"]) }
|
106
|
+
end
|
107
|
+
|
85
108
|
def filter_backtrace(backtrace)
|
86
109
|
@filters.each do |f|
|
87
110
|
backtrace = backtrace.map { |line| f.call(line) }
|
data/lib/active_support/cache.rb
CHANGED
@@ -229,6 +229,14 @@ module ActiveSupport
|
|
229
229
|
# ask whether you should force a cache write. Otherwise, it's clearer to
|
230
230
|
# just call <tt>Cache#write</tt>.
|
231
231
|
#
|
232
|
+
# Setting <tt>skip_nil: true</tt> will not cache nil result:
|
233
|
+
#
|
234
|
+
# cache.fetch('foo') { nil }
|
235
|
+
# cache.fetch('bar', skip_nil: true) { nil }
|
236
|
+
# cache.exist?('foo') # => true
|
237
|
+
# cache.exist?('bar') # => false
|
238
|
+
#
|
239
|
+
#
|
232
240
|
# Setting <tt>compress: false</tt> disables compression of the cache entry.
|
233
241
|
#
|
234
242
|
# Setting <tt>:expires_in</tt> will set an expiration time on the cache.
|
@@ -333,8 +341,9 @@ module ActiveSupport
|
|
333
341
|
# the cache with the given key, then that data is returned. Otherwise,
|
334
342
|
# +nil+ is returned.
|
335
343
|
#
|
336
|
-
# Note, if data was written with the <tt>:expires_in
|
337
|
-
# both of these conditions are applied before
|
344
|
+
# Note, if data was written with the <tt>:expires_in</tt> or
|
345
|
+
# <tt>:version</tt> options, both of these conditions are applied before
|
346
|
+
# the data is returned.
|
338
347
|
#
|
339
348
|
# Options are passed to the underlying cache implementation.
|
340
349
|
def read(name, options = nil)
|
@@ -402,8 +411,6 @@ module ActiveSupport
|
|
402
411
|
# to the cache. If you do not want to write the cache when the cache is
|
403
412
|
# not found, use #read_multi.
|
404
413
|
#
|
405
|
-
# Options are passed to the underlying cache implementation.
|
406
|
-
#
|
407
414
|
# Returns a hash with the data for each of the names. For example:
|
408
415
|
#
|
409
416
|
# cache.write("bim", "bam")
|
@@ -413,6 +420,17 @@ module ActiveSupport
|
|
413
420
|
# # => { "bim" => "bam",
|
414
421
|
# # "unknown_key" => "Fallback value for key: unknown_key" }
|
415
422
|
#
|
423
|
+
# Options are passed to the underlying cache implementation. For example:
|
424
|
+
#
|
425
|
+
# cache.fetch_multi("fizz", expires_in: 5.seconds) do |key|
|
426
|
+
# "buzz"
|
427
|
+
# end
|
428
|
+
# # => {"fizz"=>"buzz"}
|
429
|
+
# cache.read("fizz")
|
430
|
+
# # => "buzz"
|
431
|
+
# sleep(6)
|
432
|
+
# cache.read("fizz")
|
433
|
+
# # => nil
|
416
434
|
def fetch_multi(*names)
|
417
435
|
raise ArgumentError, "Missing block: `Cache#fetch_multi` requires a block." unless block_given?
|
418
436
|
|
@@ -420,18 +438,18 @@ module ActiveSupport
|
|
420
438
|
options = merged_options(options)
|
421
439
|
|
422
440
|
instrument :read_multi, names, options do |payload|
|
423
|
-
read_multi_entries(names, options)
|
424
|
-
|
425
|
-
|
441
|
+
reads = read_multi_entries(names, options)
|
442
|
+
writes = {}
|
443
|
+
ordered = names.each_with_object({}) do |name, hash|
|
444
|
+
hash[name] = reads.fetch(name) { writes[name] = yield(name) }
|
445
|
+
end
|
426
446
|
|
427
|
-
|
447
|
+
payload[:hits] = reads.keys
|
448
|
+
payload[:super_operation] = :fetch_multi
|
428
449
|
|
429
|
-
|
430
|
-
results[name] = writes[name] = yield(name)
|
431
|
-
end
|
450
|
+
write_multi(writes, options)
|
432
451
|
|
433
|
-
|
434
|
-
end
|
452
|
+
ordered
|
435
453
|
end
|
436
454
|
end
|
437
455
|
|
@@ -587,9 +605,13 @@ module ActiveSupport
|
|
587
605
|
# Merges the default options with ones specific to a method call.
|
588
606
|
def merged_options(call_options)
|
589
607
|
if call_options
|
590
|
-
options.
|
608
|
+
if options.empty?
|
609
|
+
call_options
|
610
|
+
else
|
611
|
+
options.merge(call_options)
|
612
|
+
end
|
591
613
|
else
|
592
|
-
options
|
614
|
+
options
|
593
615
|
end
|
594
616
|
end
|
595
617
|
|
@@ -634,7 +656,7 @@ module ActiveSupport
|
|
634
656
|
if key.size > 1
|
635
657
|
key = key.collect { |element| expanded_key(element) }
|
636
658
|
else
|
637
|
-
key = key.first
|
659
|
+
key = expanded_key(key.first)
|
638
660
|
end
|
639
661
|
when Hash
|
640
662
|
key = key.sort_by { |k, _| k.to_s }.collect { |k, v| "#{k}=#{v}" }
|
@@ -685,7 +707,7 @@ module ActiveSupport
|
|
685
707
|
end
|
686
708
|
|
687
709
|
def get_entry_value(entry, name, options)
|
688
|
-
instrument(:fetch_hit, name, options) {}
|
710
|
+
instrument(:fetch_hit, name, options) { }
|
689
711
|
entry.value
|
690
712
|
end
|
691
713
|
|
@@ -694,7 +716,7 @@ module ActiveSupport
|
|
694
716
|
yield(name)
|
695
717
|
end
|
696
718
|
|
697
|
-
write(name, result, options)
|
719
|
+
write(name, result, options) unless result.nil? && options[:skip_nil]
|
698
720
|
result
|
699
721
|
end
|
700
722
|
end
|
@@ -26,6 +26,11 @@ module ActiveSupport
|
|
26
26
|
@cache_path = cache_path.to_s
|
27
27
|
end
|
28
28
|
|
29
|
+
# Advertise cache versioning support.
|
30
|
+
def self.supports_cache_versioning?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
29
34
|
# Deletes all items from the cache. In this case it deletes all the entries in the specified
|
30
35
|
# file store directory except for .keep or .gitkeep. Be careful which directory is specified in your
|
31
36
|
# config file when using +FileStore+ because everything in that directory will be deleted.
|
@@ -103,12 +108,10 @@ module ActiveSupport
|
|
103
108
|
def lock_file(file_name, &block)
|
104
109
|
if File.exist?(file_name)
|
105
110
|
File.open(file_name, "r+") do |f|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
f.flock File::LOCK_UN
|
111
|
-
end
|
111
|
+
f.flock File::LOCK_EX
|
112
|
+
yield
|
113
|
+
ensure
|
114
|
+
f.flock File::LOCK_UN
|
112
115
|
end
|
113
116
|
else
|
114
117
|
yield
|
@@ -127,15 +130,19 @@ module ActiveSupport
|
|
127
130
|
hash = Zlib.adler32(fname)
|
128
131
|
hash, dir_1 = hash.divmod(0x1000)
|
129
132
|
dir_2 = hash.modulo(0x1000)
|
130
|
-
fname_paths = []
|
131
133
|
|
132
134
|
# Make sure file name doesn't exceed file system limits.
|
133
|
-
|
134
|
-
fname_paths
|
135
|
-
|
136
|
-
|
135
|
+
if fname.length < FILENAME_MAX_SIZE
|
136
|
+
fname_paths = fname
|
137
|
+
else
|
138
|
+
fname_paths = []
|
139
|
+
begin
|
140
|
+
fname_paths << fname[0, FILENAME_MAX_SIZE]
|
141
|
+
fname = fname[FILENAME_MAX_SIZE..-1]
|
142
|
+
end until fname.blank?
|
143
|
+
end
|
137
144
|
|
138
|
-
File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2,
|
145
|
+
File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, fname_paths)
|
139
146
|
end
|
140
147
|
|
141
148
|
# Translate a file path into a key.
|
@@ -17,7 +17,6 @@ end
|
|
17
17
|
|
18
18
|
require "digest/sha2"
|
19
19
|
require "active_support/core_ext/marshal"
|
20
|
-
require "active_support/core_ext/hash/transform_values"
|
21
20
|
|
22
21
|
module ActiveSupport
|
23
22
|
module Cache
|
@@ -67,6 +66,11 @@ module ActiveSupport
|
|
67
66
|
SCAN_BATCH_SIZE = 1000
|
68
67
|
private_constant :SCAN_BATCH_SIZE
|
69
68
|
|
69
|
+
# Advertise cache versioning support.
|
70
|
+
def self.supports_cache_versioning?
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
70
74
|
# Support raw values in the local cache strategy.
|
71
75
|
module LocalCacheWithRaw # :nodoc:
|
72
76
|
private
|
@@ -156,7 +160,7 @@ module ActiveSupport
|
|
156
160
|
# :url Array -> Redis::Distributed.new([{ url: … }, { url: … }, …])
|
157
161
|
#
|
158
162
|
# No namespace is set by default. Provide one if the Redis cache
|
159
|
-
# server is shared with other apps: <tt>namespace: 'myapp-cache'
|
163
|
+
# server is shared with other apps: <tt>namespace: 'myapp-cache'</tt>.
|
160
164
|
#
|
161
165
|
# Compression is enabled by default with a 1kB threshold, so cached
|
162
166
|
# values larger than 1kB are automatically compressed. Disable by
|
@@ -259,7 +263,14 @@ module ActiveSupport
|
|
259
263
|
def increment(name, amount = 1, options = nil)
|
260
264
|
instrument :increment, name, amount: amount do
|
261
265
|
failsafe :increment do
|
262
|
-
|
266
|
+
options = merged_options(options)
|
267
|
+
key = normalize_key(name, options)
|
268
|
+
|
269
|
+
redis.with do |c|
|
270
|
+
c.incrby(key, amount).tap do
|
271
|
+
write_key_expiry(c, key, options)
|
272
|
+
end
|
273
|
+
end
|
263
274
|
end
|
264
275
|
end
|
265
276
|
end
|
@@ -275,7 +286,14 @@ module ActiveSupport
|
|
275
286
|
def decrement(name, amount = 1, options = nil)
|
276
287
|
instrument :decrement, name, amount: amount do
|
277
288
|
failsafe :decrement do
|
278
|
-
|
289
|
+
options = merged_options(options)
|
290
|
+
key = normalize_key(name, options)
|
291
|
+
|
292
|
+
redis.with do |c|
|
293
|
+
c.decrby(key, amount).tap do
|
294
|
+
write_key_expiry(c, key, options)
|
295
|
+
end
|
296
|
+
end
|
279
297
|
end
|
280
298
|
end
|
281
299
|
end
|
@@ -386,6 +404,12 @@ module ActiveSupport
|
|
386
404
|
end
|
387
405
|
end
|
388
406
|
|
407
|
+
def write_key_expiry(client, key, options)
|
408
|
+
if options[:expires_in] && client.ttl(key).negative?
|
409
|
+
client.expire key, options[:expires_in].to_i
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
389
413
|
# Delete an entry from the cache.
|
390
414
|
def delete_entry(key, options)
|
391
415
|
failsafe :delete_entry, returning: false do
|
@@ -23,6 +23,9 @@ module ActiveSupport
|
|
23
23
|
# +ClassMethods.set_callback+), and run the installed callbacks at the
|
24
24
|
# appropriate times (via +run_callbacks+).
|
25
25
|
#
|
26
|
+
# By default callbacks are halted by throwing +:abort+.
|
27
|
+
# See +ClassMethods.define_callbacks+ for details.
|
28
|
+
#
|
26
29
|
# Three kinds of callbacks are supported: before callbacks, run before a
|
27
30
|
# certain event; after callbacks, run after the event; and around callbacks,
|
28
31
|
# blocks that surround the event, triggering it when they yield. Callback code
|
@@ -497,9 +500,7 @@ module ActiveSupport
|
|
497
500
|
arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) }
|
498
501
|
end
|
499
502
|
|
500
|
-
|
501
|
-
@nested
|
502
|
-
end
|
503
|
+
attr_reader :nested
|
503
504
|
|
504
505
|
def final?
|
505
506
|
!@call_template
|
@@ -578,7 +579,7 @@ module ActiveSupport
|
|
578
579
|
end
|
579
580
|
|
580
581
|
protected
|
581
|
-
|
582
|
+
attr_reader :chain
|
582
583
|
|
583
584
|
private
|
584
585
|
|
@@ -659,9 +660,17 @@ module ActiveSupport
|
|
659
660
|
# * <tt>:if</tt> - A symbol or an array of symbols, each naming an instance
|
660
661
|
# method or a proc; the callback will be called only when they all return
|
661
662
|
# a true value.
|
663
|
+
#
|
664
|
+
# If a proc is given, its body is evaluated in the context of the
|
665
|
+
# current object. It can also optionally accept the current object as
|
666
|
+
# an argument.
|
662
667
|
# * <tt>:unless</tt> - A symbol or an array of symbols, each naming an
|
663
668
|
# instance method or a proc; the callback will be called only when they
|
664
669
|
# all return a false value.
|
670
|
+
#
|
671
|
+
# If a proc is given, its body is evaluated in the context of the
|
672
|
+
# current object. It can also optionally accept the current object as
|
673
|
+
# an argument.
|
665
674
|
# * <tt>:prepend</tt> - If +true+, the callback will be prepended to the
|
666
675
|
# existing chain rather than appended.
|
667
676
|
def set_callback(name, *filter_list, &block)
|
@@ -809,7 +818,9 @@ module ActiveSupport
|
|
809
818
|
names.each do |name|
|
810
819
|
name = name.to_sym
|
811
820
|
|
812
|
-
|
821
|
+
([self] + ActiveSupport::DescendantsTracker.descendants(self)).each do |target|
|
822
|
+
target.set_callbacks name, CallbackChain.new(name, options)
|
823
|
+
end
|
813
824
|
|
814
825
|
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
815
826
|
def _run_#{name}_callbacks(&block)
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
4
|
require "active_support/ordered_options"
|
5
|
-
require "active_support/core_ext/array/extract_options"
|
6
|
-
require "active_support/core_ext/regexp"
|
7
5
|
|
8
6
|
module ActiveSupport
|
9
7
|
# Configurable provides a <tt>config</tt> method to store and retrieve
|
@@ -106,9 +104,7 @@ module ActiveSupport
|
|
106
104
|
# end
|
107
105
|
#
|
108
106
|
# User.hair_colors # => [:brown, :black, :blonde, :red]
|
109
|
-
def config_accessor(*names)
|
110
|
-
options = names.extract_options!
|
111
|
-
|
107
|
+
def config_accessor(*names, instance_reader: true, instance_writer: true, instance_accessor: true) # :doc:
|
112
108
|
names.each do |name|
|
113
109
|
raise NameError.new("invalid config attribute name") unless /\A[_A-Za-z]\w*\z/.match?(name)
|
114
110
|
|
@@ -118,9 +114,9 @@ module ActiveSupport
|
|
118
114
|
singleton_class.class_eval reader, __FILE__, reader_line
|
119
115
|
singleton_class.class_eval writer, __FILE__, writer_line
|
120
116
|
|
121
|
-
|
122
|
-
class_eval reader, __FILE__, reader_line
|
123
|
-
class_eval writer, __FILE__, writer_line
|
117
|
+
if instance_accessor
|
118
|
+
class_eval reader, __FILE__, reader_line if instance_reader
|
119
|
+
class_eval writer, __FILE__, writer_line if instance_writer
|
124
120
|
end
|
125
121
|
send("#{name}=", yield) if block_given?
|
126
122
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "active_support/core_ext/array/wrap"
|
4
4
|
require "active_support/core_ext/array/access"
|
5
5
|
require "active_support/core_ext/array/conversions"
|
6
|
+
require "active_support/core_ext/array/extract"
|
6
7
|
require "active_support/core_ext/array/extract_options"
|
7
8
|
require "active_support/core_ext/array/grouping"
|
8
|
-
require "active_support/core_ext/array/prepend_and_append"
|
9
9
|
require "active_support/core_ext/array/inquiry"
|