Class: Sequel::SQL::CaseExpression

Inherits:
GenericExpression show all
Defined in:
lib/sequel/sql.rb

Overview

Represents an SQL CASE expression, used for conditions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SubscriptMethods

#sql_subscript

Methods included from StringMethods

#ilike, #like

Methods included from OrderMethods

#asc, #desc

Methods included from ComplexExpressionMethods

#extract, #sql_boolean, #sql_number, #sql_string

Methods included from CastMethods

#cast, #cast_numeric, #cast_string

Methods included from BooleanMethods

#~

Methods included from AliasMethods

#as

Methods inherited from Expression

#==, attr_reader, comparison_attrs, #eql?, #hash, #lit, #sql_literal

Constructor Details

#initialize(conditions, default, expression = nil) ⇒ CaseExpression

Create an object with the given conditions and default value.

Raises:



536
537
538
539
# File 'lib/sequel/sql.rb', line 536

def initialize(conditions, default, expression = nil)
  raise(Sequel::Error, 'CaseExpression conditions must be a hash or array of all two pairs') unless Sequel.condition_specifier?(conditions)
  @conditions, @default, @expression = conditions.to_a, default, expression
end

Instance Attribute Details

#conditionsObject (readonly)

An array of all two pairs with the first element specifying the condition and the second element specifying the result.



526
527
528
# File 'lib/sequel/sql.rb', line 526

def conditions
  @conditions
end

#defaultObject (readonly)

The default value if no conditions are true



529
530
531
# File 'lib/sequel/sql.rb', line 529

def default
  @default
end

#expressionObject (readonly)

The expression to test the conditions against



532
533
534
# File 'lib/sequel/sql.rb', line 532

def expression
  @expression
end