Class: Kaminari::Neo4j::Paginated
- Inherits:
-
Object
- Object
- Kaminari::Neo4j::Paginated
- Includes:
- Enumerable, ConfigurationMethods::ClassMethods, CriteriaMethods
- Defined in:
- lib/kaminari/neo4j/paginated.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#source ⇒ Object
Returns the value of attribute source.
-
#total ⇒ Object
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(source, current_page, per_page = nil) ⇒ Paginated
constructor
A new instance of Paginated.
- #items ⇒ Object
- #per(num) ⇒ Object
- #pluck(*args) ⇒ Object
- #to_ary ⇒ Object
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_page ⇒ Object
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_page ⇒ Object
Returns the value of attribute per_page.
8 9 10 |
# File 'lib/kaminari/neo4j/paginated.rb', line 8 def per_page @per_page end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/kaminari/neo4j/paginated.rb', line 8 def source @source end |
#total ⇒ Object
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
#items ⇒ Object
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_ary ⇒ Object
42 43 44 |
# File 'lib/kaminari/neo4j/paginated.rb', line 42 def to_ary items.to_a end |