Sha256: cb551a52ded8e7f4e6be9b19b0a64e85100970eafbc375ade34f254c7e608716

Contents?: true

Size: 1.59 KB

Versions: 132

Compression:

Stored size: 1.59 KB

Contents

require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/array/extract_options'

module ActiveSupport
  class Deprecation
    module MethodWrapper
      # Declare that a method has been deprecated.
      #
      #   module Fred
      #     extend self
      #
      #     def foo; end
      #     def bar; end
      #     def baz; end
      #   end
      #
      #   ActiveSupport::Deprecation.deprecate_methods(Fred, :foo, bar: :qux, baz: 'use Bar#baz instead')
      #   # => [:foo, :bar, :baz]
      #
      #   Fred.foo
      #   # => "DEPRECATION WARNING: foo is deprecated and will be removed from Rails 4.1."
      #
      #   Fred.bar
      #   # => "DEPRECATION WARNING: bar is deprecated and will be removed from Rails 4.1 (use qux instead)."
      #
      #   Fred.baz
      #   # => "DEPRECATION WARNING: baz is deprecated and will be removed from Rails 4.1 (use Bar#baz instead)."
      def deprecate_methods(target_module, *method_names)
        options = method_names.extract_options!
        deprecator = options.delete(:deprecator) || ActiveSupport::Deprecation.instance
        method_names += options.keys

        method_names.each do |method_name|
          target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
            target_module.send(:define_method, "#{target}_with_deprecation#{punctuation}") do |*args, &block|
              deprecator.deprecation_warning(method_name, options[method_name])
              send(:"#{target}_without_deprecation#{punctuation}", *args, &block)
            end
          end
        end
      end
    end
  end
end

Version data entries

132 entries across 127 versions & 13 rubygems

Version Path
activesupport-4.1.15 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.6 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.1.15.rc1 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.6.rc1 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.1.14.2 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.5.2 lib/active_support/deprecation/method_wrappers.rb
activejob-lock-0.0.2 rails/activesupport/lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.5.1 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.1.14.1 lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/deprecation/method_wrappers.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.5/lib/active_support/deprecation/method_wrappers.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.1.13/lib/active_support/deprecation/method_wrappers.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/activesupport-4.2.4/lib/active_support/deprecation/method_wrappers.rb
activesupport-4.1.14 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.5 lib/active_support/deprecation/method_wrappers.rb
activesupport-4.2.5.rc2 lib/active_support/deprecation/method_wrappers.rb