Sha256: f7ac21c0c64865469626718362f0d669b91531218569d153973d0d21357e557f

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'active_support/deprecation'

# TODO: remove this branch and file when support for rails 3.2 is dropped

module Formtastic
  if ActiveSupport::Deprecation.respond_to?(:new)
    Deprecation = ActiveSupport::Deprecation
  else
    require 'forwardable'

    class Deprecation
      mattr_accessor :deprecation
      self.deprecation = ActiveSupport::Deprecation.dup

      extend Forwardable
      methods = deprecation.methods - deprecation.class.methods
      def_delegators :deprecation, *methods

      def initialize(version, _library)
        deprecation.silenced = false
        deprecation.deprecation_horizon = version
      end

      def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
        caller_backtrace ||= caller(2)

        deprecated_method_warning(deprecated_method_name, message).tap do |msg|
          warn(msg, caller_backtrace)
        end
      end

      def deprecated_method_warning(method_name, message = nil)
        warning = "#{method_name} is deprecated and will be removed from Formtastic #{deprecation_horizon}"
        case message
          when Symbol then "#{warning} (use #{message} instead)"
          when String then "#{warning} (#{message})"
          else warning
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formtastic-3.1.0 lib/formtastic/deprecation.rb
formtastic-3.1.0.rc2 lib/formtastic/deprecation.rb
formtastic-3.1.0.rc1 lib/formtastic/deprecation.rb