Class: ROM::SQL::Plugin::Pagination::Pager
- Inherits:
- 
      Object
      
        - Object
- ROM::SQL::Plugin::Pagination::Pager
 
- Includes:
- Options
- Defined in:
- lib/rom/sql/plugin/pagination.rb
Instance Attribute Summary collapse
- 
  
    
      #dataset  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute dataset. 
Instance Method Summary collapse
- #at(dataset, current_page, per_page = self.per_page) ⇒ Object
- 
  
    
      #initialize(dataset, options = {})  ⇒ Pager 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Pager. 
- #next_page ⇒ Object
- #prev_page ⇒ Object
- #total ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(dataset, options = {}) ⇒ Pager
Returns a new instance of Pager.
| 14 15 16 17 | # File 'lib/rom/sql/plugin/pagination.rb', line 14 def initialize(dataset, = {}) super @dataset = dataset end | 
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
| 12 13 14 | # File 'lib/rom/sql/plugin/pagination.rb', line 12 def dataset @dataset end | 
Instance Method Details
#at(dataset, current_page, per_page = self.per_page) ⇒ Object
| 37 38 39 40 41 42 43 44 45 | # File 'lib/rom/sql/plugin/pagination.rb', line 37 def at(dataset, current_page, per_page = self.per_page) current_page = current_page.to_i per_page = per_page.to_i self.class.new( dataset.offset((current_page-1)*per_page).limit(per_page), current_page: current_page, per_page: per_page ) end | 
#next_page ⇒ Object
| 19 20 21 22 | # File 'lib/rom/sql/plugin/pagination.rb', line 19 def next_page num = current_page + 1 num if total_pages >= num end | 
#prev_page ⇒ Object
| 24 25 26 27 | # File 'lib/rom/sql/plugin/pagination.rb', line 24 def prev_page num = current_page - 1 num if num > 0 end | 
#total ⇒ Object
| 29 30 31 | # File 'lib/rom/sql/plugin/pagination.rb', line 29 def total dataset.unlimited.count end | 
#total_pages ⇒ Object
| 33 34 35 | # File 'lib/rom/sql/plugin/pagination.rb', line 33 def total_pages (total / per_page.to_f).ceil end |