Sha256: 81dddedc338824186117ef95e7211aadb1178e3c5f5b2f8c982487b00967fefe

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

Contents

module WillPaginate::Deprecation
  class << self
    def warn(message, stack = caller)
      offending_line = origin_of_call(stack)
      full_message = "DEPRECATION WARNING: #{message} (called from #{offending_line})"
      logger = rails_logger || Kernel
      logger.warn full_message
    end

    private

    def rails_logger
      defined?(Rails.logger) && Rails.logger
    end

    def origin_of_call(stack)
      lib_root = File.expand_path('../../..', __FILE__)
      stack.find { |line| line.index(lib_root) != 0 } || stack.first
    end
  end

  class Hash < ::Hash
    def initialize(values = {})
      super()
      update values
      @deprecated = {}
    end

    def []=(key, value)
      check_deprecated(key, value)
      super
    end

    def deprecate_key(*keys)
      message = block_given? ? Proc.new : keys.pop
      Array(keys).each { |key| @deprecated[key] = message }
    end

    def merge(another)
      to_hash.update(another)
    end

    def to_hash
      ::Hash.new.update(self)
    end

    private

    def check_deprecated(key, value)
      if msg = @deprecated[key] and (!msg.respond_to?(:call) or (msg = msg.call(key, value)))
        WillPaginate::Deprecation.warn(msg)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
will_paginate-3.1.7 lib/will_paginate/deprecation.rb
will_paginate-3.1.6 lib/will_paginate/deprecation.rb
will_paginate-3.0.12 lib/will_paginate/deprecation.rb
will_paginate-3.1.5 lib/will_paginate/deprecation.rb
will_paginate-3.0.11 lib/will_paginate/deprecation.rb
will_paginate-3.1.3 lib/will_paginate/deprecation.rb
will_paginate-3.0.10 lib/will_paginate/deprecation.rb
will_paginate-3.0.9 lib/will_paginate/deprecation.rb
will_paginate-3.1.2 lib/will_paginate/deprecation.rb
will_paginate-3.1.1 lib/will_paginate/deprecation.rb
will_paginate-3.0.8 lib/will_paginate/deprecation.rb
will_paginate-3.1.0 lib/will_paginate/deprecation.rb