forked from mislav/will_paginate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate renderer, previous/next_label global settings with paginati…
…on_options Renderer shouldn't be set globally because of mounted apps compatibility, and previous/next_label in Rails should be customized with i18n rather than editing pagination_options.
- Loading branch information
Showing
5 changed files
with
123 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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) && 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters