Class: ActiveResourceExtensions::SearchableResource::Collection
- Inherits:
-
Object
- Object
- ActiveResourceExtensions::SearchableResource::Collection
- Defined in:
- lib/active_resource_extensions/searchable_resource/collection.rb
Overview
Proxy of an Array compatible with will_paginate
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
Instance Method Summary collapse
-
#initialize(target, current_page, per_page, total_entries) ⇒ Collection
constructor
A new instance of Collection.
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #target ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(target, current_page, per_page, total_entries) ⇒ Collection
Returns a new instance of Collection.
11 12 13 14 15 16 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 11 def initialize target, current_page, per_page, total_entries @target = target @current_page = current_page @per_page = per_page @total_entries = total_entries end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
36 37 38 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 36 def method_missing(name, *args, &block) target.send(name, *args, &block) end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
9 10 11 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 9 def current_page @current_page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
9 10 11 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 9 def per_page @per_page end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
9 10 11 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 9 def total_entries @total_entries end |
Instance Method Details
#next_page ⇒ Object
26 27 28 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 26 def next_page current_page == total_pages ? nil : ( current_page + 1 ) end |
#previous_page ⇒ Object
22 23 24 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 22 def previous_page current_page == 1 ? nil : ( current_page - 1 ) end |
#target ⇒ Object
30 31 32 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 30 def target @target ||= [] end |
#total_pages ⇒ Object
18 19 20 |
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 18 def total_pages ( total_entries.to_f / @per_page ).ceil end |