Class Sequel::SQL::DateAdd
In: lib/sequel/extensions/date_arithmetic.rb
Parent: GenericExpression

The DateAdd class represents the addition of an interval to a date/timestamp expression.

Methods

new  

Classes and Modules

Module Sequel::SQL::DateAdd::DatasetMethods

Attributes

expr  [R]  The expression that the interval is being added to.
interval  [R]  The interval added to the expression, as a hash with symbol keys.

Public Class methods

Supports two types of intervals:

Hash :Used directly, but values cannot be plain strings.
ActiveSupport::Duration :Converted to a hash using the interval‘s parts.

[Source]

     # File lib/sequel/extensions/date_arithmetic.rb, line 163
163:       def initialize(expr, interval)
164:         @expr = expr
165:         @interval = if interval.is_a?(Hash)
166:           interval.each_value do |v|
167:              # Attempt to prevent SQL injection by users who pass untrusted strings
168:              # as interval values. 
169:              if v.is_a?(String) && !v.is_a?(LiteralString)
170:                raise Sequel::InvalidValue, "cannot provide String value as interval part: #{v.inspect}"
171:              end
172:           end
173:           interval
174:         else
175:           h = Hash.new(0)
176:           interval.parts.each{|unit, value| h[unit] += value}
177:           {}.merge(h)
178:         end
179:       end

[Validate]