Class: ActiveRecordExtended::QueryMethods::WithCTE::WithChain

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_extended/query_methods/with_cte.rb

Instance Method Summary collapse

Constructor Details

#initialize(scope) ⇒ WithChain

Returns a new instance of WithChain.

Parameters:

  • scope (ActiveRecord::Relation)


82
83
84
85
# File 'lib/active_record_extended/query_methods/with_cte.rb', line 82

def initialize(scope)
  @scope       = scope
  @scope.cte ||= WithCTE.new(scope)
end

Instance Method Details

#materialized(args) ⇒ Object

Parameters:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/active_record_extended/query_methods/with_cte.rb', line 96

def materialized(args)
  @scope.tap do |scope|
    args.each_pair do |name, _expression|
      sym_name = name.to_sym
      raise ArgumentError.new("CTE already set as not_materialized") if scope.cte.not_materialized_key?(sym_name)

      scope.cte.materialized_keys << sym_name
    end
    scope.cte.pipe_cte_with!(args)
  end
end

#not_materialized(args) ⇒ Object

Parameters:



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/active_record_extended/query_methods/with_cte.rb', line 109

def not_materialized(args)
  @scope.tap do |scope|
    args.each_pair do |name, _expression|
      sym_name = name.to_sym
      raise ArgumentError.new("CTE already set as materialized") if scope.cte.materialized_key?(sym_name)

      scope.cte.not_materialized_keys << sym_name
    end
    scope.cte.pipe_cte_with!(args)
  end
end

#recursive(args) ⇒ Object

Parameters:



88
89
90
91
92
93
# File 'lib/active_record_extended/query_methods/with_cte.rb', line 88

def recursive(args)
  @scope.tap do |scope|
    scope.recursive_value = true
    scope.cte.pipe_cte_with!(args)
  end
end