Class: Arel::Nodes::Case

Inherits:
Node
  • Object
show all
Includes:
AliasPredication, Expressions, Predications
Defined in:
lib/arel_extension/nodes/case.rb

Overview

Case node

Examples:

switch.when(table[:x].gt(1), table[:y]).else(table[:z])
# CASE WHEN "table"."x" > 1 THEN "table"."y" ELSE "table"."z" END
switch.when(table[:x].gt(1)).then(table[:y]).else(table[:z])

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Predications

#coalesce

Methods included from Expressions

#sum_without_alias

Constructor Details

#initializeCase

Returns a new instance of Case.



21
22
23
24
# File 'lib/arel_extension/nodes/case.rb', line 21

def initialize
  @conditions = []
  @default = nil
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



19
20
21
# File 'lib/arel_extension/nodes/case.rb', line 19

def conditions
  @conditions
end

#defaultObject (readonly)

Returns the value of attribute default.



19
20
21
# File 'lib/arel_extension/nodes/case.rb', line 19

def default
  @default
end

Instance Method Details

#else(expression) ⇒ Object



36
37
38
39
# File 'lib/arel_extension/nodes/case.rb', line 36

def else(expression)
  @default = Else.new(expression)
  self
end

#then(expression) ⇒ Object



31
32
33
34
# File 'lib/arel_extension/nodes/case.rb', line 31

def then(expression)
  @conditions.last.right = expression
  self
end

#when(condition, expression = nil) ⇒ Object



26
27
28
29
# File 'lib/arel_extension/nodes/case.rb', line 26

def when(condition, expression = nil)
  @conditions << When.new(condition, expression)
  self
end