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)


84
85
86
87
# File 'lib/active_record_extended/query_methods/with_cte.rb', line 84

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

Instance Method Details

#materialized(args) ⇒ Object

Parameters:



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

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:



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

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:



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

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