class Compendium::ThroughQuery

Attributes

through[RW]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Compendium::Query::new
# File lib/compendium/through_query.rb, line 7
def initialize(*args)
  @report = args.shift if arg_is_report?(args.first)
  @through = args.slice!(1)
  super(*args)
end

Private Instance Methods

any_results?(results) click to toggle source
# File lib/compendium/through_query.rb, line 46
def any_results?(results)
  results = results.values if results.is_a? Hash
  results.all?(&:blank?)
end
collect_results(context, params) click to toggle source
Calls superclass method Compendium::Query#collect_results
# File lib/compendium/through_query.rb, line 15
def collect_results(context, params)
  results = collect_through_query_results(params, context)

  # If none of the through queries have any results, we shouldn't try to execute the query, because it
  # depends on the results of its parents.
  return @results = ResultSet.new([]) if any_results?(results)

  # If the proc collects two arguments, pass results and params, otherwise just results
  args = !proc || proc.arity == 1 ? [results] : [results, params]

  super(context, *args)
end
collect_through_query_results(params, context) click to toggle source
# File lib/compendium/through_query.rb, line 32
def collect_through_query_results(params, context)
  results = {}

  queries = Array.wrap(through).map(&method(:get_associated_query))

  queries.each do |q|
    q.run(params, context) unless q.ran?
    results[q.name] = q.results.records.dup
  end

  results = results[queries.first.name] if queries.size == 1
  results
end
fetch_results(command) click to toggle source
# File lib/compendium/through_query.rb, line 28
def fetch_results(command)
  command
end