Class: ActiveRecord::Refined::AST::DatetimeValueFunction

Inherits:
Node
  • Object
show all
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

Instance Method Summary collapse

Methods included from Arithmetics

#*, #+, #-, #/

Methods included from Predications

#!=, #!~, #<, #<=, #==, #=~, #>, #>=, #between?, #casecmp?, #distinct_from?, #end_with?, #ilike?, #in?, #include?, #intersect?, #like?, #member?, #not_between?, #not_distinct_from?, #not_ilike?, #not_in?, #not_like?, #not_null?, #null?, #start_with?, #subset?, #superset?

Methods inherited from Node

#as, #asc, #desc

Constructor Details

#initialize(name, precision = nil) ⇒ DatetimeValueFunction

Returns a new instance of DatetimeValueFunction.



472
473
474
475
476
477
478
479
# File 'lib/active_record/refined/ast.rb', line 472

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

#nameObject (readonly)

Returns the value of attribute name.



470
471
472
# File 'lib/active_record/refined/ast.rb', line 470

def name
  @name
end

#precisionObject (readonly)

Returns the value of attribute precision.



470
471
472
# File 'lib/active_record/refined/ast.rb', line 470

def precision
  @precision
end

Instance Method Details

#to_arel(_table) ⇒ Object



481
482
483
484
# File 'lib/active_record/refined/ast.rb', line 481

def to_arel(_table)
  Arel::Nodes::SqlLiteral.new(
    precision ? "#{name}(#{precision})" : name)
end