Class: Arel::Nodes::Case
- Includes:
- AliasPredication, OrderPredications, Predications
- Defined in:
- lib/arel/nodes/case.rb
Instance Attribute Summary collapse
-
#case ⇒ Object
Returns the value of attribute case.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#default ⇒ Object
Returns the value of attribute default.
Instance Method Summary collapse
- #else(expression) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(expression = nil, default = nil) ⇒ Case
constructor
A new instance of Case.
- #initialize_copy(other) ⇒ Object
- #then(expression) ⇒ Object
- #when(condition, expression = nil) ⇒ Object
Methods included from AliasPredication
Methods included from Predications
#between, #concat, #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, #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
Methods included from OrderPredications
Methods inherited from Node
#_caller, #and, #each, #not, #or, #to_sql
Methods included from FactoryMethods
#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.
10 11 12 13 14 |
# File 'lib/arel/nodes/case.rb', line 10 def initialize expression = nil, default = nil @case = expression @conditions = [] @default = default end |
Instance Attribute Details
#case ⇒ Object
Returns the value of attribute case.
8 9 10 |
# File 'lib/arel/nodes/case.rb', line 8 def case @case end |
#conditions ⇒ Object
Returns the value of attribute conditions.
8 9 10 |
# File 'lib/arel/nodes/case.rb', line 8 def conditions @conditions end |
#default ⇒ Object
Returns the value of attribute default.
8 9 10 |
# File 'lib/arel/nodes/case.rb', line 8 def default @default end |
Instance Method Details
#else(expression) ⇒ Object
26 27 28 29 |
# File 'lib/arel/nodes/case.rb', line 26 def else expression @default = Else.new Nodes.build_quoted(expression) self end |
#eql?(other) ⇒ Boolean Also known as: ==
42 43 44 45 46 47 |
# File 'lib/arel/nodes/case.rb', line 42 def eql? other self.class == other.class && self.case == other.case && self.conditions == other.conditions && self.default == other.default end |
#hash ⇒ Object
38 39 40 |
# File 'lib/arel/nodes/case.rb', line 38 def hash [@case, @conditions, @default].hash end |
#initialize_copy(other) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/arel/nodes/case.rb', line 31 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
21 22 23 24 |
# File 'lib/arel/nodes/case.rb', line 21 def then expression @conditions.last.right = Nodes.build_quoted(expression) self end |
#when(condition, expression = nil) ⇒ Object
16 17 18 19 |
# File 'lib/arel/nodes/case.rb', line 16 def when condition, expression = nil @conditions << When.new(Nodes.build_quoted(condition), expression) self end |