Class: ActiveRecord::Refined::AST::DatetimeValueFunction
- Includes:
- Arithmetics, Predications
- Defined in:
- lib/active_record/refined/ast.rb
Overview
CURRENT_TIMESTAMP and its relatives, what the SQL grammar calls a datetime value function. The grammar has them bare, and PostgreSQL and SQLite reject them written as calls, so unlike Function the name is emitted without parentheses. A precision is the one thing that does go into parentheses, and it is written into the SQL as given, so only an Integer is accepted.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
Instance Method Summary collapse
-
#initialize(name, precision = nil) ⇒ DatetimeValueFunction
constructor
A new instance of DatetimeValueFunction.
- #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(name, precision = nil) ⇒ DatetimeValueFunction
Returns a new instance of DatetimeValueFunction.
1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'lib/active_record/refined/ast.rb', line 1110 def initialize(name, precision = nil) unless precision.nil? || precision.is_a?(Integer) raise ArgumentError, "#{precision.inspect} is not an Integer precision" end @name = name @precision = precision end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
1108 1109 1110 |
# File 'lib/active_record/refined/ast.rb', line 1108 def name @name end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
1108 1109 1110 |
# File 'lib/active_record/refined/ast.rb', line 1108 def precision @precision end |
Instance Method Details
#to_arel(_table, _model) ⇒ Object
1119 1120 1121 1122 |
# File 'lib/active_record/refined/ast.rb', line 1119 def to_arel(_table, _model) Arel::Nodes::SqlLiteral.new( precision ? "#{name}(#{precision})" : name) end |