Class: ActiveResourceExtensions::SearchableResource::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_resource_extensions/searchable_resource/collection.rb

Overview

Proxy of an Array compatible with will_paginate

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pageObject (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_pageObject (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_entriesObject (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_pageObject



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_pageObject



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

#targetObject



30
31
32
# File 'lib/active_resource_extensions/searchable_resource/collection.rb', line 30

def target
  @target ||= []
end

#total_pagesObject



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