Created
February 12, 2016 20:53
-
-
Save adelevie/67fbde8c66b6bf476f6f to your computer and use it in GitHub Desktop.
This file contains 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 AuctionQuery | |
def initialize(relation = Auction.all) | |
@relation = relation.extending(Scopes) | |
end | |
module Scopes | |
def delivery_deadline_expired | |
where('delivery_deadline < ?', Time.zone.now) | |
end | |
def accepted | |
where(result: accepted_enum) | |
end | |
def delivered | |
where.not(delivery_url: [nil, ""]) | |
end | |
def cap_submitted | |
where.not(cap_proposal_url: [nil, ""]) | |
end | |
def paid | |
where( | |
awardee_paid_status: paid_enum | |
) | |
end | |
def not_paid | |
where( | |
awardee_paid_status: not_paid_enum | |
) | |
end | |
private | |
def paid_enum | |
Auction.awardee_paid_statuses['paid'] | |
end | |
def not_paid_enum | |
Auction.awardee_paid_statuses['not_paid'] | |
end | |
def accepted_enum | |
Auction.results['accepted'] | |
end | |
end | |
[ | |
:delivery_deadline_expired, | |
:accepted, | |
:delivered, | |
:cap_submitted, | |
:paid, | |
:not_paid | |
].each do |key| | |
define_method key do | |
@relation.send(key) | |
end | |
end | |
def complete_and_successful | |
@relation | |
.delivery_deadline_expired | |
.delivered | |
.accepted | |
.cap_submitted | |
.paid | |
end | |
def payment_pending | |
@relation | |
.delivery_deadline_expired | |
.delivered.accepted | |
.cap_submitted | |
.not_paid | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool!