Class: Arel::Nodes::Case

Inherits:
NodeExpression show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Math

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

Methods included from OrderPredications

#asc, #desc

Methods included from AliasPredication

#as

Methods included from Predications

#between, #concat, #contains, #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, #is_distinct_from, #is_not_distinct_from, #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, #overlaps, #quoted_array

Methods included from Expressions

#average, #count, #extract, #maximum, #minimum, #sum

Methods inherited from Node

#and, #equality?, #fetch_attribute, #invert, #not, #or, #to_sql

Methods included from FactoryMethods

#coalesce, #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.



8
9
10
11
12
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 8

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

Instance Attribute Details

#caseObject

Returns the value of attribute case.



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 6

def case
  @case
end

#conditionsObject

Returns the value of attribute conditions.



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 6

def conditions
  @conditions
end

#defaultObject

Returns the value of attribute default.



6
7
8
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 6

def default
  @default
end

Instance Method Details

#else(expression) ⇒ Object



24
25
26
27
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/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: ==

Returns:

  • (Boolean)


40
41
42
43
44
45
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/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

#hashObject



36
37
38
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 36

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

#initialize_copy(other) ⇒ Object



29
30
31
32
33
34
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/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) ⇒ Object



19
20
21
22
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 19

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

#when(condition, expression = nil) ⇒ Object



14
15
16
17
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4/lib/arel/nodes/case.rb', line 14

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