Classes and Modules
Constants
DURATION_UNITS | = | [:years, :months, :weeks, :days, :hours, :minutes, :seconds].freeze | ||
PARSER | = | Parser.new |
Single instance of |
Public Class methods
extended(db)
Reset the conversion procs if using the native postgres adapter, and extend the datasets to correctly literalize ActiveSupport::Duration values.
[show source]
# File lib/sequel/extensions/pg_interval.rb 143 def self.extended(db) 144 db.instance_exec do 145 extend_datasets(IntervalDatasetMethods) 146 add_conversion_proc(1186, Postgres::IntervalDatabaseMethods::PARSER) 147 if respond_to?(:register_array_type) 148 register_array_type('interval', :oid=>1187, :scalar_oid=>1186) 149 end 150 @schema_type_classes[:interval] = ActiveSupport::Duration 151 end 152 end
literal_duration(duration)
Return an unquoted string version of the duration object suitable for use as a bound variable.
[show source]
# File lib/sequel/extensions/pg_interval.rb 52 def self.literal_duration(duration) 53 h = Hash.new(0) 54 duration.parts.each{|unit, value| h[unit] += value} 55 s = String.new 56 57 DURATION_UNITS.each do |unit| 58 if (v = h[unit]) != 0 59 s << "#{v.is_a?(Integer) ? v : sprintf('%0.6f', v)} #{unit} " 60 end 61 end 62 63 if s.empty? 64 '0' 65 else 66 s 67 end 68 end
Public Instance methods
bound_variable_arg(arg, conn)
Handle ActiveSupport::Duration values in bound variables.
[show source]
# File lib/sequel/extensions/pg_interval.rb 155 def bound_variable_arg(arg, conn) 156 case arg 157 when ActiveSupport::Duration 158 IntervalDatabaseMethods.literal_duration(arg) 159 else 160 super 161 end 162 end