Class: Sequel::SQL::CaseExpression
- Inherits:
-
GenericExpression
- Object
- Expression
- GenericExpression
- Sequel::SQL::CaseExpression
- Defined in:
- lib/sequel_core/sql.rb
Overview
Represents an SQL CASE expression, used for conditions.
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
An array of all two pairs with the first element specifying the condition and the second element specifying the result.
-
#default ⇒ Object
readonly
The default value if no conditions are true.
Instance Method Summary collapse
-
#initialize(conditions, default) ⇒ CaseExpression
constructor
Create an object with the given conditions and default value.
-
#to_s(ds) ⇒ Object
Delegate the creation of the resulting SQL to the given dataset, since it may be database dependent.
Methods included from ComplexExpressionMethods
#extract, #sql_boolean, #sql_number, #sql_string
Methods included from StringMethods
Methods included from BooleanMethods
Methods included from OrderMethods
Methods included from CastMethods
#cast, #cast_numeric, #cast_string
Methods included from AliasMethods
Methods inherited from Expression
Constructor Details
#initialize(conditions, default) ⇒ CaseExpression
Create an object with the given conditions and default value.
473 474 475 476 |
# File 'lib/sequel_core/sql.rb', line 473 def initialize(conditions, default) raise(Sequel::Error, 'CaseExpression conditions must be an array with all_two_pairs') unless Array === conditions and conditions.all_two_pairs? @conditions, @default = conditions, default end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
An array of all two pairs with the first element specifying the condition and the second element specifying the result.
466 467 468 |
# File 'lib/sequel_core/sql.rb', line 466 def conditions @conditions end |
#default ⇒ Object (readonly)
The default value if no conditions are true
469 470 471 |
# File 'lib/sequel_core/sql.rb', line 469 def default @default end |
Instance Method Details
#to_s(ds) ⇒ Object
Delegate the creation of the resulting SQL to the given dataset, since it may be database dependent.
480 481 482 |
# File 'lib/sequel_core/sql.rb', line 480 def to_s(ds) ds.case_expression_sql(self) end |