Class: Ludy::RailsPaginator

Inherits:
Paginator show all
Defined in:
lib/ludy/paginator.rb

Overview

rails paginator was provided for convenience, it wraps Paginator for you, and you can just pass the model class to it. you don’t have to care about the fetcher and counter. additionally, you can pass other options to rails paginator, they would be used in find options. e.g.,

RailsPaginator.new Model, :order => 'created_at DESC'

would invoke Model.find :all, :offset => ?, :limit => ?, order => ‘created_at DESC’ TODO: conditions/options invoker…

Instance Attribute Summary collapse

Attributes inherited from Paginator

#counter, #fetcher, #per_page

Instance Method Summary collapse

Methods inherited from Paginator

#==, #count, #each, #offset, #size, #to_a

Constructor Details

#initialize(model_class, opts = {}) ⇒ RailsPaginator

Returns a new instance of RailsPaginator.



99
100
101
102
103
104
105
106
# File 'lib/ludy/paginator.rb', line 99

def initialize model_class, opts = {}
  @model_class = model_class
  super(lambda{ |offset, per_page|
    @model_class.find :all, opts.merge(:offset => offset, :limit => per_page)
  }, lambda{
    @model_class.count
  })
end

Instance Attribute Details

#model_classObject (readonly)

Returns the value of attribute model_class.



98
99
100
# File 'lib/ludy/paginator.rb', line 98

def model_class
  @model_class
end

Instance Method Details

#page(page) ⇒ Object Also known as: []

it simply call super(page.to_i), so RailsPaginator also eat string.



108
# File 'lib/ludy/paginator.rb', line 108

def page page; super page.to_i; end