Class: RoarExtensions::PaginatedCollectionPresenter
- Inherits:
-
Object
- Object
- RoarExtensions::PaginatedCollectionPresenter
- Includes:
- Presenter
- Defined in:
- lib/roar_extensions/paginated_collection_presenter.rb
Instance Method Summary collapse
-
#initialize(record, base_path) ⇒ PaginatedCollectionPresenter
constructor
A new instance of PaginatedCollectionPresenter.
- #page_link(page_number) ⇒ Object
-
#to_hash(options = {}) ⇒ Object
Hack to push the :include and :exclude options to the collection results.
- #to_hash_without_entries ⇒ Object
Methods included from Presenter
Constructor Details
#initialize(record, base_path) ⇒ PaginatedCollectionPresenter
Returns a new instance of PaginatedCollectionPresenter.
19 20 21 22 23 24 25 |
# File 'lib/roar_extensions/paginated_collection_presenter.rb', line 19 def initialize(record, base_path) unless record.respond_to?(:next_page) record = KaminariShim.new(record) end super(record) @base_path = base_path end |
Instance Method Details
#page_link(page_number) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/roar_extensions/paginated_collection_presenter.rb', line 27 def page_link(page_number) if page_number == 1 @base_path elsif !page_number.nil? "#{@base_path}?page=#{page_number}" end end |
#to_hash(options = {}) ⇒ Object
Hack to push the :include and :exclude options to the collection results
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/roar_extensions/paginated_collection_presenter.rb', line 38 def to_hash( = {}) opt_include = .delete(:include) opt_exclude = .delete(:exclude) res = to_hash_without_entries() res["paginated_collection"]["entries"] = record.collect.map do |e| entry_include = opt_include && opt_include.map {|name| get_actual_property_name(e, name)} entry_exclude = opt_exclude && opt_exclude.map {|name| get_actual_property_name(e, name)} e.to_hash(.merge(:include => entry_include, :exclude => entry_exclude)) end res end |
#to_hash_without_entries ⇒ Object
35 |
# File 'lib/roar_extensions/paginated_collection_presenter.rb', line 35 alias_method :to_hash_without_entries, :to_hash |