Query Object pattern from http://craftingruby.com/posts/2015/06/29/query-objects-through-scopes.html
class Video < ActiveRecord::Base
scope :featured_and_popular, Videos::FeaturedAndPopularQuery
endmodule Videos
class FeaturedAndPopularQuery
class << self
delegate :call, to: :new
end
def initialize(relation = Video.all)
@relation = relation
end
def call
@relation.where(featured: true).where('views_count > ?', 100)
end
end
end