Created
January 22, 2016 20:02
-
-
Save jeffcole/db1dc6535b488510a425 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
module Repositories | |
class Banana | |
attr_reader :relation | |
def initialize(relation = ::Banana.all) | |
self.relation = relation | |
end | |
def old | |
self.class.new( | |
relation.where("created_at < ?", 3.weeks.ago) | |
) | |
end | |
def sweet | |
self.class.new( | |
relation.where(sweet: true) | |
) | |
end | |
private | |
attr_writer :relation | |
end | |
end | |
# bananas_controller.rb | |
@bananas = Repositories::Banana.new.old.sweet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment