Class: Arel::Nodes::Case

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AliasPredication

#as

Methods included from Predications

#between, #concat, #does_not_match, #does_not_match_all, #does_not_match_any, #does_not_match_regexp, #eq, #eq_all, #eq_any, #gt, #gt_all, #gt_any, #gteq, #gteq_all, #gteq_any, #in, #in_all, #in_any, #lt, #lt_all, #lt_any, #lteq, #lteq_all, #lteq_any, #matches, #matches_all, #matches_any, #matches_regexp, #not_between, #not_eq, #not_eq_all, #not_eq_any, #not_in, #not_in_all, #not_in_any

Methods included from OrderPredications

#asc, #desc

Methods inherited from Node

#_caller, #and, #each, #not, #or, #to_sql

Methods included from FactoryMethods

#create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower

Constructor Details

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

Returns a new instance of Case.



11
12
13
14
15
# File 'lib/arel/nodes/case.rb', line 11

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

Instance Attribute Details

#caseObject

Returns the value of attribute case.



9
10
11
# File 'lib/arel/nodes/case.rb', line 9

def case
  @case
end

#conditionsObject

Returns the value of attribute conditions.



9
10
11
# File 'lib/arel/nodes/case.rb', line 9

def conditions
  @conditions
end

#defaultObject

Returns the value of attribute default.



9
10
11
# File 'lib/arel/nodes/case.rb', line 9

def default
  @default
end

Instance Method Details

#else(expression) ⇒ Object



27
28
29
30
# File 'lib/arel/nodes/case.rb', line 27

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

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

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/arel/nodes/case.rb', line 43

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

#hashObject



39
40
41
# File 'lib/arel/nodes/case.rb', line 39

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

#initialize_copy(other) ⇒ Object



32
33
34
35
36
37
# File 'lib/arel/nodes/case.rb', line 32

def initialize_copy other
  super
  @case = @case.clone if @case
  @conditions = @conditions.map { |x| x.clone }
  @default = @default.clone if @default
end

#then(expression) ⇒ Object



22
23
24
25
# File 'lib/arel/nodes/case.rb', line 22

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

#when(condition, expression = nil) ⇒ Object



17
18
19
20
# File 'lib/arel/nodes/case.rb', line 17

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