Skip to content

Instantly share code, notes, and snippets.

@edlvj
Created November 2, 2018 14:18
Show Gist options
  • Save edlvj/27c58cbb017a9dff2af36c66fcb0506f to your computer and use it in GitHub Desktop.
Save edlvj/27c58cbb017a9dff2af36c66fcb0506f to your computer and use it in GitHub Desktop.
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