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.

Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +325 -136
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +4 -2
  5. data/lib/active_support.rb +8 -21
  6. data/lib/active_support/backtrace_cleaner.rb +33 -25
  7. data/lib/active_support/basic_object.rb +7 -17
  8. data/lib/active_support/benchmarkable.rb +19 -15
  9. data/lib/active_support/buffered_logger.rb +9 -113
  10. data/lib/active_support/cache.rb +203 -171
  11. data/lib/active_support/cache/file_store.rb +12 -12
  12. data/lib/active_support/cache/mem_cache_store.rb +24 -30
  13. data/lib/active_support/cache/memory_store.rb +2 -0
  14. data/lib/active_support/callbacks.rb +195 -247
  15. data/lib/active_support/concern.rb +16 -23
  16. data/lib/active_support/concurrency/latch.rb +27 -0
  17. data/lib/active_support/configurable.rb +69 -12
  18. data/lib/active_support/core_ext.rb +1 -0
  19. data/lib/active_support/core_ext/array.rb +0 -1
  20. data/lib/active_support/core_ext/array/access.rb +17 -9
  21. data/lib/active_support/core_ext/array/conversions.rb +113 -55
  22. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  23. data/lib/active_support/core_ext/array/grouping.rb +21 -22
  24. data/lib/active_support/core_ext/array/uniq_by.rb +12 -9
  25. data/lib/active_support/core_ext/array/wrap.rb +11 -14
  26. data/lib/active_support/core_ext/big_decimal/conversions.rb +7 -24
  27. data/lib/active_support/core_ext/class/attribute.rb +12 -8
  28. data/lib/active_support/core_ext/class/attribute_accessors.rb +14 -12
  29. data/lib/active_support/core_ext/class/delegating_attributes.rb +15 -19
  30. data/lib/active_support/core_ext/class/subclasses.rb +11 -5
  31. data/lib/active_support/core_ext/date.rb +6 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +34 -188
  33. data/lib/active_support/core_ext/date/conversions.rb +16 -38
  34. data/lib/active_support/core_ext/date/infinite_comparable.rb +5 -0
  35. data/lib/active_support/core_ext/date/zones.rb +25 -2
  36. data/lib/active_support/core_ext/date_and_time/calculations.rb +232 -0
  37. data/lib/active_support/core_ext/date_time.rb +5 -0
  38. data/lib/active_support/core_ext/date_time/acts_like.rb +0 -1
  39. data/lib/active_support/core_ext/date_time/calculations.rb +73 -65
  40. data/lib/active_support/core_ext/date_time/conversions.rb +21 -33
  41. data/lib/active_support/core_ext/date_time/infinite_comparable.rb +5 -0
  42. data/lib/active_support/core_ext/date_time/zones.rb +11 -8
  43. data/lib/active_support/core_ext/enumerable.rb +26 -73
  44. data/lib/active_support/core_ext/file.rb +0 -1
  45. data/lib/active_support/core_ext/file/atomic.rb +27 -11
  46. data/lib/active_support/core_ext/hash.rb +0 -1
  47. data/lib/active_support/core_ext/hash/conversions.rb +145 -79
  48. data/lib/active_support/core_ext/hash/deep_merge.rb +14 -8
  49. data/lib/active_support/core_ext/hash/diff.rb +5 -4
  50. data/lib/active_support/core_ext/hash/except.rb +1 -9
  51. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -5
  52. data/lib/active_support/core_ext/hash/keys.rb +108 -24
  53. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  54. data/lib/active_support/core_ext/hash/slice.rb +12 -12
  55. data/lib/active_support/core_ext/infinite_comparable.rb +35 -0
  56. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  57. data/lib/active_support/core_ext/integer/time.rb +17 -12
  58. data/lib/active_support/core_ext/kernel/debugger.rb +2 -2
  59. data/lib/active_support/core_ext/kernel/reporting.rb +36 -22
  60. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  61. data/lib/active_support/core_ext/load_error.rb +7 -5
  62. data/lib/active_support/core_ext/logger.rb +7 -23
  63. data/lib/active_support/core_ext/marshal.rb +19 -0
  64. data/lib/active_support/core_ext/module.rb +1 -3
  65. data/lib/active_support/core_ext/module/aliasing.rb +8 -9
  66. data/lib/active_support/core_ext/module/anonymous.rb +2 -7
  67. data/lib/active_support/core_ext/module/attr_internal.rb +0 -1
  68. data/lib/active_support/core_ext/module/attribute_accessors.rb +12 -10
  69. data/lib/active_support/core_ext/module/delegation.rb +57 -40
  70. data/lib/active_support/core_ext/module/deprecation.rb +19 -3
  71. data/lib/active_support/core_ext/module/introspection.rb +17 -27
  72. data/lib/active_support/core_ext/module/qualified_const.rb +8 -20
  73. data/lib/active_support/core_ext/module/remove_method.rb +1 -5
  74. data/lib/active_support/core_ext/numeric.rb +2 -0
  75. data/lib/active_support/core_ext/numeric/conversions.rb +135 -0
  76. data/lib/active_support/core_ext/numeric/infinite_comparable.rb +9 -0
  77. data/lib/active_support/core_ext/numeric/time.rb +6 -6
  78. data/lib/active_support/core_ext/object.rb +1 -0
  79. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  80. data/lib/active_support/core_ext/object/blank.rb +7 -23
  81. data/lib/active_support/core_ext/object/deep_dup.rb +46 -0
  82. data/lib/active_support/core_ext/object/duplicable.rb +1 -30
  83. data/lib/active_support/core_ext/object/inclusion.rb +6 -6
  84. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  85. data/lib/active_support/core_ext/object/to_json.rb +8 -0
  86. data/lib/active_support/core_ext/object/to_param.rb +5 -2
  87. data/lib/active_support/core_ext/object/try.rb +46 -25
  88. data/lib/active_support/core_ext/object/with_options.rb +7 -8
  89. data/lib/active_support/core_ext/proc.rb +3 -0
  90. data/lib/active_support/core_ext/range.rb +0 -2
  91. data/lib/active_support/core_ext/range/conversions.rb +0 -2
  92. data/lib/active_support/core_ext/range/include_range.rb +1 -1
  93. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  94. data/lib/active_support/core_ext/string.rb +2 -2
  95. data/lib/active_support/core_ext/string/access.rb +95 -90
  96. data/lib/active_support/core_ext/string/conversions.rb +29 -38
  97. data/lib/active_support/core_ext/string/encoding.rb +6 -9
  98. data/lib/active_support/core_ext/string/filters.rb +24 -18
  99. data/lib/active_support/core_ext/string/indent.rb +43 -0
  100. data/lib/active_support/core_ext/string/inflections.rb +70 -60
  101. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  102. data/lib/active_support/core_ext/string/multibyte.rb +41 -64
  103. data/lib/active_support/core_ext/string/output_safety.rb +59 -51
  104. data/lib/active_support/core_ext/string/zones.rb +13 -0
  105. data/lib/active_support/core_ext/struct.rb +6 -0
  106. data/lib/active_support/core_ext/thread.rb +74 -0
  107. data/lib/active_support/core_ext/time.rb +6 -0
  108. data/lib/active_support/core_ext/time/calculations.rb +105 -193
  109. data/lib/active_support/core_ext/time/conversions.rb +27 -51
  110. data/lib/active_support/core_ext/time/infinite_comparable.rb +5 -0
  111. data/lib/active_support/core_ext/time/marshal.rb +0 -27
  112. data/lib/active_support/core_ext/time/zones.rb +27 -17
  113. data/lib/active_support/core_ext/uri.rb +13 -17
  114. data/lib/active_support/dependencies.rb +160 -141
  115. data/lib/active_support/dependencies/autoload.rb +47 -20
  116. data/lib/active_support/deprecation.rb +39 -14
  117. data/lib/active_support/deprecation/behaviors.rb +44 -30
  118. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  119. data/lib/active_support/deprecation/method_wrappers.rb +33 -18
  120. data/lib/active_support/deprecation/proxy_wrappers.rb +58 -13
  121. data/lib/active_support/deprecation/reporting.rb +40 -11
  122. data/lib/active_support/descendants_tracker.rb +34 -19
  123. data/lib/active_support/duration.rb +6 -8
  124. data/lib/active_support/file_update_checker.rb +63 -47
  125. data/lib/active_support/gzip.rb +11 -5
  126. data/lib/active_support/hash_with_indifferent_access.rb +112 -37
  127. data/lib/active_support/i18n.rb +4 -0
  128. data/lib/active_support/i18n_railtie.rb +5 -22
  129. data/lib/active_support/inflections.rb +14 -12
  130. data/lib/active_support/inflector/inflections.rb +108 -71
  131. data/lib/active_support/inflector/methods.rb +181 -160
  132. data/lib/active_support/inflector/transliterate.rb +16 -17
  133. data/lib/active_support/json/decoding.rb +18 -17
  134. data/lib/active_support/json/encoding.rb +93 -39
  135. data/lib/active_support/json/variable.rb +10 -1
  136. data/lib/active_support/key_generator.rb +75 -0
  137. data/lib/active_support/lazy_load_hooks.rb +21 -19
  138. data/lib/active_support/locale/en.yml +100 -3
  139. data/lib/active_support/log_subscriber.rb +56 -36
  140. data/lib/active_support/log_subscriber/test_helper.rb +18 -15
  141. data/lib/active_support/logger.rb +57 -0
  142. data/lib/active_support/logger_silence.rb +24 -0
  143. data/lib/active_support/message_encryptor.rb +32 -29
  144. data/lib/active_support/message_verifier.rb +8 -14
  145. data/lib/active_support/multibyte.rb +5 -28
  146. data/lib/active_support/multibyte/chars.rb +80 -333
  147. data/lib/active_support/multibyte/unicode.rb +74 -64
  148. data/lib/active_support/notifications.rb +57 -25
  149. data/lib/active_support/notifications/fanout.rb +105 -18
  150. data/lib/active_support/notifications/instrumenter.rb +32 -13
  151. data/lib/active_support/number_helper.rb +636 -0
  152. data/lib/active_support/ordered_hash.rb +8 -190
  153. data/lib/active_support/ordered_options.rb +21 -23
  154. data/lib/active_support/proxy_object.rb +13 -0
  155. data/lib/active_support/rails.rb +27 -0
  156. data/lib/active_support/railtie.rb +12 -32
  157. data/lib/active_support/rescuable.rb +9 -4
  158. data/lib/active_support/string_inquirer.rb +13 -8
  159. data/lib/active_support/tagged_logging.rb +51 -73
  160. data/lib/active_support/test_case.rb +46 -17
  161. data/lib/active_support/testing/assertions.rb +56 -26
  162. data/lib/active_support/testing/autorun.rb +5 -0
  163. data/lib/active_support/testing/constant_lookup.rb +52 -0
  164. data/lib/active_support/testing/declarative.rb +1 -1
  165. data/lib/active_support/testing/deprecation.rb +0 -19
  166. data/lib/active_support/testing/isolation.rb +25 -58
  167. data/lib/active_support/testing/pending.rb +5 -43
  168. data/lib/active_support/testing/setup_and_teardown.rb +6 -92
  169. data/lib/active_support/testing/tagged_logging.rb +25 -0
  170. data/lib/active_support/time.rb +6 -21
  171. data/lib/active_support/time_with_zone.rb +78 -43
  172. data/lib/active_support/values/time_zone.rb +77 -58
  173. data/lib/active_support/values/unicode_tables.dat +0 -0
  174. data/lib/active_support/version.rb +4 -4
  175. data/lib/active_support/xml_mini.rb +35 -17
  176. data/lib/active_support/xml_mini/jdom.rb +9 -17
  177. data/lib/active_support/xml_mini/libxml.rb +1 -2
  178. data/lib/active_support/xml_mini/libxmlsax.rb +1 -2
  179. data/lib/active_support/xml_mini/nokogiri.rb +1 -2
  180. data/lib/active_support/xml_mini/nokogirisax.rb +1 -2
  181. data/lib/active_support/xml_mini/rexml.rb +6 -8
  182. metadata +107 -77
  183. data/lib/active_support/base64.rb +0 -54
  184. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  185. data/lib/active_support/core_ext/date/freeze.rb +0 -33
  186. data/lib/active_support/core_ext/exception.rb +0 -3
  187. data/lib/active_support/core_ext/file/path.rb +0 -5
  188. data/lib/active_support/core_ext/float.rb +0 -1
  189. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  190. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -18
  191. data/lib/active_support/core_ext/io.rb +0 -15
  192. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  193. data/lib/active_support/core_ext/module/synchronization.rb +0 -45
  194. data/lib/active_support/core_ext/process.rb +0 -1
  195. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  196. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  197. data/lib/active_support/core_ext/range/cover.rb +0 -3
  198. data/lib/active_support/core_ext/rexml.rb +0 -46
  199. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  200. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  201. data/lib/active_support/memoizable.rb +0 -116
  202. data/lib/active_support/multibyte/exceptions.rb +0 -8
  203. data/lib/active_support/multibyte/utils.rb +0 -60
  204. data/lib/active_support/ruby/shim.rb +0 -22
  205. data/lib/active_support/security_utils.rb +0 -27
  206. data/lib/active_support/testing/mochaing.rb +0 -7
  207. data/lib/active_support/testing/performance.rb +0 -317
  208. data/lib/active_support/testing/performance/jruby.rb +0 -115
  209. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  210. data/lib/active_support/testing/performance/ruby.rb +0 -152
  211. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  212. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  213. data/lib/active_support/time/autoload.rb +0 -5
  214. 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
- @@autoloads = {}
7
- @@under_path = nil
8
- @@at_path = nil
9
- @@eager_autoload = false
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 = @@at_path)
12
- full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
13
- location = path || Inflector.underscore(full)
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 @@eager_autoload
16
- @@autoloads[const_name] = location
41
+ if @_eager_autoload
42
+ @_autoloads[const_name] = path
17
43
  end
18
- super const_name, location
44
+
45
+ super const_name, path
19
46
  end
20
47
 
21
48
  def autoload_under(path)
22
- @@under_path, old_path = path, @@under_path
49
+ @_under_path, old_path = path, @_under_path
23
50
  yield
24
51
  ensure
25
- @@under_path = old_path
52
+ @_under_path = old_path
26
53
  end
27
54
 
28
55
  def autoload_at(path)
29
- @@at_path, old_path = path, @@at_path
56
+ @_at_path, old_path = path, @_at_path
30
57
  yield
31
58
  ensure
32
- @@at_path = old_path
59
+ @_at_path = old_path
33
60
  end
34
61
 
35
62
  def eager_autoload
36
- old_eager, @@eager_autoload = @@eager_autoload, true
63
+ old_eager, @_eager_autoload = @_eager_autoload, true
37
64
  yield
38
65
  ensure
39
- @@eager_autoload = old_eager
66
+ @_eager_autoload = old_eager
40
67
  end
