class Sequel::Postgres::PGMultiRange

:nocov:

Attributes

db_type[RW]

The type of this multirange (e.g. 'int4multirange').

Public Class Methods

new(ranges, db_type) click to toggle source

Set the array of ranges to delegate to, and the database type.

Calls superclass method
# File lib/sequel/extensions/pg_multirange.rb, line 265
def initialize(ranges, db_type)
  super(ranges)
  @db_type = db_type.to_s
end

Public Instance Methods

==(other) click to toggle source

Don't consider multiranges with different database types equal.

Calls superclass method
# File lib/sequel/extensions/pg_multirange.rb, line 308
def ==(other)
  return false if PGMultiRange === other && other.db_type != db_type
  super
end
===(value)
Alias for: cover?
cover?(value) click to toggle source

Return whether the value is inside any of the ranges in the multirange.

# File lib/sequel/extensions/pg_multirange.rb, line 293
def cover?(value)
  any?{|range| range.cover?(value)}
end
Also aliased as: ===
eql?(other) click to toggle source

Don't consider multiranges with different database types equal.

# File lib/sequel/extensions/pg_multirange.rb, line 299
def eql?(other)
  if PGMultiRange === other
    return false unless other.db_type == db_type
    other = other.__getobj__
  end
  __getobj__.eql?(other)
end
op() click to toggle source

Wrap the PGRange instance in an RangeOp, allowing you to easily use the PostgreSQL range functions and operators with literal ranges.

# File lib/sequel/extensions/pg_range_ops.rb, line 152
def op
  RangeOp.new(self)
end
sequel_auto_param_type(ds) click to toggle source

Allow automatic parameterization.

# File lib/sequel/extensions/pg_multirange.rb, line 340
def sequel_auto_param_type(ds)
  "::#{db_type}"
end
sql_literal_append(ds, sql) click to toggle source

Append the multirange SQL to the given sql string.

# File lib/sequel/extensions/pg_multirange.rb, line 271
def sql_literal_append(ds, sql)
  sql << db_type << '('
  joiner = nil
  conversion_meth = nil
  each do |range|
    if joiner
      sql << joiner
    else
      joiner = ', '
    end

    unless range.is_a?(PGRange)
      conversion_meth ||= :"typecast_value_#{db_type.sub('multi', '')}"
      range = ds.db.send(conversion_meth, range)
    end

    ds.literal_append(sql, range)
  end
  sql << ')'
end
unquoted_literal(ds) click to toggle source

Return a string containing the unescaped version of the multirange. Separated out for use by the bound argument code.

# File lib/sequel/extensions/pg_multirange.rb, line 315
def unquoted_literal(ds)
  val = String.new
  val << "{"

  joiner = nil
  conversion_meth = nil
  each do |range|
    if joiner
      val << joiner
    else
      joiner = ', '
    end

    unless range.is_a?(PGRange)
      conversion_meth ||= :"typecast_value_#{db_type.sub('multi', '')}"
      range = ds.db.send(conversion_meth, range)
    end

    val << range.unquoted_literal(ds)
  end
   
  val << "}"
end