Class: PagedPaginator
- Inherits:
 - 
      JSONAPI::Paginator
      
        
- Object
 - JSONAPI::Paginator
 - PagedPaginator
 
 
- Defined in:
 - lib/jsonapi/paginator.rb
 
Instance Attribute Summary collapse
- 
  
    
      #number  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute number.
 - 
  
    
      #size  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute size.
 
Class Method Summary collapse
- .requires_record_count ⇒ Object deprecated Deprecated.
 
Instance Method Summary collapse
- #apply(relation, _order_options) ⇒ Object
 - #calculate_page_count(record_count) ⇒ Object
 - 
  
    
      #initialize(params)  ⇒ PagedPaginator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of PagedPaginator.
 - #links_page_params(options = {}) ⇒ Object
 - #requires_record_count ⇒ Object
 
Methods inherited from JSONAPI::Paginator
Constructor Details
#initialize(params) ⇒ PagedPaginator
Returns a new instance of PagedPaginator.
      137 138 139 140  | 
    
      # File 'lib/jsonapi/paginator.rb', line 137 def initialize(params) parse_pagination_params(params) verify_pagination_params end  | 
  
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
      135 136 137  | 
    
      # File 'lib/jsonapi/paginator.rb', line 135 def number @number end  | 
  
#size ⇒ Object (readonly)
Returns the value of attribute size.
      135 136 137  | 
    
      # File 'lib/jsonapi/paginator.rb', line 135 def size @size end  | 
  
Class Method Details
.requires_record_count ⇒ Object
Deprecated. 
  
      143 144 145  | 
    
      # File 'lib/jsonapi/paginator.rb', line 143 def self.requires_record_count true end  | 
  
Instance Method Details
#apply(relation, _order_options) ⇒ Object
      155 156 157 158  | 
    
      # File 'lib/jsonapi/paginator.rb', line 155 def apply(relation, ) offset = (@number - 1) * @size relation.offset(offset).limit(@size) end  | 
  
#calculate_page_count(record_count) ⇒ Object
      151 152 153  | 
    
      # File 'lib/jsonapi/paginator.rb', line 151 def calculate_page_count(record_count) (record_count / @size.to_f).ceil end  | 
  
#links_page_params(options = {}) ⇒ Object
      160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193  | 
    
      # File 'lib/jsonapi/paginator.rb', line 160 def links_page_params( = {}) record_count = [:record_count] page_count = calculate_page_count(record_count) links_page_params = {} links_page_params['first'] = { 'number' => 1, 'size' => @size } if @number > 1 links_page_params['prev'] = { 'number' => @number - 1, 'size' => @size } end unless @number >= page_count links_page_params['next'] = { 'number' => @number + 1, 'size' => @size } end if record_count links_page_params['last'] = { 'number' => page_count == 0 ? 1 : page_count, 'size' => @size } end links_page_params end  | 
  
#requires_record_count ⇒ Object
      147 148 149  | 
    
      # File 'lib/jsonapi/paginator.rb', line 147 def requires_record_count true end  |