Class: Kaminari::ActiveGraph::Paginated
- Inherits:
-
Object
- Object
- Kaminari::ActiveGraph::Paginated
show all
- Includes:
- Enumerable, CriteriaMethods, ConfigurationMethods::ClassMethods
- Defined in:
- lib/kaminari/active_graph/paginated.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#entry_name, #limit_value, #offset_value, #total_count
Constructor Details
#initialize(source, current_page, per_page = nil) ⇒ Paginated
Returns a new instance of Paginated.
14
15
16
17
18
19
|
# File 'lib/kaminari/active_graph/paginated.rb', line 14
def initialize(source, current_page, per_page = nil)
self.source = source
self.current_page = (current_page || 1).to_i
self.current_page = 1 if self.current_page < 1
self.per_page = (per_page || default_per_page).to_i
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
29
30
31
|
# File 'lib/kaminari/active_graph/paginated.rb', line 29
def method_missing(name, *args, &block)
items.respond_to?(name) ? items.send(name, *args, &block) : super
end
|
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
8
9
10
|
# File 'lib/kaminari/active_graph/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/active_graph/paginated.rb', line 8
def per_page
@per_page
end
|
#source ⇒ Object
Returns the value of attribute source.
8
9
10
|
# File 'lib/kaminari/active_graph/paginated.rb', line 8
def source
@source
end
|
Class Method Details
.create_from(source, page, per_page = nil) ⇒ Object
37
38
39
|
# File 'lib/kaminari/active_graph/paginated.rb', line 37
def self.create_from(source, page, per_page = nil)
new(source, page, per_page)
end
|
Instance Method Details
#items ⇒ Object
25
26
27
|
# File 'lib/kaminari/active_graph/paginated.rb', line 25
def items
@items ||= source.skip((current_page - 1) * per_page).limit(per_page)
end
|
#per(num) ⇒ Object
41
42
43
|
# File 'lib/kaminari/active_graph/paginated.rb', line 41
def per(num)
self.class.create_from(source, current_page, num)
end
|
#pluck(*args) ⇒ Object
45
46
47
48
|
# File 'lib/kaminari/active_graph/paginated.rb', line 45
def pluck(*args)
@items = source.pluck(*args)
self
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
33
34
35
|
# File 'lib/kaminari/active_graph/paginated.rb', line 33
def respond_to_missing?(name, include_private = false)
items.respond_to?(name, include_private) || super
end
|
#to_ary ⇒ Object
50
51
52
|
# File 'lib/kaminari/active_graph/paginated.rb', line 50
def to_ary
items.to_a
end
|
#total ⇒ Object
21
22
23
|
# File 'lib/kaminari/active_graph/paginated.rb', line 21
def total
source.count
end
|