Module: WillPaginate::Deprecation

Defined in:
lib/will_paginate/deprecation.rb

Constant Summary collapse

BEHAVIORS =

Choose the default warn behavior according to RAILS_ENV. Ignore deprecation warnings in production.

{
  '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
                   }
}

Class Method Summary collapse

Class Method Details

.behaviorObject

Behavior is a block that takes a message argument.


38
# File 'lib/will_paginate/deprecation.rb', line 38

def self.behavior() @behavior; end

.behavior=(value) ⇒ Object


39
# File 'lib/will_paginate/deprecation.rb', line 39

def self.behavior=(value) @behavior = value; end

.debugObject


4
# File 'lib/will_paginate/deprecation.rb', line 4

def self.debug() @debug; end

.debug=(value) ⇒ Object


5
# File 'lib/will_paginate/deprecation.rb', line 5

def self.debug=(value) @debug = value; end

.default_behaviorObject


29
30
31
32
33
34
35
# File 'lib/will_paginate/deprecation.rb', line 29

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

.silenceObject


42
43
44
45
46
47
48
# File 'lib/will_paginate/deprecation.rb', line 42

def self.silence
  old_behavior = self.behavior
  self.behavior = nil
  yield
ensure
  self.behavior = old_behavior
end

.warn(message, callstack = caller) ⇒ Object


22
23
24
25
26
27
# File 'lib/will_paginate/deprecation.rb', line 22

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