Created
November 2, 2018 14:18
-
-
Save edlvj/27c58cbb017a9dff2af36c66fcb0506f 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
module Opportunities | |
class CustomerReferencesQuery | |
attr_reader :query, :opportunity | |
def initialize(query, opportunity) | |
@basic_query = query | |
@opportunity = opportunity | |
end | |
def call | |
query = @basic_query.filter_by_industry.filter_by_product | |
return query if query.count >= 5 | |
query = @basic_query.filter_by_product | |
return query if query.count >= 5 | |
@basic_query | |
end | |
def filter_by_industry | |
where(customer_reference.customer.industry_id = opportunity.customer.industry_id) | |
end | |
def filter_by_product | |
where(customer_reference.customer.products = opportunity.products) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment