module ActiveRecordExtended::QueryMethods::WithCTE

Public Instance Methods

build_with(arel) click to toggle source
# File lib/active_record_extended/query_methods/with_cte.rb, line 131
def build_with(arel)
  return unless with_values?

  cte_statements = cte.map do |name, expression|
    grouped_expression = cte.generate_grouping(expression)
    cte_name           = cte.to_arel_sql(cte.double_quote(name.to_s))
    Arel::Nodes::As.new(cte_name, grouped_expression)
  end

  if recursive_value?
    arel.with(:recursive, cte_statements)
  else
    arel.with(cte_statements)
  end
end
cte() click to toggle source

@return [WithCTE]

# File lib/active_record_extended/query_methods/with_cte.rb, line 81
def cte
  @values[:cte]
end
cte=(cte) click to toggle source

@param [WithCTE] cte

# File lib/active_record_extended/query_methods/with_cte.rb, line 86
def cte=(cte)
  raise TypeError.new("Must be a WithCTE class type") unless cte.is_a?(WithCTE)

  @values[:cte] = cte
end
recursive_value=(value) click to toggle source

@param [Boolean] value

# File lib/active_record_extended/query_methods/with_cte.rb, line 103
def recursive_value=(value)
  raise ImmutableRelation if @loaded

  @values[:recursive] = value
end
recursive_value?() click to toggle source

@return [Boolean]

# File lib/active_record_extended/query_methods/with_cte.rb, line 110
def recursive_value?
  !(!@values[:recursive])
end
with(opts = :chain, *rest) click to toggle source

@param [Hash, WithCTE] opts

# File lib/active_record_extended/query_methods/with_cte.rb, line 115
def with(opts = :chain, *rest)
  return WithChain.new(spawn) if opts == :chain

  opts.blank? ? self : spawn.with!(opts, *rest)
end
with!(opts = :chain, *_rest) click to toggle source

@param [Hash, WithCTE] opts

# File lib/active_record_extended/query_methods/with_cte.rb, line 122
def with!(opts = :chain, *_rest)
  return WithChain.new(self) if opts == :chain

  tap do |scope|
    scope.cte ||= WithCTE.new(self)
    scope.cte.pipe_cte_with!(opts)
  end
end
with_values=(values) click to toggle source

@param [Hash, WithCTE] values

# File lib/active_record_extended/query_methods/with_cte.rb, line 98
def with_values=(values)
  cte.with_values = values
end
with_values?() click to toggle source

@return [Boolean]

# File lib/active_record_extended/query_methods/with_cte.rb, line 93
def with_values?
  !(cte.nil? || cte.empty?)
end