Class: Kaminari::Neo4j::Paginated

Inherits:
Object
  • Object
show all
Includes:
Enumerable, ConfigurationMethods::ClassMethods, CriteriaMethods
Defined in:
lib/kaminari/neo4j/paginated.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CriteriaMethods

#entry_name, #limit_value, #offset_value, #total_count

Constructor Details

#initialize(source, current_page, per_page = nil) ⇒ Paginated

Returns a new instance of Paginated.



15
16
17
18
19
# File 'lib/kaminari/neo4j/paginated.rb', line 15

def initialize(source, current_page, per_page = nil)
  self.source = source
  self.current_page = (current_page || 1).to_i
  self.per_page = (per_page || default_per_page).to_i
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



8
9
10
# File 'lib/kaminari/neo4j/paginated.rb', line 8

def current_page
  @current_page
end

#per_pageObject

Returns the value of attribute per_page.



8
9
10
# File 'lib/kaminari/neo4j/paginated.rb', line 8

def per_page
  @per_page
end

#sourceObject

Returns the value of attribute source.



8
9
10
# File 'lib/kaminari/neo4j/paginated.rb', line 8

def source
  @source
end

#totalObject

Returns the value of attribute total.



8
9
10
# File 'lib/kaminari/neo4j/paginated.rb', line 8

def total
  @total
end

Class Method Details

.create_from(source, page, per_page = 0) ⇒ Object



29
30
31
# File 'lib/kaminari/neo4j/paginated.rb', line 29

def self.create_from(source, page, per_page = 0)
  new(source, page, per_page)
end

Instance Method Details

#itemsObject



25
26
27
# File 'lib/kaminari/neo4j/paginated.rb', line 25

def items
  @items || source.skip((current_page - 1) * per_page).limit(per_page)
end

#per(num) ⇒ Object



33
34
35
# File 'lib/kaminari/neo4j/paginated.rb', line 33

def per(num)
  self.class.create_from(source, current_page, num)
end

#pluck(*args) ⇒ Object



37
38
39
40
# File 'lib/kaminari/neo4j/paginated.rb', line 37

def pluck(*args)
  @items = source.pluck(*args)
  self
end

#to_aryObject



42
43
44
# File 'lib/kaminari/neo4j/paginated.rb', line 42

def to_ary
  items.to_a
end