Last active
November 15, 2019 16:58
-
-
Save Dimanaux/c03878e59520c69ed65344a297a3efb2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CollectionDecorator | |
def self.page(objects_relation, page = 1) | |
CollectionDecorator.new(objects_relation.order("created_at").page(page)) | |
end | |
def initialize(objects_relation) | |
@objects_relation = objects_relation | |
end | |
include Enumerable | |
def each(&block) | |
if block_given? | |
@objects_relation.each { |p| block.call(p.decorate) } | |
else | |
to_enum(:each) | |
end | |
end | |
def to_ary | |
to_a | |
end | |
def respond_to?(method) | |
@objects_relation.respond_to?(method) | |
end | |
def respond_to_missing?(method) | |
respond_to?(method) | |
end | |
def method_missing(method, *args, &block) | |
@objects_relation.send(method, *args, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment