Skip to content

Instantly share code, notes, and snippets.

@jeffcole
Created January 22, 2016 20:02
Show Gist options
  • Save jeffcole/db1dc6535b488510a425 to your computer and use it in GitHub Desktop.
Save jeffcole/db1dc6535b488510a425 to your computer and use it in GitHub Desktop.
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