Class: Westfield::Paginator
- Inherits:
-
Object
- Object
- Westfield::Paginator
- Defined in:
- lib/westfield_paginator/config.rb,
lib/westfield_paginator/paginator.rb
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
-
.config ⇒ Object
Global settings for Westfield::Paginator.
-
.configure {|@config ||= Westfield::Paginator::Configuration.new| ... } ⇒ Object
Configures global settings for pagination Westfield::Paginator.configure do |config| config.default_per_page = 10 end.
Instance Method Summary collapse
- #current_page ⇒ Object
-
#initialize(records, page: nil, per_page: nil, max_per_page: nil) ⇒ Paginator
constructor
A new instance of Paginator.
- #meta ⇒ Object
- #paginated_records ⇒ Object
- #per_page ⇒ Object
- #total_count ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(records, page: nil, per_page: nil, max_per_page: nil) ⇒ Paginator
Returns a new instance of Paginator.
6 7 8 9 10 11 12 13 14 |
# File 'lib/westfield_paginator/paginator.rb', line 6 def initialize(records, page: nil, per_page: nil, max_per_page: nil) @page_info = Westfield::PageInfo.new(page: page, per_page: per_page, max_per_page: max_per_page) if records.is_a? Array @records = Kaminari.paginate_array(records) else @records = records end end |
Class Method Details
.config ⇒ Object
Global settings for Westfield::Paginator
15 16 17 |
# File 'lib/westfield_paginator/config.rb', line 15 def self.config @config end |
.configure {|@config ||= Westfield::Paginator::Configuration.new| ... } ⇒ Object
10 11 12 |
# File 'lib/westfield_paginator/config.rb', line 10 def self.configure(&block) yield @config ||= Westfield::Paginator::Configuration.new end |
Instance Method Details
#current_page ⇒ Object
24 25 26 |
# File 'lib/westfield_paginator/paginator.rb', line 24 def current_page paginated_records.current_page end |
#meta ⇒ Object
20 21 22 |
# File 'lib/westfield_paginator/paginator.rb', line 20 def PaginatorMeta.new(self).as_json end |
#paginated_records ⇒ Object
16 17 18 |
# File 'lib/westfield_paginator/paginator.rb', line 16 def paginated_records @paginated ||= @records.page(page_info.page).per(page_info.per_page) end |
#per_page ⇒ Object
28 29 30 |
# File 'lib/westfield_paginator/paginator.rb', line 28 def per_page page_info.per_page end |
#total_count ⇒ Object
36 37 38 |
# File 'lib/westfield_paginator/paginator.rb', line 36 def total_count paginated_records.total_count end |
#total_pages ⇒ Object
32 33 34 |
# File 'lib/westfield_paginator/paginator.rb', line 32 def total_pages paginated_records.total_pages end |