Class: Arel::Nodes::Case

Inherits:
Node
  • Object
show all
Includes:
AliasPredication, OrderPredications, Predications
Defined in:
lib/thredded/rails_lt_5_2_arel_case_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expression = nil, default = nil) ⇒ Case

Returns a new instance of Case.


12
13
14
15
16
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 12

def initialize(expression = nil, default = nil)
  @case = expression
  @conditions = []
  @default = default
end

Instance Attribute Details

#caseObject

Returns the value of attribute case


10
11
12
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 10

def case
  @case
end

#conditionsObject

Returns the value of attribute conditions


10
11
12
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 10

def conditions
  @conditions
end

#defaultObject

Returns the value of attribute default


10
11
12
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 10

def default
  @default
end

Instance Method Details

#else(expression) ⇒ Object


28
29
30
31
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 28

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

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

44
45
46
47
48
49
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 44

def eql?(other)
  self.class == other.class &&
    self.case == other.case &&
    conditions == other.conditions &&
    default == other.default
end

#hashObject


40
41
42
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 40

def hash
  [@case, @conditions, @default].hash
end

#initialize_copy(other) ⇒ Object


33
34
35
36
37
38
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 33

def initialize_copy(other)
  super
  @case = @case.clone if @case
  @conditions = @conditions.map(&:clone)
  @default = @default.clone if @default
end

#then(expression) ⇒ Object


23
24
25
26
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 23

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

#when(condition, expression = nil) ⇒ Object


18
19
20
21
# File 'lib/thredded/rails_lt_5_2_arel_case_node.rb', line 18

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