activesupport 3.2.22.5 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +364 -135
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -4
- data/lib/active_support/backtrace_cleaner.rb +33 -25
- data/lib/active_support/basic_object.rb +7 -17
- data/lib/active_support/benchmarkable.rb +19 -15
- data/lib/active_support/buffered_logger.rb +9 -113
- data/lib/active_support/cache/file_store.rb +14 -14
- data/lib/active_support/cache/mem_cache_store.rb +24 -30
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/cache/strategy/local_cache.rb +48 -37
- data/lib/active_support/cache.rb +228 -183
- data/lib/active_support/callbacks.rb +201 -253
- data/lib/active_support/concern.rb +16 -23
- data/lib/active_support/concurrency/latch.rb +27 -0
- data/lib/active_support/configurable.rb +69 -12
- data/lib/active_support/core_ext/array/access.rb +17 -9
- data/lib/active_support/core_ext/array/conversions.rb +115 -55
- data/lib/active_support/core_ext/array/extract_options.rb +2 -2
- data/lib/active_support/core_ext/array/grouping.rb +21 -22
- data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
- data/lib/active_support/core_ext/array/wrap.rb +13 -16
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/benchmark.rb +7 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -24
- data/lib/active_support/core_ext/class/attribute.rb +40 -32
- data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
- data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
- data/lib/active_support/core_ext/class/subclasses.rb +11 -5
- data/lib/active_support/core_ext/date/calculations.rb +44 -187
- data/lib/active_support/core_ext/date/conversions.rb +16 -38
- data/lib/active_support/core_ext/date/zones.rb +25 -2
- data/lib/active_support/core_ext/date.rb +5 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +77 -62
- data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
- data/lib/active_support/core_ext/date_time/zones.rb +11 -8
- data/lib/active_support/core_ext/date_time.rb +4 -0
- data/lib/active_support/core_ext/enumerable.rb +26 -73
- data/lib/active_support/core_ext/file/atomic.rb +27 -11
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/hash/conversions.rb +145 -79
- data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
- data/lib/active_support/core_ext/hash/diff.rb +5 -4
- data/lib/active_support/core_ext/hash/except.rb +1 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
- data/lib/active_support/core_ext/hash/keys.rb +108 -24
- data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
- data/lib/active_support/core_ext/hash/slice.rb +12 -12
- data/lib/active_support/core_ext/hash.rb +0 -1
- data/lib/active_support/core_ext/integer/inflections.rb +13 -1
- data/lib/active_support/core_ext/integer/time.rb +17 -12
- data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
- data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
- data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
- data/lib/active_support/core_ext/load_error.rb +7 -5
- data/lib/active_support/core_ext/logger.rb +7 -23
- data/lib/active_support/core_ext/marshal.rb +21 -0
- data/lib/active_support/core_ext/module/aliasing.rb +8 -9
- data/lib/active_support/core_ext/module/anonymous.rb +2 -7
- data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
- data/lib/active_support/core_ext/module/delegation.rb +92 -49
- data/lib/active_support/core_ext/module/deprecation.rb +19 -3
- data/lib/active_support/core_ext/module/introspection.rb +17 -27
- data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
- data/lib/active_support/core_ext/module/remove_method.rb +1 -5
- data/lib/active_support/core_ext/module.rb +1 -3
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
- data/lib/active_support/core_ext/numeric/time.rb +6 -6
- data/lib/active_support/core_ext/numeric.rb +1 -0
- data/lib/active_support/core_ext/object/acts_like.rb +4 -4
- data/lib/active_support/core_ext/object/blank.rb +7 -23
- data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
- data/lib/active_support/core_ext/object/duplicable.rb +1 -30
- data/lib/active_support/core_ext/object/inclusion.rb +8 -7
- data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
- data/lib/active_support/core_ext/object/to_json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +5 -2
- data/lib/active_support/core_ext/object/try.rb +46 -25
- data/lib/active_support/core_ext/object/with_options.rb +7 -8
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/proc.rb +3 -0
- data/lib/active_support/core_ext/range/conversions.rb +0 -2
- data/lib/active_support/core_ext/range/include_range.rb +3 -1
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +0 -2
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/conversions.rb +27 -38
- data/lib/active_support/core_ext/string/encoding.rb +6 -9
- data/lib/active_support/core_ext/string/filters.rb +24 -18
- data/lib/active_support/core_ext/string/indent.rb +43 -0
- data/lib/active_support/core_ext/string/inflections.rb +70 -60
- data/lib/active_support/core_ext/string/inquiry.rb +2 -2
- data/lib/active_support/core_ext/string/multibyte.rb +41 -64
- data/lib/active_support/core_ext/string/output_safety.rb +59 -51
- data/lib/active_support/core_ext/string/zones.rb +13 -0
- data/lib/active_support/core_ext/string.rb +2 -3
- data/lib/active_support/core_ext/struct.rb +6 -0
- data/lib/active_support/core_ext/thread.rb +74 -0
- data/lib/active_support/core_ext/time/calculations.rb +108 -184
- data/lib/active_support/core_ext/time/conversions.rb +27 -51
- data/lib/active_support/core_ext/time/marshal.rb +0 -27
- data/lib/active_support/core_ext/time/zones.rb +27 -17
- data/lib/active_support/core_ext/time.rb +5 -0
- data/lib/active_support/core_ext/uri.rb +13 -17
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/dependencies.rb +160 -141
- data/lib/active_support/deprecation/behaviors.rb +44 -30
- data/lib/active_support/deprecation/instance_delegator.rb +24 -0
- data/lib/active_support/deprecation/method_wrappers.rb +33 -18
- data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
- data/lib/active_support/deprecation/reporting.rb +40 -11
- data/lib/active_support/deprecation.rb +39 -14
- data/lib/active_support/descendants_tracker.rb +34 -19
- data/lib/active_support/duration.rb +6 -8
- data/lib/active_support/file_update_checker.rb +63 -47
- data/lib/active_support/gzip.rb +11 -5
- data/lib/active_support/hash_with_indifferent_access.rb +127 -42
- data/lib/active_support/i18n.rb +4 -0
- data/lib/active_support/i18n_railtie.rb +5 -22
- data/lib/active_support/inflections.rb +14 -12
- data/lib/active_support/inflector/inflections.rb +108 -71
- data/lib/active_support/inflector/methods.rb +181 -160
- data/lib/active_support/inflector/transliterate.rb +16 -17
- data/lib/active_support/json/decoding.rb +18 -17
- data/lib/active_support/json/encoding.rb +93 -39
- data/lib/active_support/json/variable.rb +10 -1
- data/lib/active_support/key_generator.rb +75 -0
- data/lib/active_support/lazy_load_hooks.rb +21 -19
- data/lib/active_support/locale/en.yml +100 -3
- data/lib/active_support/log_subscriber/test_helper.rb +18 -15
- data/lib/active_support/log_subscriber.rb +35 -52
- data/lib/active_support/logger.rb +57 -0
- data/lib/active_support/logger_silence.rb +24 -0
- data/lib/active_support/message_encryptor.rb +38 -35
- data/lib/active_support/message_verifier.rb +9 -15
- data/lib/active_support/multibyte/chars.rb +80 -333
- data/lib/active_support/multibyte/unicode.rb +74 -64
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/notifications/fanout.rb +112 -18
- data/lib/active_support/notifications/instrumenter.rb +33 -14
- data/lib/active_support/notifications.rb +79 -26
- data/lib/active_support/number_helper.rb +637 -0
- data/lib/active_support/ordered_hash.rb +8 -190
- data/lib/active_support/ordered_options.rb +21 -23
- data/lib/active_support/per_thread_registry.rb +52 -0
- data/lib/active_support/proxy_object.rb +13 -0
- data/lib/active_support/rails.rb +27 -0
- data/lib/active_support/railtie.rb +12 -32
- data/lib/active_support/rescuable.rb +9 -4
- data/lib/active_support/string_inquirer.rb +13 -8
- data/lib/active_support/subscriber.rb +93 -0
- data/lib/active_support/tagged_logging.rb +51 -73
- data/lib/active_support/test_case.rb +46 -17
- data/lib/active_support/testing/assertions.rb +56 -26
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +54 -0
- data/lib/active_support/testing/declarative.rb +1 -1
- data/lib/active_support/testing/deprecation.rb +0 -19
- data/lib/active_support/testing/isolation.rb +29 -58
- data/lib/active_support/testing/pending.rb +5 -43
- data/lib/active_support/testing/setup_and_teardown.rb +6 -92
- data/lib/active_support/testing/tagged_logging.rb +25 -0
- data/lib/active_support/time.rb +6 -21
- data/lib/active_support/time_with_zone.rb +80 -43
- data/lib/active_support/values/time_zone.rb +81 -60
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +7 -6
- data/lib/active_support/xml_mini/jdom.rb +9 -11
- data/lib/active_support/xml_mini/libxml.rb +1 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
- data/lib/active_support/xml_mini/nokogiri.rb +1 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
- data/lib/active_support/xml_mini/rexml.rb +6 -8
- data/lib/active_support/xml_mini.rb +35 -17
- data/lib/active_support.rb +8 -21
- metadata +104 -72
- data/lib/active_support/base64.rb +0 -54
- data/lib/active_support/core_ext/array/random_access.rb +0 -30
- data/lib/active_support/core_ext/date/freeze.rb +0 -33
- data/lib/active_support/core_ext/exception.rb +0 -3
- data/lib/active_support/core_ext/file/path.rb +0 -5
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- data/lib/active_support/core_ext/float.rb +0 -1
- data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
- data/lib/active_support/core_ext/io.rb +0 -15
- data/lib/active_support/core_ext/module/method_names.rb +0 -14
- data/lib/active_support/core_ext/module/synchronization.rb +0 -45
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- data/lib/active_support/core_ext/process.rb +0 -1
- data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
- data/lib/active_support/core_ext/range/cover.rb +0 -3
- data/lib/active_support/core_ext/rexml.rb +0 -46
- data/lib/active_support/core_ext/string/interpolation.rb +0 -2
- data/lib/active_support/core_ext/string/xchar.rb +0 -18
- data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
- data/lib/active_support/memoizable.rb +0 -116
- data/lib/active_support/multibyte/exceptions.rb +0 -8
- data/lib/active_support/multibyte/utils.rb +0 -60
- data/lib/active_support/ruby/shim.rb +0 -22
- data/lib/active_support/security_utils.rb +0 -27
- data/lib/active_support/testing/mochaing.rb +0 -7
- data/lib/active_support/testing/performance/jruby.rb +0 -115
- data/lib/active_support/testing/performance/rubinius.rb +0 -113
- data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
- data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
- data/lib/active_support/testing/performance/ruby.rb +0 -152
- data/lib/active_support/testing/performance.rb +0 -317
- data/lib/active_support/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -24
|
@@ -1,49 +1,63 @@
|
|
|
1
1
|
require "active_support/notifications"
|
|
2
|
-
require "active_support/core_ext/array/wrap"
|
|
3
2
|
|
|
4
3
|
module ActiveSupport
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
class Deprecation
|
|
5
|
+
# Default warning behaviors per Rails.env.
|
|
6
|
+
DEFAULT_BEHAVIORS = {
|
|
7
|
+
:stderr => Proc.new { |message, callstack|
|
|
8
|
+
$stderr.puts(message)
|
|
9
|
+
$stderr.puts callstack.join("\n ") if debug
|
|
10
|
+
},
|
|
11
|
+
:log => Proc.new { |message, callstack|
|
|
12
|
+
logger =
|
|
13
|
+
if defined?(Rails) && Rails.logger
|
|
14
|
+
Rails.logger
|
|
15
|
+
else
|
|
16
|
+
require 'active_support/logger'
|
|
17
|
+
ActiveSupport::Logger.new($stderr)
|
|
18
|
+
end
|
|
19
|
+
logger.warn message
|
|
20
|
+
logger.debug callstack.join("\n ") if debug
|
|
21
|
+
},
|
|
22
|
+
:notify => Proc.new { |message, callstack|
|
|
23
|
+
ActiveSupport::Notifications.instrument("deprecation.rails",
|
|
24
|
+
:message => message, :callstack => callstack)
|
|
25
|
+
},
|
|
26
|
+
:silence => Proc.new { |message, callstack| }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module Behavior
|
|
7
30
|
# Whether to print a backtrace along with the warning.
|
|
8
31
|
attr_accessor :debug
|
|
9
32
|
|
|
10
|
-
# Returns the
|
|
33
|
+
# Returns the current behavior or if one isn't set, defaults to +:stderr+.
|
|
11
34
|
def behavior
|
|
12
35
|
@behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
|
|
13
36
|
end
|
|
14
37
|
|
|
15
|
-
# Sets the behavior to the specified value. Can be a single value
|
|
38
|
+
# Sets the behavior to the specified value. Can be a single value, array,
|
|
39
|
+
# or an object that responds to +call+.
|
|
40
|
+
#
|
|
41
|
+
# Available behaviors:
|
|
16
42
|
#
|
|
17
|
-
#
|
|
43
|
+
# [+stderr+] Log all deprecation warnings to +$stderr+.
|
|
44
|
+
# [+log+] Log all deprecation warnings to +Rails.logger+.
|
|
45
|
+
# [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
|
|
46
|
+
# [+silence+] Do nothing.
|
|
47
|
+
#
|
|
48
|
+
# Setting behaviors only affects deprecations that happen after boot time.
|
|
49
|
+
# Deprecation warnings raised by gems are not affected by this setting
|
|
50
|
+
# because they happen before Rails boots up.
|
|
18
51
|
#
|
|
19
52
|
# ActiveSupport::Deprecation.behavior = :stderr
|
|
20
53
|
# ActiveSupport::Deprecation.behavior = [:stderr, :log]
|
|
54
|
+
# ActiveSupport::Deprecation.behavior = MyCustomHandler
|
|
55
|
+
# ActiveSupport::Deprecation.behavior = proc { |message, callstack|
|
|
56
|
+
# # custom stuff
|
|
57
|
+
# }
|
|
21
58
|
def behavior=(behavior)
|
|
22
|
-
@behavior = Array
|
|
59
|
+
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
|
|
23
60
|
end
|
|
24
61
|
end
|
|
25
|
-
|
|
26
|
-
# Default warning behaviors per Rails.env.
|
|
27
|
-
DEFAULT_BEHAVIORS = {
|
|
28
|
-
:stderr => Proc.new { |message, callstack|
|
|
29
|
-
$stderr.puts(message)
|
|
30
|
-
$stderr.puts callstack.join("\n ") if debug
|
|
31
|
-
},
|
|
32
|
-
:log => Proc.new { |message, callstack|
|
|
33
|
-
logger =
|
|
34
|
-
if defined?(Rails) && Rails.logger
|
|
35
|
-
Rails.logger
|
|
36
|
-
else
|
|
37
|
-
require 'logger'
|
|
38
|
-
Logger.new($stderr)
|
|
39
|
-
end
|
|
40
|
-
logger.warn message
|
|
41
|
-
logger.debug callstack.join("\n ") if debug
|
|
42
|
-
},
|
|
43
|
-
:notify => Proc.new { |message, callstack|
|
|
44
|
-
ActiveSupport::Notifications.instrument("deprecation.rails",
|
|
45
|
-
:message => message, :callstack => callstack)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
62
|
end
|
|
49
63
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'active_support/core_ext/kernel/singleton_class'
|
|
2
|
+
require 'active_support/core_ext/module/delegation'
|
|
3
|
+
|
|
4
|
+
module ActiveSupport
|
|
5
|
+
class Deprecation
|
|
6
|
+
module InstanceDelegator # :nodoc:
|
|
7
|
+
def self.included(base)
|
|
8
|
+
base.extend(ClassMethods)
|
|
9
|
+
base.public_class_method :new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module ClassMethods # :nodoc:
|
|
13
|
+
def include(included_module)
|
|
14
|
+
included_module.instance_methods.each { |m| method_added(m) }
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def method_added(method_name)
|
|
19
|
+
singleton_class.delegate(method_name, to: :instance)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
require 'active_support/core_ext/module/deprecation'
|
|
2
1
|
require 'active_support/core_ext/module/aliasing'
|
|
3
2
|
require 'active_support/core_ext/array/extract_options'
|
|
4
3
|
|
|
5
4
|
module ActiveSupport
|
|
6
|
-
class
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
class Deprecation
|
|
6
|
+
module MethodWrapper
|
|
7
|
+
# Declare that a method has been deprecated.
|
|
8
|
+
#
|
|
9
|
+
# module Fred
|
|
10
|
+
# extend self
|
|
11
|
+
#
|
|
12
|
+
# def foo; end
|
|
13
|
+
# def bar; end
|
|
14
|
+
# def baz; end
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
|
|
18
|
+
# # => [:foo, :bar, :baz]
|
|
19
|
+
#
|
|
20
|
+
# Fred.foo
|
|
21
|
+
# # => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
|
|
22
|
+
#
|
|
23
|
+
# Fred.bar
|
|
24
|
+
# # => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
|
|
25
|
+
#
|
|
26
|
+
# Fred.baz
|
|
27
|
+
# # => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
|
|
28
|
+
def deprecate_methods(target_module, *method_names)
|
|
29
|
+
options = method_names.extract_options!
|
|
30
|
+
deprecator = options.delete(:deprecator) || ActiveSupport::Deprecation.instance
|
|
31
|
+
method_names += options.keys
|
|
11
32
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
::ActiveSupport::Deprecation.deprecated_method_warning(
|
|
18
|
-
:#{method_name},
|
|
19
|
-
#{options[method_name].inspect}),
|
|
20
|
-
caller
|
|
21
|
-
)
|
|
22
|
-
send(:#{target}_without_deprecation#{punctuation}, *args, &block)
|
|
33
|
+
method_names.each do |method_name|
|
|
34
|
+
target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
|
|
35
|
+
target_module.send(:define_method, "#{target}_with_deprecation#{punctuation}") do |*args, &block|
|
|
36
|
+
deprecator.deprecation_warning(method_name, options[method_name])
|
|
37
|
+
send(:"#{target}_without_deprecation#{punctuation}", *args, &block)
|
|
23
38
|
end
|
|
24
|
-
|
|
39
|
+
end
|
|
25
40
|
end
|
|
26
41
|
end
|
|
27
42
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require 'active_support/inflector/methods'
|
|
2
2
|
|
|
3
3
|
module ActiveSupport
|
|
4
|
-
|
|
4
|
+
class Deprecation
|
|
5
5
|
class DeprecationProxy #:nodoc:
|
|
6
6
|
def self.new(*args, &block)
|
|
7
7
|
object = args.first
|
|
@@ -25,10 +25,20 @@ module ActiveSupport
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
# This DeprecatedObjectProxy transforms object to deprecated object.
|
|
29
|
+
#
|
|
30
|
+
# @old_object = DeprecatedObjectProxy.new(Object.new, "Don't use this object anymore!")
|
|
31
|
+
# @old_object = DeprecatedObjectProxy.new(Object.new, "Don't use this object anymore!", deprecator_instance)
|
|
32
|
+
#
|
|
33
|
+
# When someone executes any method except +inspect+ on proxy object this will
|
|
34
|
+
# trigger +warn+ method on +deprecator_instance+.
|
|
35
|
+
#
|
|
36
|
+
# Default deprecator is <tt>ActiveSupport::Deprecation</tt>
|
|
37
|
+
class DeprecatedObjectProxy < DeprecationProxy
|
|
38
|
+
def initialize(object, message, deprecator = ActiveSupport::Deprecation.instance)
|
|
30
39
|
@object = object
|
|
31
40
|
@message = message
|
|
41
|
+
@deprecator = deprecator
|
|
32
42
|
end
|
|
33
43
|
|
|
34
44
|
private
|
|
@@ -37,15 +47,40 @@ module ActiveSupport
|
|
|
37
47
|
end
|
|
38
48
|
|
|
39
49
|
def warn(callstack, called, args)
|
|
40
|
-
|
|
50
|
+
@deprecator.warn(@message, callstack)
|
|
41
51
|
end
|
|
42
52
|
end
|
|
43
53
|
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
# This DeprecatedInstanceVariableProxy transforms instance variable to
|
|
55
|
+
# deprecated instance variable.
|
|
56
|
+
#
|
|
57
|
+
# class Example
|
|
58
|
+
# def initialize(deprecator)
|
|
59
|
+
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, deprecator)
|
|
60
|
+
# @_request = :a_request
|
|
61
|
+
# end
|
|
62
|
+
#
|
|
63
|
+
# def request
|
|
64
|
+
# @_request
|
|
65
|
+
# end
|
|
66
|
+
#
|
|
67
|
+
# def old_request
|
|
68
|
+
# @request
|
|
69
|
+
# end
|
|
70
|
+
# end
|
|
71
|
+
#
|
|
72
|
+
# When someone execute any method on @request variable this will trigger
|
|
73
|
+
# +warn+ method on +deprecator_instance+ and will fetch <tt>@_request</tt>
|
|
74
|
+
# variable via +request+ method and execute the same method on non-proxy
|
|
75
|
+
# instance variable.
|
|
76
|
+
#
|
|
77
|
+
# Default deprecator is <tt>ActiveSupport::Deprecation</tt>.
|
|
78
|
+
class DeprecatedInstanceVariableProxy < DeprecationProxy
|
|
79
|
+
def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance)
|
|
80
|
+
@instance = instance
|
|
81
|
+
@method = method
|
|
82
|
+
@var = var
|
|
83
|
+
@deprecator = deprecator
|
|
49
84
|
end
|
|
50
85
|
|
|
51
86
|
private
|
|
@@ -54,14 +89,24 @@ module ActiveSupport
|
|
|
54
89
|
end
|
|
55
90
|
|
|
56
91
|
def warn(callstack, called, args)
|
|
57
|
-
|
|
92
|
+
@deprecator.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
|
|
58
93
|
end
|
|
59
94
|
end
|
|
60
95
|
|
|
61
|
-
|
|
62
|
-
|
|
96
|
+
# This DeprecatedConstantProxy transforms constant to deprecated constant.
|
|
97
|
+
#
|
|
98
|
+
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST')
|
|
99
|
+
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST', deprecator_instance)
|
|
100
|
+
#
|
|
101
|
+
# When someone use old constant this will trigger +warn+ method on
|
|
102
|
+
# +deprecator_instance+.
|
|
103
|
+
#
|
|
104
|
+
# Default deprecator is <tt>ActiveSupport::Deprecation</tt>.
|
|
105
|
+
class DeprecatedConstantProxy < DeprecationProxy
|
|
106
|
+
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance)
|
|
63
107
|
@old_const = old_const
|
|
64
108
|
@new_const = new_const
|
|
109
|
+
@deprecator = deprecator
|
|
65
110
|
end
|
|
66
111
|
|
|
67
112
|
def class
|
|
@@ -74,7 +119,7 @@ module ActiveSupport
|
|
|
74
119
|
end
|
|
75
120
|
|
|
76
121
|
def warn(callstack, called, args)
|
|
77
|
-
|
|
122
|
+
@deprecator.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
|
|
78
123
|
end
|
|
79
124
|
end
|
|
80
125
|
end
|
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
module ActiveSupport
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class Deprecation
|
|
3
|
+
module Reporting
|
|
4
|
+
# Whether to print a message (silent mode)
|
|
4
5
|
attr_accessor :silenced
|
|
6
|
+
# Name of gem where method is deprecated
|
|
7
|
+
attr_accessor :gem_name
|
|
5
8
|
|
|
6
|
-
# Outputs a deprecation warning to the output configured by
|
|
9
|
+
# Outputs a deprecation warning to the output configured by
|
|
10
|
+
# <tt>ActiveSupport::Deprecation.behavior</tt>.
|
|
7
11
|
#
|
|
8
|
-
# ActiveSupport::Deprecation.warn(
|
|
12
|
+
# ActiveSupport::Deprecation.warn('something broke!')
|
|
9
13
|
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
|
10
|
-
def warn(message = nil, callstack =
|
|
14
|
+
def warn(message = nil, callstack = nil)
|
|
11
15
|
return if silenced
|
|
16
|
+
|
|
17
|
+
callstack ||= caller(2)
|
|
12
18
|
deprecation_message(callstack, message).tap do |m|
|
|
13
19
|
behavior.each { |b| b.call(m, callstack) }
|
|
14
20
|
end
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
# Silence deprecation warnings within the block.
|
|
24
|
+
#
|
|
25
|
+
# ActiveSupport::Deprecation.warn('something broke!')
|
|
26
|
+
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
|
27
|
+
#
|
|
28
|
+
# ActiveSupport::Deprecation.silence do
|
|
29
|
+
# ActiveSupport::Deprecation.warn('something broke!')
|
|
30
|
+
# end
|
|
31
|
+
# # => nil
|
|
18
32
|
def silence
|
|
19
33
|
old_silenced, @silenced = @silenced, true
|
|
20
34
|
yield
|
|
@@ -22,16 +36,31 @@ module ActiveSupport
|
|
|
22
36
|
@silenced = old_silenced
|
|
23
37
|
end
|
|
24
38
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
when String then "#{warning} (#{message})"
|
|
30
|
-
else warning
|
|
39
|
+
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
|
40
|
+
caller_backtrace ||= caller(2)
|
|
41
|
+
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
|
|
42
|
+
warn(msg, caller_backtrace)
|
|
31
43
|
end
|
|
32
44
|
end
|
|
33
45
|
|
|
34
46
|
private
|
|
47
|
+
# Outputs a deprecation warning message
|
|
48
|
+
#
|
|
49
|
+
# ActiveSupport::Deprecation.deprecated_method_warning(:method_name)
|
|
50
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon}"
|
|
51
|
+
# ActiveSupport::Deprecation.deprecated_method_warning(:method_name, :another_method)
|
|
52
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (use another_method instead)"
|
|
53
|
+
# ActiveSupport::Deprecation.deprecated_method_warning(:method_name, "Optional message")
|
|
54
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (Optional message)"
|
|
55
|
+
def deprecated_method_warning(method_name, message = nil)
|
|
56
|
+
warning = "#{method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
|
|
57
|
+
case message
|
|
58
|
+
when Symbol then "#{warning} (use #{message} instead)"
|
|
59
|
+
when String then "#{warning} (#{message})"
|
|
60
|
+
else warning
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
35
64
|
def deprecation_message(callstack, message = nil)
|
|
36
65
|
message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
|
|
37
66
|
message += '.' unless message =~ /\.$/
|
|
@@ -1,18 +1,43 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'active_support/deprecation/reporting'
|
|
3
|
-
require 'active_support/deprecation/method_wrappers'
|
|
4
|
-
require 'active_support/deprecation/proxy_wrappers'
|
|
1
|
+
require 'singleton'
|
|
5
2
|
|
|
6
3
|
module ActiveSupport
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
# \Deprecation specifies the API used by Rails to deprecate methods, instance
|
|
5
|
+
# variables, objects and constants.
|
|
6
|
+
class Deprecation
|
|
7
|
+
# active_support.rb sets an autoload for ActiveSupport::Deprecation.
|
|
8
|
+
#
|
|
9
|
+
# If these requires were at the top of the file the constant would not be
|
|
10
|
+
# defined by the time their files were loaded. Since some of them reopen
|
|
11
|
+
# ActiveSupport::Deprecation its autoload would be triggered, resulting in
|
|
12
|
+
# a circular require warning for active_support/deprecation.rb.
|
|
13
|
+
#
|
|
14
|
+
# So, we define the constant first, and load dependencies later.
|
|
15
|
+
require 'active_support/deprecation/instance_delegator'
|
|
16
|
+
require 'active_support/deprecation/behaviors'
|
|
17
|
+
require 'active_support/deprecation/reporting'
|
|
18
|
+
require 'active_support/deprecation/method_wrappers'
|
|
19
|
+
require 'active_support/deprecation/proxy_wrappers'
|
|
20
|
+
require 'active_support/core_ext/module/deprecation'
|
|
21
|
+
|
|
22
|
+
include Singleton
|
|
23
|
+
include InstanceDelegator
|
|
24
|
+
include Behavior
|
|
25
|
+
include Reporting
|
|
26
|
+
include MethodWrapper
|
|
13
27
|
|
|
14
|
-
#
|
|
15
|
-
|
|
16
|
-
|
|
28
|
+
# The version the deprecated behavior will be removed, by default.
|
|
29
|
+
attr_accessor :deprecation_horizon
|
|
30
|
+
|
|
31
|
+
# It accepts two parameters on initialization. The first is an version of library
|
|
32
|
+
# and the second is an library name
|
|
33
|
+
#
|
|
34
|
+
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
|
35
|
+
def initialize(deprecation_horizon = '4.1', gem_name = 'Rails')
|
|
36
|
+
self.gem_name = gem_name
|
|
37
|
+
self.deprecation_horizon = deprecation_horizon
|
|
38
|
+
# By default, warnings are not silenced and debugging is off.
|
|
39
|
+
self.silenced = false
|
|
40
|
+
self.debug = false
|
|
41
|
+
end
|
|
17
42
|
end
|
|
18
|
-
end
|
|
43
|
+
end
|
|
@@ -2,35 +2,50 @@ module ActiveSupport
|
|
|
2
2
|
# This module provides an internal implementation to track descendants
|
|
3
3
|
# which is faster than iterating through ObjectSpace.
|
|
4
4
|
module DescendantsTracker
|
|
5
|
-
@@direct_descendants =
|
|
5
|
+
@@direct_descendants = {}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
class << self
|
|
8
|
+
def direct_descendants(klass)
|
|
9
|
+
@@direct_descendants[klass] || []
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
def descendants(klass)
|
|
13
|
+
arr = []
|
|
14
|
+
accumulate_descendants(klass, arr)
|
|
15
|
+
arr
|
|
15
16
|
end
|
|
16
|
-
end
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
def clear
|
|
19
|
+
if defined? ActiveSupport::Dependencies
|
|
20
|
+
@@direct_descendants.each do |klass, descendants|
|
|
21
|
+
if ActiveSupport::Dependencies.autoloaded?(klass)
|
|
22
|
+
@@direct_descendants.delete(klass)
|
|
23
|
+
else
|
|
24
|
+
descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) }
|
|
25
|
+
end
|
|
25
26
|
end
|
|
27
|
+
else
|
|
28
|
+
@@direct_descendants.clear
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# This is the only method that is not thread safe, but is only ever called
|
|
33
|
+
# during the eager loading phase.
|
|
34
|
+
def store_inherited(klass, descendant)
|
|
35
|
+
(@@direct_descendants[klass] ||= []) << descendant
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def accumulate_descendants(klass, acc)
|
|
40
|
+
if direct_descendants = @@direct_descendants[klass]
|
|
41
|
+
acc.concat(direct_descendants)
|
|
42
|
+
direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
|
|
26
43
|
end
|
|
27
|
-
else
|
|
28
|
-
@@direct_descendants.clear
|
|
29
44
|
end
|
|
30
45
|
end
|
|
31
46
|
|
|
32
47
|
def inherited(base)
|
|
33
|
-
self
|
|
48
|
+
DescendantsTracker.store_inherited(self, base)
|
|
34
49
|
super
|
|
35
50
|
end
|
|
36
51
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
require 'active_support/
|
|
1
|
+
require 'active_support/proxy_object'
|
|
2
2
|
require 'active_support/core_ext/array/conversions'
|
|
3
3
|
require 'active_support/core_ext/object/acts_like'
|
|
4
4
|
|
|
5
5
|
module ActiveSupport
|
|
6
6
|
# Provides accurate date and time measurements using Date#advance and
|
|
7
7
|
# Time#advance, respectively. It mainly supports the methods on Numeric.
|
|
8
|
-
# Example:
|
|
9
8
|
#
|
|
10
|
-
# 1.month.ago # equivalent to Time.now.advance(:
|
|
11
|
-
class Duration <
|
|
9
|
+
# 1.month.ago # equivalent to Time.now.advance(months: -1)
|
|
10
|
+
class Duration < ProxyObject
|
|
12
11
|
attr_accessor :value, :parts
|
|
13
|
-
delegate :duplicable?, :to => :value # required when using ActiveSupport's BasicObject on 1.8
|
|
14
12
|
|
|
15
13
|
def initialize(value, parts) #:nodoc:
|
|
16
14
|
@value, @parts = value, parts
|
|
@@ -41,8 +39,8 @@ module ActiveSupport
|
|
|
41
39
|
end
|
|
42
40
|
alias :kind_of? :is_a?
|
|
43
41
|
|
|
44
|
-
# Returns true if
|
|
45
|
-
# same
|
|
42
|
+
# Returns +true+ if +other+ is also a Duration instance with the
|
|
43
|
+
# same +value+, or if <tt>other == value</tt>.
|
|
46
44
|
def ==(other)
|
|
47
45
|
if Duration === other
|
|
48
46
|
other.value == value
|
|
@@ -72,7 +70,7 @@ module ActiveSupport
|
|
|
72
70
|
alias :until :ago
|
|
73
71
|
|
|
74
72
|
def inspect #:nodoc:
|
|
75
|
-
consolidated = parts.inject(::Hash.new(0)) { |h,
|
|
73
|
+
consolidated = parts.inject(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }
|
|
76
74
|
parts = [:years, :months, :days, :minutes, :seconds].map do |length|
|
|
77
75
|
n = consolidated[length]
|
|
78
76
|
"#{n} #{n == 1 ? length.to_s.singularize : length.to_s}" if n.nonzero?
|