Class: ActiveGraph::Paginated
- Inherits:
 - 
      Object
      
        
- Object
 - ActiveGraph::Paginated
 
 
- Includes:
 - Enumerable
 
- Defined in:
 - lib/active_graph/paginated.rb
 
Instance Attribute Summary collapse
- 
  
    
      #current_page  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute current_page.
 - 
  
    
      #items  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute items.
 - 
  
    
      #total  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute total.
 
Class Method Summary collapse
Instance Method Summary collapse
- 
  
    
      #initialize(items, total, current_page)  ⇒ Paginated 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Paginated.
 
Constructor Details
#initialize(items, total, current_page) ⇒ Paginated
Returns a new instance of Paginated.
      6 7 8 9 10  | 
    
      # File 'lib/active_graph/paginated.rb', line 6 def initialize(items, total, current_page) @items = items @total = total @current_page = current_page end  | 
  
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
      4 5 6  | 
    
      # File 'lib/active_graph/paginated.rb', line 4 def current_page @current_page end  | 
  
#items ⇒ Object (readonly)
Returns the value of attribute items.
      4 5 6  | 
    
      # File 'lib/active_graph/paginated.rb', line 4 def items @items end  | 
  
#total ⇒ Object (readonly)
Returns the value of attribute total.
      4 5 6  | 
    
      # File 'lib/active_graph/paginated.rb', line 4 def total @total end  | 
  
Class Method Details
.create_from(source, page, per_page, order = nil) ⇒ Object
      12 13 14 15 16 17 18 19 20 21  | 
    
      # File 'lib/active_graph/paginated.rb', line 12 def self.create_from(source, page, per_page, order = nil) target = source.node_var || source.identity partial = source.skip((page - 1) * per_page).limit(per_page) ordered_partial, ordered_source = if order [partial.order_by(order), source.query.with("#{target} as #{target}").pluck("COUNT(#{target})").first] else [partial, source.count] end Paginated.new(ordered_partial, ordered_source, page) end  |