lib/pagy/extras/shared.rb in pagy-1.2.1 vs lib/pagy/extras/shared.rb in pagy-1.3
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require 'json'
+require 'digest'
class Pagy
# Default :breakpoints
VARS[:breakpoints] = { 0 => [1,4,4,1] }
@@ -25,20 +26,25 @@
@vars[:breakpoints].each {|width, size| r[:items] |= r[:series][width] = series(size)}
r[:widths] = r[:series].keys.sort!{|a,b| b <=> a}
end
end
- def self.deprecate(mod, old_meth, new_meth)
- mod.send(:define_method, old_meth) do |pagy, id=caller(1,1)[0].hash.to_s|
- Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
- mod.instance_method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
- end
- end
-
module Frontend
def pagy_json_tag(*args)
%(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
+ end
+
+ def pagy_id
+ # SHA1 is the fastest on modern ruby
+ "pagy-#{Digest::SHA1.hexdigest(caller(2..2)[0].split(':in')[0])}"
+ end
+
+ def self.deprecate(old_meth, new_meth)
+ send(:define_method, old_meth) do |pagy, id=pagy_id|
+ Warning.warn "WARNING: The ##{old_meth} pagy helper method is deprecated and will be removed in 2.0; please use ##{new_meth} instead. More info at https://github.com/ddnexus/pagy/blob/master/DEPRECATIONS.md\n"
+ method(new_meth).arity == 1 ? send(new_meth, pagy) : send(new_meth, pagy, id)
+ end
end
end
end