Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 56 lines (45 sloc) 1.23 kB
d6e775c @mislav deprecate renderer, previous/next_label global settings with paginati…
authored
1 module WillPaginate::Deprecation
2 class << self
3 def warn(message, stack = caller)
4 offending_line = origin_of_call(stack)
5 full_message = "DEPRECATION WARNING: #{message} (called from #{offending_line})"
6 logger = rails_logger || Kernel
7 logger.warn full_message
8 end
9
10 private
11
12 def rails_logger
13 defined?(Rails) && Rails.logger
14 end
15
16 def origin_of_call(stack)
17 lib_root = File.expand_path('../../..', __FILE__)
18 stack.find { |line| line.index(lib_root) != 0 } || stack.first
19 end
20 end
21
22 class Hash < ::Hash
23 def initialize(values = {})
24 super()
25 update values
26 @deprecated = {}
27 end
28
29 def []=(key, value)
30 check_deprecated(key, value)
31 super
32 end
33
34 def deprecate_key(*keys)
35 message = block_given? ? Proc.new : keys.pop
36 Array(keys).each { |key| @deprecated[key] = message }
37 end
38
39 def merge(another)
40 to_hash.update(another)
41 end
42
43 def to_hash
44 ::Hash.new.update(self)
45 end
46
47 private
48
49 def check_deprecated(key, value)
50 if msg = @deprecated[key] and (!msg.respond_to?(:call) or (msg = msg.call(key, value)))
51 WillPaginate::Deprecation.warn(msg)
52 end
53 end
54 end
55 end
Something went wrong with that request. Please try again.