Method: Leaf::Collection#initialize
- Defined in:
- lib/leaf/collection.rb
#initialize(page, per_page, total = nil) ⇒ Collection
Arguments to the constructor are the current page number, per-page limit and the total number of entries. The last argument is optional because it is best to do lazy counting; in other words, count conditionally after populating the collection using the replace method.
29 30 31 32 33 34 35 36 |
# File 'lib/leaf/collection.rb', line 29 def initialize(page, per_page, total = nil) @current_page = page.to_i raise InvalidPage.new(page, @current_page) if @current_page < 1 @per_page = per_page.to_i raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1 self.total_entries = total if total end |