Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 50 lines (45 sloc) 1.52 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# borrowed from ActiveSupport::Deprecation
module WillPaginate
  module Deprecation
    def self.debug() @debug; end
    def self.debug=(value) @debug = value; end
    self.debug = false

    # Choose the default warn behavior according to Rails.env.
    # Ignore deprecation warnings in production.
    BEHAVIORS = {
      'test' => Proc.new { |message, callstack|
                         $stderr.puts(message)
                         $stderr.puts callstack.join("\n ") if debug
                       },
      'development' => Proc.new { |message, callstack|
                         logger = defined?(::RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stderr)
                         logger.warn message
                         logger.debug callstack.join("\n ") if debug
                       }
    }

    def self.warn(message, callstack = caller)
      if behavior
        message = 'WillPaginate: ' + message.strip.gsub(/\s+/, ' ')
        behavior.call(message, callstack)
      end
    end

    def self.default_behavior
      if defined?(::Rails)
        BEHAVIORS[::Rails.env.to_s]
      else
        BEHAVIORS['test']
      end
    end

    # Behavior is a block that takes a message argument.
    def self.behavior() @behavior; end
    def self.behavior=(value) @behavior = value; end
    self.behavior = default_behavior

    def self.silence
      old_behavior = self.behavior
      self.behavior = nil
      yield
    ensure
      self.behavior = old_behavior
    end
  end
end
Something went wrong with that request. Please try again.