Last active
March 30, 2016 14:38
-
-
Save caedes/abfe14430d202e35f48a6f653ae46b15 to your computer and use it in GitHub Desktop.
How to delegating ActiveRecord scopes to Query objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Card | |
scope :black_listed, Cards::BlackListedQuery | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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