Class: Sequel::SQL::CaseExpression
- Inherits:
-
GenericExpression
- Object
- Expression
- GenericExpression
- Sequel::SQL::CaseExpression
- Defined in:
- lib/sequel/sql.rb
Overview
Represents an SQL CASE expression, used for conditional branching in SQL.
Instance Attribute Summary (collapse)
-
- (Object) conditions
readonly
An array of all two pairs with the first element specifying the condition and the second element specifying the result if the condition matches.
-
- (Object) default
readonly
The default value if no conditions match.
-
- (Object) expression
readonly
The expression to test the conditions against.
Instance Method Summary (collapse)
-
- (Boolean) expression?
Whether to use an expression for this CASE expression.
-
- (CaseExpression) initialize(conditions, default, expression = (no_expression=true; nil))
constructor
Create an object with the given conditions and default value.
Methods included from Postgres::HStoreOpMethods
Methods included from Postgres::ArrayOpMethods
Methods included from SubscriptMethods
Methods included from StringMethods
Methods included from OrderMethods
Methods included from NumericMethods
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
Methods inherited from Expression
#==, attr_reader, comparison_attrs, #eql?, #hash, #inspect, #lit, #sql_literal, to_s_method
Constructor Details
- (CaseExpression) initialize(conditions, default, expression = (no_expression=true; nil))
Create an object with the given conditions and default value. An expression can be provided to test each condition against, instead of having all conditions represent their own boolean expression.
644 645 646 647 |
# File 'lib/sequel/sql.rb', line 644 def initialize(conditions, default, expression=(no_expression=true; nil)) raise(Sequel::Error, 'CaseExpression conditions must be a hash or array of all two pairs') unless Sequel.condition_specifier?(conditions) @conditions, @default, @expression, @no_expression = conditions.to_a, default, expression, no_expression end |
Instance Attribute Details
- (Object) conditions (readonly)
An array of all two pairs with the first element specifying the condition and the second element specifying the result if the condition matches.
632 633 634 |
# File 'lib/sequel/sql.rb', line 632 def conditions @conditions end |
- (Object) default (readonly)
The default value if no conditions match.
635 636 637 |
# File 'lib/sequel/sql.rb', line 635 def default @default end |
- (Object) expression (readonly)
The expression to test the conditions against
638 639 640 |
# File 'lib/sequel/sql.rb', line 638 def expression @expression end |
Instance Method Details
- (Boolean) expression?
Whether to use an expression for this CASE expression.
650 651 652 |
# File 'lib/sequel/sql.rb', line 650 def expression? !@no_expression end |