41
68
 
42
- def self.eager_autoload!
43
- @@autoloads.values.each { |file| require file }
69
+ def eager_load!
70
+ @_autoloads.values.each { |file| require file }
44
71
  end
45
72
 
46
73
  def autoloads
47
- @@autoloads
74
+ @_autoloads
48
75
  end
49
76
  end
50
77
  end
@@ -1,18 +1,43 @@
1
- require 'active_support/deprecation/behaviors'
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
- module Deprecation
8
- class << self
9
- # The version the deprecated behavior will be removed, by default.
10
- attr_accessor :deprecation_horizon
11
- end
12
- self.deprecation_horizon = '4.0'
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
- # By default, warnings are not silenced and debugging is off.
15
- self.silenced = false
16
- self.debug = false
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
- module Deprecation
6
- class << self
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 set behavior or if one isn't set, defaults to +:stderr+
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 or an array.
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
- # Examples
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.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
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 << Deprecation
7
- # Declare that a method has been deprecated.
8
- def deprecate_methods(target_module, *method_names)
9
- options = method_names.extract_options!
10
- method_names += options.keys
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
- method_names.each do |method_name|
13
- target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
14
- target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
15
- def #{target}_with_deprecation#{punctuation}(*args, &block)
16
- ::ActiveSupport::Deprecation.warn(
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
- end_eval
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
- module Deprecation
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
- class DeprecatedObjectProxy < DeprecationProxy #:nodoc:
29
- def initialize(object, message)
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
- ActiveSupport::Deprecation.warn(@message, callstack)
50
+ @deprecator.warn(@message, callstack)
41
51
  end
42
52
  end
43
53
 
44
- # Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
45
- # which emits deprecation warnings on any method call (except +inspect+).
46
- class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
47
- def initialize(instance, method, var = "@#{method}")
48
- @instance, @method, @var = instance, method, var
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
- ActiveSupport::Deprecation.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
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
- class DeprecatedConstantProxy < DeprecationProxy #:nodoc:all
62
- def initialize(old_const, new_const)
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
- ActiveSupport::Deprecation.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
122
+ @deprecator.warn("#{@old_const} is deprecated! Use #{@new_const} instead.", callstack)
78
123
  end
79
124
  end
80
125
  end