Skip to content

Commit a3da3cd

Browse files
authored
Absolutize generic define? to fix module resolution
1 parent fb2c986 commit a3da3cd

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

gem/apps/rails.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ end
6363
require 'pagy/extras/pagy'
6464
require 'pagy/extras/limit'
6565
require 'pagy/extras/overflow'
66+
require 'pagy/extras/headers'
6667
Pagy::DEFAULT[:limit] = 10
6768
Pagy::DEFAULT[:overflow] = :empty_page
6869
Pagy::DEFAULT.freeze
@@ -90,6 +91,10 @@ class Comment < ActiveRecord::Base # :nodoc:
9091
belongs_to :post
9192
end # :nodoc:
9293

94+
# Unused model, useful to test overriding conflicts
95+
module Calendar
96+
end
97+
9398
# DB seed
9499
1.upto(11) do |pi|
95100
Post.create(title: "Post #{pi + 1}")
@@ -110,6 +115,7 @@ class CommentsController < ActionController::Base # :nodoc:
110115

111116
def index
112117
@pagy, @comments = pagy(Comment.all)
118+
pagy_headers_merge(@pagy)
113119
render inline: TEMPLATE
114120
end
115121
end

gem/lib/pagy/extras/headers.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def pagy_headers(pagy)
2525
pagy_link_header(pagy).tap do |hash|
2626
hash[headers[:page]] = pagy.page.to_s if pagy.page && headers[:page]
2727
hash[headers[:limit]] = pagy.limit.to_s \
28-
if headers[:limit] && !(defined?(Calendar) && pagy.is_a?(Calendar::Unit))
29-
return hash if (defined?(Countless) && pagy.is_a?(Countless)) || \
30-
(defined?(Keyset) && pagy.is_a?(Keyset))
28+
if headers[:limit] && !(defined?(::Pagy::Calendar) && pagy.is_a?(Calendar::Unit))
29+
return hash if (defined?(::Pagy::Countless) && pagy.is_a?(Countless)) || \
30+
(defined?(::Pagy::Keyset) && pagy.is_a?(Keyset))
3131

3232
hash[headers[:pages]] = pagy.last.to_s if headers[:pages]
3333
hash[headers[:count]] = pagy.count.to_s if pagy.count && headers[:count] # count may be nil with Calendar
@@ -36,7 +36,7 @@ def pagy_headers(pagy)
3636

3737
def pagy_link_header(pagy)
3838
{ 'link' => [].tap do |link|
39-
if defined?(Keyset) && pagy.is_a?(Keyset)
39+
if defined?(::Pagy::Keyset) && pagy.is_a?(Keyset)
4040
link << %(<#{pagy_url_for(pagy, nil, absolute: true)}>; rel="first")
4141
link << %(<#{pagy_url_for(pagy, pagy.next, absolute: true)}>; rel="next") if pagy.next
4242
else
@@ -45,7 +45,7 @@ def pagy_link_header(pagy)
4545
link << %(<#{url_str.sub(PAGE_TOKEN, pagy.prev.to_s)}>; rel="prev") if pagy.prev
4646
link << %(<#{url_str.sub(PAGE_TOKEN, pagy.next.to_s)}>; rel="next") if pagy.next
4747
link << %(<#{url_str.sub(PAGE_TOKEN, pagy.last.to_s)}>; rel="last") \
48-
unless defined?(Countless) && pagy.is_a?(Countless)
48+
unless defined?(::Pagy::Countless) && pagy.is_a?(Countless)
4949
end
5050
end.join(', ') }
5151
end

gem/lib/pagy/extras/i18n.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def localize(time, opts)
1919
end
2020
end
2121
end
22-
Calendar::Unit.prepend I18nExtra::CalendarOverride if defined?(Calendar::Unit)
22+
Calendar::Unit.prepend I18nExtra::CalendarOverride if defined?(::Pagy::Calendar::Unit)
2323

2424
# Add the pagy locales to the I18n.load_path
2525
::I18n.load_path += Dir[Pagy.root.join('locales', '*.yml')]

gem/lib/pagy/extras/js_tools.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def label_sequels(sequels = self.sequels)
4444
end
4545
end
4646
end
47-
Calendar::Unit.prepend CalendarOverride if defined?(Calendar::Unit)
47+
Calendar::Unit.prepend CalendarOverride if defined?(::Pagy::Calendar::Unit)
4848

4949
# Additions for the Frontend
5050
module FrontendAddOn
51-
if defined?(Oj)
51+
if defined?(::Oj)
5252
# Return a data tag with the base64 encoded JSON-serialized args generated with the faster oj gem
5353
# Base64 encoded JSON is smaller than HTML escaped JSON
5454
def pagy_data(pagy, *args)

gem/lib/pagy/extras/jsonapi.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module BackendOverride
2424

2525
# Return the jsonapi links
2626
def pagy_jsonapi_links(pagy, **opts)
27-
if defined?(Pagy::Keyset) && pagy.is_a?(Pagy::Keyset)
27+
if defined?(::Pagy::Keyset) && pagy.is_a?(Keyset)
2828
{ first: pagy_url_for(pagy, nil, **opts),
2929
last: nil,
3030
prev: nil,
@@ -67,7 +67,7 @@ def pagy_get_limit_param(vars)
6767
end
6868
end
6969
# :nocov:
70-
LimitExtra::BackendAddOn.prepend LimitExtraOverride if defined?(LimitExtra::BackendAddOn)
70+
LimitExtra::BackendAddOn.prepend LimitExtraOverride if defined?(::Pagy::LimitExtra::BackendAddOn)
7171
# :nocov:
7272

7373
# Module overriding UrlHelper

gem/lib/pagy/extras/metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module MetadataExtra
1717
def pagy_metadata(pagy, absolute: nil)
1818
scaffold_url = pagy_url_for(pagy, PAGE_TOKEN, absolute:)
1919
{}.tap do |metadata|
20-
keys = if defined?(Calendar::Unit) && pagy.is_a?(Calendar::Unit)
20+
keys = if defined?(::Pagy::Calendar::Unit) && pagy.is_a?(Calendar::Unit)
2121
pagy.vars[:metadata] - %i[count limit]
2222
else
2323
pagy.vars[:metadata]

gem/lib/pagy/extras/overflow.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def initialize(**vars)
2828
@vars[:page] = requested_page # restore the requested page
2929
when :empty_page
3030
@offset = @limit = @in = @from = @to = 0 # vars relative to the actual page
31-
if defined?(Calendar::Unit) \
31+
if defined?(::Pagy::Calendar::Unit) \
3232
&& is_a?(Calendar::Unit) # only for Calendar::Units instances
3333
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but any time would do)
3434
@from = @to = edge # set both to the edge utc time (a >=&&< query will get no records)
@@ -52,7 +52,7 @@ def series(*, **)
5252
end
5353
end
5454
Pagy.prepend PagyOverride
55-
Pagy::Calendar::Unit.prepend PagyOverride if defined?(Calendar::Unit)
55+
Pagy::Calendar::Unit.prepend PagyOverride if defined?(::Pagy::Calendar::Unit)
5656

5757
# Support for Pagy::Countless class
5858
module CountlessOverride
@@ -75,7 +75,7 @@ def finalize(fetched_size)
7575
end
7676
end
7777
# :nocov:
78-
Pagy::Countless.prepend CountlessOverride if defined?(Countless)
78+
Pagy::Countless.prepend CountlessOverride if defined?(::Pagy::Countless)
7979
# :nocov:
8080
end
8181
end

0 commit comments

Comments
 (0)