Module: PaginationScope::Extention
- Defined in:
- lib/pagination_scope.rb
Instance Method Summary collapse
- #count ⇒ Object
- #num_pages ⇒ Object
- #page ⇒ Object
- #pages(window, left, right) ⇒ Object
- #size ⇒ Object
Instance Method Details
#count ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/pagination_scope.rb', line 35 def count @count ||= with_scope :find => .except(:offset, :limit) do if proxy_scope.respond_to?(:proxy_options) select = proxy_scope.[:group] end select ||= "#{table_name}.#{primary_key}" proxy_scope.count(:distinct => true, :select => select) end end |
#num_pages ⇒ Object
45 |
# File 'lib/pagination_scope.rb', line 45 def num_pages; (count.to_f/[:limit]).ceil end |
#page ⇒ Object
46 |
# File 'lib/pagination_scope.rb', line 46 def page; [:offset]/[:limit] + 1 end |
#pages(window, left, right) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/pagination_scope.rb', line 48 def pages(window, left, right) return [] if num_pages <= 1 (1..num_pages).inject([]) do |result, i| i <= left || (num_pages - i) < right || (i-page).abs < window ? result << i : (result.last.nil? ? result : result << nil) end end |
#size ⇒ Object
31 32 33 |
# File 'lib/pagination_scope.rb', line 31 def size proxy_found.size end |