Skip to content

Commit

Permalink
Renaming prepended modules with more specific and safe naming convent…
Browse files Browse the repository at this point in the history
…ion (see Issue #290 PR #293)
  • Loading branch information
ddnexus committed Apr 8, 2021
1 parent 3eef450 commit aac54aa
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/pagy/extras/elasticsearch_rails.rb
Expand Up @@ -41,7 +41,7 @@ def pagy_elasticsearch_rails(pagy_search_args, vars={})
vars[:count] = total.is_a?(Hash) ? total['value'] : total
pagy = Pagy.new(vars)
# with :last_page overflow we need to re-run the method in order to get the hits
if defined?(Pagy::Overflow) && pagy.overflow? && pagy.vars[:overflow] == :last_page
if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
return pagy_elasticsearch_rails(pagy_search_args, vars.merge(page: pagy.page))
end
return pagy, called.empty? ? response : response.send(*called)
Expand Down
8 changes: 4 additions & 4 deletions lib/pagy/extras/items.rb
Expand Up @@ -12,7 +12,7 @@ class Pagy

ITEMS_PLACEHOLDER = '__pagy_items__'

module Items ; private
module UseItemsExtra ; private

[:pagy_get_vars, :pagy_countless_get_vars, :pagy_elasticsearch_rails_get_vars, :pagy_searchkick_get_vars].each do |meth|
if Backend.private_method_defined?(meth, true)
Expand All @@ -25,12 +25,12 @@ module Items ; private
end

end
Backend.prepend Items
Backend.prepend UseItemsExtra


module Frontend

module Items
module UseItemsExtra
def pagy_url_for(page, pagy, url=false)
p_vars = pagy.vars
params = request.GET.merge(p_vars[:params])
Expand All @@ -39,7 +39,7 @@ def pagy_url_for(page, pagy, url=false)
"#{request.base_url if url}#{request.path}?#{Rack::Utils.build_nested_query(pagy_get_params(params))}#{p_vars[:anchor]}"
end
end
prepend Items
prepend UseItemsExtra

# Return the items selector HTML. For example "Show [20] items per page"
def pagy_items_selector_js(pagy, id=pagy_id)
Expand Down
8 changes: 4 additions & 4 deletions lib/pagy/extras/overflow.rb
Expand Up @@ -4,7 +4,7 @@

class Pagy

module Overflow
module UseOverflowExtra
VARS[:overflow] = :empty_page

def overflow? = @overflow
Expand Down Expand Up @@ -41,14 +41,14 @@ def series(size=@vars[:size])
end

end
prepend Overflow
prepend UseOverflowExtra


# support for Pagy::Countless
if defined?(Pagy::Countless)
class Countless

module Overflow
module UseOverflowExtra

def finalize(items)
@overflow = false
Expand All @@ -68,7 +68,7 @@ def finalize(items)
end

end
prepend Overflow
prepend UseOverflowExtra

end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/searchkick.rb
Expand Up @@ -39,7 +39,7 @@ def pagy_searchkick(pagy_search_args, vars={})
vars[:count] = results.total_count
pagy = Pagy.new(vars)
# with :last_page overflow we need to re-run the method in order to get the hits
if defined?(Pagy::Overflow) && pagy.overflow? && pagy.vars[:overflow] == :last_page
if defined?(Pagy::UseOverflowExtra) && pagy.overflow? && pagy.vars[:overflow] == :last_page
return pagy_searchkick(pagy_search_args, vars.merge(page: pagy.page))
end
return pagy, called.empty? ? results : results.send(*called)
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/shared.rb
Expand Up @@ -30,14 +30,14 @@ module Frontend
if defined?(Oj)
# it returns a script tag with the JSON-serialized args generated with the faster oj gem
def pagy_json_tag(pagy, *args)
args << ( defined?(Trim) && pagy.vars[:page_param] )
args << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
%(<script type="application/json" class="pagy-json">#{Oj.dump(args, mode: :strict)}</script>)
end
else
require 'json'
# it returns a script tag with the JSON-serialized args generated with the slower to_json
def pagy_json_tag(pagy, *args)
args << ( defined?(Trim) && pagy.vars[:page_param] )
args << ( defined?(UseTrimExtra) && pagy.vars[:page_param] )
%(<script type="application/json" class="pagy-json">#{args.to_json}</script>)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pagy/extras/trim.rb
Expand Up @@ -4,7 +4,7 @@

class Pagy

module Trim
module UseTrimExtra
def pagy_link_proc(pagy, link_extra='')
link_proc = super(pagy, link_extra)
re = /[?&]#{pagy.vars[:page_param]}=1\b(?!&)|\b#{pagy.vars[:page_param]}=1&/
Expand All @@ -14,6 +14,6 @@ def pagy_link_proc(pagy, link_extra='')
end
end
end
Frontend.prepend Trim
Frontend.prepend UseTrimExtra

end

0 comments on commit aac54aa

Please sign in to comment.