Skip to content

Commit

Permalink
Remove nil variables from DEFAULT
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 7, 2024
1 parent e5aa702 commit 70c75de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 44 deletions.
6 changes: 3 additions & 3 deletions docs/api/pagy.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ They are all integers:
| `:size` | The size of the page links to show: can be an array of initial pages, before current page, after current page, final pages or the total page size. _(see also [How to control the page links](/docs/how-to.md#control-the-page-links))_ | `7` |
| `:page_param` | The name of the page param name used in the url. _(see [How to customize the page param](/docs/how-to.md#customize-the-page-param))_ | `:page` |
| `:params` | It can be a `Hash` of params to add to the URL, or a `Proc` that can edit/add/delete the request params _(see [How to customize the params](/docs/how-to.md#customize-the-params))_ | `{}` |
| `:fragment` | The arbitrary fragment string (including the "#") to add to the url. _(see [How to customize the params](/docs/how-to.md#customize-the-params))_ | `''` |
| `:fragment` | The arbitrary fragment string (including the "#") to add to the url. _(see [How to customize the params](/docs/how-to.md#customize-the-params))_ | `nil` |
| `:anchor_string` | The extra attributes string (formatted as a valid HTML attribute/value pairs) added to the page links _(see [How to customize the link attributes](/docs/how-to.md#customize-the-link-attributes))_ | `nil` |
| `:cycle` | Enable cycling/circular/infinite pagination: `true` sets `next` to `1` when the current page is the last page | `false` |
| `:request_path` | Allows overriding the request path for pagination links. Pass the path only (not the absolute url). _(see [Customize the request path](/docs/how-to.md#customize-the-request-path))_ | `nil` |
Expand All @@ -167,8 +167,8 @@ or `nil`), except the `vars` hash:
| `page` | The current page number |
| `items` | The requested number of items for the page |
| `in` | The number of the items in the page |
| `last` | The number of the last page in the collection (ordinal meaning) |
| `pages` | Alias for `last` (cardinal meaning) |
| `last` | The number of the last page in the collection (ordinal meaning) |
| `pages` | Alias for `last` (cardinal meaning) |
| `offset` | The number of items skipped from the collection in order to get the start of the current page (`:outset` included) |
| `from` | The collection-position of the first item in the page (`:outset` excluded) |
| `to` | The collection-position of the last item in the page (`:outset` excluded) |
Expand Down
22 changes: 8 additions & 14 deletions gem/lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ def self.root
end

# Core defult: constant for easy access, but mutable for customizable defaults
DEFAULT = { page: 1, # rubocop:disable Style/MutableConstant
items: 20,
outset: 0,
size: 7,
cycle: false,
# backend/collection
count_args: [:all], # AR friendly
# backend/url
params: {},
page_param: :page,
fragment: '',
request_path: nil,
# frontend/helpers
anchor_string: nil }
DEFAULT = { page: 1, # rubocop:disable Style/MutableConstant
items: 20,
outset: 0,
size: 7,
cycle: false,
count_args: [:all], # AR friendly
params: {},
page_param: :page }

attr_reader :count, :page, :items, :vars, :last, :offset, :in, :from, :to, :prev, :next, :params, :request_path
alias pages last
Expand Down
43 changes: 20 additions & 23 deletions test/pagy/extras/metadata_test.rb.rematch
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ pagy/extras/metadata::#pagy_metadata for Pagy::Calendar#test_0002_returns only s
:prev: 2
:next: 4
:pages: 26
pagy/extras/metadata::#pagy_metadata for Pagy#test_0001_defines all metadata:
:metadata:
- :scaffold_url
- :first_url
- :prev_url
- :page_url
- :next_url
- :last_url
- :count
- :page
- :items
- :vars
- :pages
- :last
- :in
- :from
- :to
- :prev
- :next
- :series
pagy/extras/metadata::#pagy_metadata for Pagy#test_0002_returns the full pagy metadata:
:metadata:
:scaffold_url: "/foo?page=__pagy_page__"
Expand All @@ -40,9 +60,6 @@ pagy/extras/metadata::#pagy_metadata for Pagy#test_0002_returns the full pagy me
- :all
:params: {}
:page_param: :page
:fragment: ''
:request_path:
:anchor_string:
:countless_minimal: false
:steps: false
:metadata:
Expand Down Expand Up @@ -102,23 +119,3 @@ pagy/extras/metadata::#pagy_metadata for Pagy#test_0004_returns only specific me
:prev: 2
:next: 4
:pages: 50
pagy/extras/metadata::#pagy_metadata for Pagy#test_0001_defines all metadata:
:metadata:
- :scaffold_url
- :first_url
- :prev_url
- :page_url
- :next_url
- :last_url
- :count
- :page
- :items
- :vars
- :pages
- :last
- :in
- :from
- :to
- :prev
- :next
- :series
5 changes: 1 addition & 4 deletions test/pagy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def series_for(page, *expected)
end
it 'initializes the request_path' do
pagy = Pagy.new(count: 100, request_path: '/foo')
_(pagy.request_path).must_equal('/foo')
_(pagy.vars[:request_path]).must_equal('/foo')
end
end

Expand All @@ -327,9 +327,6 @@ def series_for(page, *expected)
_(Pagy::DEFAULT[:size]).must_equal 7
_(Pagy::DEFAULT[:page_param]).must_equal :page
_(Pagy::DEFAULT[:params]).must_equal({})
_(Pagy::DEFAULT[:fragment]).must_equal('')
_(Pagy::DEFAULT[:request_path]).must_be_nil
_(Pagy::DEFAULT[:anchor_string]).must_be_nil
end
end

Expand Down

0 comments on commit 70c75de

Please sign in to comment.