class SnipsQuery
def initialize(relation = Snip.all)
@relation = relation
end
def call(q: nil, tag: nil)
scope = @relation
scope = scope.search(q) if q.present?
scope = scope.tagged_with(tag) if tag.present?
scope
end
end
Return relations from query objects, not arrays. It keeps composition possible (additional filters, pagination, eager loading) and avoids loading huge result sets accidentally.