class ActiveRecordExtended::QueryMethods::WithCTE::WithCTE
Attributes
with_keys[R]
with_values[R]
Public Class Methods
new(scope)
click to toggle source
@param [ActiveRecord::Relation] scope
# File lib/active_record_extended/query_methods/with_cte.rb, line 15 def initialize(scope) @scope = scope reset! end
Public Instance Methods
each() { |key, with_values| ... }
click to toggle source
@return [Enumerable] Returns the order for which CTE's were imported as.
# File lib/active_record_extended/query_methods/with_cte.rb, line 21 def each return to_enum(:each) unless block_given? with_keys.each do |key| yield(key, with_values[key]) end end
Also aliased as: each_pair
pipe_cte_with!(value)
click to toggle source
@param [Hash, WithCTE] value
# File lib/active_record_extended/query_methods/with_cte.rb, line 37 def pipe_cte_with!(value) return if value.nil? || value.empty? value.each_pair do |name, expression| sym_name = name.to_sym next if with_values.key?(sym_name) # Ensure we follow FIFO pattern. # If the parent has similar CTE alias keys, we want to favor the parent's expressions over its children's. if expression.is_a?(ActiveRecord::Relation) && expression.with_values? pipe_cte_with!(expression.cte) expression.cte.reset! end @with_keys |= [sym_name] @with_values[sym_name] = expression end value.reset! if value.is_a?(WithCTE) end
reset!()
click to toggle source
# File lib/active_record_extended/query_methods/with_cte.rb, line 58 def reset! @with_keys = [] @with_values = {} end
with_values=(value)
click to toggle source
@param [Hash, WithCTE] value
# File lib/active_record_extended/query_methods/with_cte.rb, line 31 def with_values=(value) reset! pipe_cte_with!(value) end