Class: ActiveRecord::Refined::AST::Cast
- Includes:
- Arithmetics, Predications
- Defined in:
- lib/active_record/refined/ast.rb
Overview
CAST(expr AS type). The type is grammar too, written into the SQL as given -- it is the adapter's own name for the type, and whether it exists is the database's to say -- so it has to look like one: a plain name, at most parenthesized with lengths.
Instance Attribute Summary collapse
-
#operand ⇒ Object
readonly
Returns the value of attribute operand.
-
#sql_type ⇒ Object
readonly
Returns the value of attribute sql_type.
Instance Method Summary collapse
-
#initialize(operand, sql_type) ⇒ Cast
constructor
A new instance of Cast.
- #to_arel(table, model) ⇒ Object
Methods included from Arithmetics
#&, #*, #+, #-, #/, #<<, #>>, #^, #|, #~
Methods included from Predications
#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #bury, #casecmp?, #contains?, #dig, #dig_json, #distinct_from?, #end_with?, #false?, #ilike?, #in?, #include?, #intersect?, #key?, #like?, #member?, #not_between?, #not_distinct_from?, #not_false?, #not_ilike?, #not_in?, #not_like?, #not_null?, #not_true?, #null?, #start_with?, #subset?, #superset?, #true?, #when
Methods inherited from Node
Constructor Details
#initialize(operand, sql_type) ⇒ Cast
Returns a new instance of Cast.
1089 1090 1091 1092 |
# File 'lib/active_record/refined/ast.rb', line 1089 def initialize(operand, sql_type) @operand = operand @sql_type = AST.check_name(sql_type, TYPE_NAME, "SQL type") end |
Instance Attribute Details
#operand ⇒ Object (readonly)
Returns the value of attribute operand.
1087 1088 1089 |
# File 'lib/active_record/refined/ast.rb', line 1087 def operand @operand end |
#sql_type ⇒ Object (readonly)
Returns the value of attribute sql_type.
1087 1088 1089 |
# File 'lib/active_record/refined/ast.rb', line 1087 def sql_type @sql_type end |
Instance Method Details
#to_arel(table, model) ⇒ Object
1094 1095 1096 1097 1098 1099 |
# File 'lib/active_record/refined/ast.rb', line 1094 def to_arel(table, model) Arel::Nodes::NamedFunction.new( "CAST", [Arel::Nodes::As.new(to_arel_argument(operand, table, model), Arel::Nodes::SqlLiteral.new(sql_type.to_s))]) end |