Skip to content

Commit

Permalink
Fix for missing defined?(Calendar) checks; small simplification in he…
Browse files Browse the repository at this point in the history
…aders extra
  • Loading branch information
ddnexus committed Nov 8, 2021
1 parent 0da78d6 commit 7b0170c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/pagy/extras/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def pagy_headers(pagy)

# Generates a hash structure of the headers
def pagy_headers_hash(pagy)
countless = defined?(Pagy::Countless) && pagy.is_a?(Pagy::Countless)
countless = defined?(Countless) && pagy.is_a?(Countless)
rel = { 'first' => 1, 'prev' => pagy.prev, 'next' => pagy.next }
rel['last'] = pagy.last unless countless
url_str = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: true)
Expand All @@ -39,7 +39,7 @@ def pagy_headers_hash(pagy)
hash = { 'Link' => link }
headers = pagy.vars[:headers]
hash[headers[:page]] = pagy.page.to_s if headers[:page]
if headers[:items] && !(defined?(Pagy::Calendar) && pagy.is_a?(Pagy::Calendar)) # not for Calendar
if headers[:items] && !(defined?(Calendar) && pagy.is_a?(Calendar)) # items is not for Calendar
hash[headers[:items]] = pagy.vars[:items].to_s
end
unless countless
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module MetadataExtra
def pagy_metadata(pagy, absolute: nil)
scaffold_url = pagy_url_for(pagy, PAGE_PLACEHOLDER, absolute: absolute)
{}.tap do |metadata|
keys = pagy.is_a?(Calendar) ? pagy.vars[:metadata] - %i[count items] : pagy.vars[:metadata]
keys = defined?(Calendar) && pagy.is_a?(Calendar) ? pagy.vars[:metadata] - %i[count items] : pagy.vars[:metadata]
keys.each do |key|
metadata[key] = case key
when :scaffold_url then scaffold_url
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/extras/overflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(vars)
@vars[:page] = requested_page # restore the requested page
when :empty_page
@offset = @in = @from = @to = 0 # vars relative to the actual page
if is_a?(Calendar) # only for Calendar instances
if defined?(Calendar) && is_a?(Calendar) # only for Calendar instances
edge = @order == :asc ? @final : @initial # get the edge of the overflow side (neat, but it would work with any time)
@utc_from = @utc_to = edge.getutc # set both to the edge utc time (a query with >= && < will get no record)
end
Expand Down

0 comments on commit 7b0170c

Please sign in to comment.