123456789_123456789_123456789_123456789_123456789_

Class: Arel::Nodes::Case

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Arel::Nodes::NodeExpression
Defined in: activerecord/lib/arel/nodes/case.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::Arel::Math - Included

#&, #*, #+, #-, #/, #<<, #>>, #^, #|, #~@

::Arel::OrderPredications - Included

::Arel::AliasPredication - Included

#as

::Arel::Predications - Included

::Arel::Expressions - Included

Node - Inherited

#and

Factory method to create an And node.

#fetch_attribute, #invert,
#not

Factory method to create a Nodes::Not node that has the recipient of the caller as a child.

#or

Factory method to create a Grouping node that has an Or node as a child.

#to_sql

FIXME: this method should go away.

::Arel::FactoryMethods - Included

Constructor Details

.new(expression = nil, default = nil) ⇒ Case

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 8

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

Instance Attribute Details

#case (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 6

attr_accessor :case, :conditions, :default

#conditions (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 6

attr_accessor :case, :conditions, :default

#default (rw)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 6

attr_accessor :case, :conditions, :default

Instance Method Details

#==(other)

Alias for #eql?.

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 46

alias :== :eql?

#else(expression)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 24

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

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

[ GitHub ]

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

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

#hash

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 36

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

#initialize_copy(other)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 29

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

#then(expression)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 19

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

#when(condition, expression = nil)

[ GitHub ]

  
# File 'activerecord/lib/arel/nodes/case.rb', line 14

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