activesupport 3.2.22.5 → 4.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 +325 -136
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -2
- data/lib/active_support.rb +8 -21
- 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.rb +203 -171
- data/lib/active_support/cache/file_store.rb +12 -12
- 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/callbacks.rb +195 -247
- 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.rb +1 -0
- data/lib/active_support/core_ext/array.rb +0 -1
- data/lib/active_support/core_ext/array/access.rb +17 -9
- data/lib/active_support/core_ext/array/conversions.rb +113 -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 +11 -14
- data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
- data/lib/active_support/core_ext/class/attribute.rb +12 -8
- 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.rb +6 -0
- data/lib/active_support/core_ext/date/calculations.rb +34 -188
- data/lib/active_support/core_ext/date/conversions.rb +16 -38
- data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date/zones.rb +25 -2
- data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
- data/lib/active_support/core_ext/date_time.rb +5 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
- data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
- data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
- data/lib/active_support/core_ext/date_time/zones.rb +11 -8
- data/lib/active_support/core_ext/enumerable.rb +26 -73
- data/lib/active_support/core_ext/file.rb +0 -1
- data/lib/active_support/core_ext/file/atomic.rb +27 -11
- data/lib/active_support/core_ext/hash.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/infinite_comparable.rb +35 -0
- 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 +19 -0
- data/lib/active_support/core_ext/module.rb +1 -3
- 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 +57 -40
- 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/numeric.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
- data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
- data/lib/active_support/core_ext/numeric/time.rb +6 -6
- data/lib/active_support/core_ext/object.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 +6 -6
- 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/proc.rb +3 -0
- data/lib/active_support/core_ext/range.rb +0 -2
- data/lib/active_support/core_ext/range/conversions.rb +0 -2
- data/lib/active_support/core_ext/range/include_range.rb +1 -1
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/string.rb +2 -2
- data/lib/active_support/core_ext/string/access.rb +95 -90
- data/lib/active_support/core_ext/string/conversions.rb +29 -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/struct.rb +6 -0
- data/lib/active_support/core_ext/thread.rb +74 -0
- data/lib/active_support/core_ext/time.rb +6 -0
- data/lib/active_support/core_ext/time/calculations.rb +105 -193
- data/lib/active_support/core_ext/time/conversions.rb +27 -51
- data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
- 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/uri.rb +13 -17
- data/lib/active_support/dependencies.rb +160 -141
- data/lib/active_support/dependencies/autoload.rb +47 -20
- data/lib/active_support/deprecation.rb +39 -14
- 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/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 +112 -37
- 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.rb +56 -36
- data/lib/active_support/log_subscriber/test_helper.rb +18 -15
- data/lib/active_support/logger.rb +57 -0
- data/lib/active_support/logger_silence.rb +24 -0
- data/lib/active_support/message_encryptor.rb +32 -29
- data/lib/active_support/message_verifier.rb +8 -14
- data/lib/active_support/multibyte.rb +5 -28
- data/lib/active_support/multibyte/chars.rb +80 -333
- data/lib/active_support/multibyte/unicode.rb +74 -64
- data/lib/active_support/notifications.rb +57 -25
- data/lib/active_support/notifications/fanout.rb +105 -18
- data/lib/active_support/notifications/instrumenter.rb +32 -13
- data/lib/active_support/number_helper.rb +636 -0
- data/lib/active_support/ordered_hash.rb +8 -190
- data/lib/active_support/ordered_options.rb +21 -23
- 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/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 +52 -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 +25 -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 +78 -43
- data/lib/active_support/values/time_zone.rb +77 -58
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +4 -4
- data/lib/active_support/xml_mini.rb +35 -17
- data/lib/active_support/xml_mini/jdom.rb +9 -17
- data/lib/active_support/xml_mini/libxml.rb +1 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
- data/lib/active_support/xml_mini/nokogiri.rb +1 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
- data/lib/active_support/xml_mini/rexml.rb +6 -8
- metadata +107 -77
- 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.rb +0 -1
- data/lib/active_support/core_ext/float/rounding.rb +0 -19
- 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.rb +0 -1
- data/lib/active_support/core_ext/process/daemon.rb +0 -23
- 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/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.rb +0 -317
- 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.rb +0 -152
- 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/time/autoload.rb +0 -5
- data/lib/active_support/whiny_nil.rb +0 -24
@@ -1,50 +1,77 @@
|
|
1
1
|
require "active_support/inflector/methods"
|
2
|
-
require "active_support/lazy_load_hooks"
|
3
2
|
|
4
3
|
module ActiveSupport
|
4
|
+
# Autoload and eager load conveniences for your library.
|
5
|
+
#
|
6
|
+
# This module allows you to define autoloads based on
|
7
|
+
# Rails conventions (i.e. no need to define the path
|
8
|
+
# it is automatically guessed based on the filename)
|
9
|
+
# and also define a set of constants that needs to be
|
10
|
+
# eager loaded:
|
11
|
+
#
|
12
|
+
# module MyLib
|
13
|
+
# extend ActiveSupport::Autoload
|
14
|
+
#
|
15
|
+
# autoload :Model
|
16
|
+
#
|
17
|
+
# eager_autoload do
|
18
|
+
# autoload :Cache
|
19
|
+
# end
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# Then your library can be eager loaded by simply calling:
|
23
|
+
#
|
24
|
+
# MyLib.eager_load!
|
5
25
|
module Autoload
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
26
|
+
def self.extended(base) # :nodoc:
|
27
|
+
base.class_eval do
|
28
|
+
@_autoloads = {}
|
29
|
+
@_under_path = nil
|
30
|
+
@_at_path = nil
|
31
|
+
@_eager_autoload = false
|
32
|
+
end
|
33
|
+
end
|
10
34
|
|
11
|
-
def autoload(const_name, path =
|
12
|
-
|
13
|
-
|
35
|
+
def autoload(const_name, path = @_at_path)
|
36
|
+
unless path
|
37
|
+
full = [name, @_under_path, const_name.to_s].compact.join("::")
|
38
|
+
path = Inflector.underscore(full)
|
39
|
+
end
|
14
40
|
|
15
|
-
if
|
16
|
-
|
41
|
+
if @_eager_autoload
|
42
|
+
@_autoloads[const_name] = path
|
17
43
|
end
|
18
|
-
|
44
|
+
|
45
|
+
super const_name, path
|
19
46
|
end
|
20
47
|
|
21
48
|
def autoload_under(path)
|
22
|
-
|
49
|
+
@_under_path, old_path = path, @_under_path
|
23
50
|
yield
|
24
51
|
ensure
|
25
|
-
|
52
|
+
@_under_path = old_path
|
26
53
|
end
|
27
54
|
|
28
55
|
def autoload_at(path)
|
29
|
-
|
56
|
+
@_at_path, old_path = path, @_at_path
|
30
57
|
yield
|
31
58
|
ensure
|
32
|
-
|
59
|
+
@_at_path = old_path
|
33
60
|
end
|
34
61
|
|
35
62
|
def eager_autoload
|
36
|
-
old_eager,
|
63
|
+
old_eager, @_eager_autoload = @_eager_autoload, true
|
37
64
|
yield
|
38
65
|
ensure
|
39
|
-
|
66
|
+
@_eager_autoload = old_eager
|
40
67
|
end
|
41
68
|
|
42
|
-
def
|
43
|
-
|
69
|
+
def eager_load!
|
70
|
+
@_autoloads.values.each { |file| require file }
|
44
71
|
end
|
45
72
|
|
46
73
|
def autoloads
|
47
|
-
|
74
|
+
@_autoloads
|
48
75
|
end
|
49
76
|
end
|
50
77
|
end
|
@@ -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
|
@@ -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 depracated 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
|
+
# depracated 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 depracated 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
|