Class: Geckorate::Decorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Geckorate::Decorator
- Defined in:
- lib/geckorate.rb
Class Method Summary collapse
- .decorate_collection(collection, options = {}) ⇒ Object
- .decorate_kaminari_collection(collection, options = {}) ⇒ Object
- .decorate_will_paginate_collection(collectionf, options = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.decorate_collection(collection, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/geckorate.rb', line 8 def decorate_collection(collection, = {}) return [] if collection.empty? klass = .fetch(:class_name, collection.first.class) full_klass_name = klass.to_s.concat('Decorator') decorator_klass = Class.const_get(full_klass_name) collection.map do |item| decorator_klass.new(item).decorate() end end |
.decorate_kaminari_collection(collection, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/geckorate.rb', line 20 def decorate_kaminari_collection(collection, = {}) { page: collection.current_page, per_page: collection.current_per_page, total: collection.total_count, records: decorate_collection(collection, ) } end |
.decorate_will_paginate_collection(collectionf, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/geckorate.rb', line 29 def decorate_will_paginate_collection(collectionf, = {}) { page: collection.current_page, per_page: collection.per_page, total: collection.total_entries, records: decorate_collection(collection, ) } end |
Instance Method Details
#decorate(options = {}) ⇒ Object
5 |
# File 'lib/geckorate.rb', line 5 def decorate( = {}); end |