Skip to content

Instantly share code, notes, and snippets.

@caedes
Last active March 30, 2016 14:38
Show Gist options
  • Save caedes/abfe14430d202e35f48a6f653ae46b15 to your computer and use it in GitHub Desktop.
Save caedes/abfe14430d202e35f48a6f653ae46b15 to your computer and use it in GitHub Desktop.
How to delegating ActiveRecord scopes to Query objects
class Card
scope :black_listed, Cards::BlackListedQuery
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment