Module: Quo::Utilities::Wrap

Included in:
Query
Defined in:
lib/quo/utilities/wrap.rb

Overview

Wrap a ActiveRecord::Relation or data collection in a Query.

If the passed in object is already a Query object then just return it or copy it if new options are passed in. Otherwise if a Relation wrap it in a new Query object or else in an EagerQuery .

Instance Method Summary collapse

Instance Method Details

#wrap(query_rel_or_data, **options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/quo/utilities/wrap.rb', line 10

def wrap(query_rel_or_data, **options)
  if query_rel_or_data.is_a? Quo::Query
    return options.present? ? query_rel_or_data.copy(**options) : query_rel_or_data
  end

  if query_rel_or_data.is_a? ActiveRecord::Relation
    Quo::WrappedQuery.new(query_rel_or_data, **options)
  else
    Quo::LoadedQuery.new(query_rel_or_data, **options)
  end
end