caedes
3/30/2016 - 2:31 PM

How to delegating ActiveRecord scopes to Query objects

How to delegating ActiveRecord scopes to Query objects

module Cards
  class BlackListedQuery
    class << self
      delegate :call, to: :new
    end

    def initialize(relation = Card.unscoped)
      @relation = relation
    end

    def call
      @relation.where "cards.black_listed_at IS NOT NULL"
    end
  end
end
class Card
  scope :black_listed, Cards::BlackListedQuery
end