class Sequel::JDBC::Postgres::Dataset::PGArrayConverter

Handle conversions of PostgreSQL array instances

Public Class Methods

new(meth) click to toggle source

Set the method that will return the correct conversion proc for elements of this array.

# File lib/sequel/adapters/jdbc/postgresql.rb, line 116
def initialize(meth)
  @conversion_proc_method = meth
  @conversion_proc = nil
end

Public Instance Methods

call(v) click to toggle source

Convert Java::OrgPostgresqlJdbc4::Jdbc4Array to ruby arrays

# File lib/sequel/adapters/jdbc/postgresql.rb, line 122
def call(v)
  _pg_array(v.array)
end

Private Instance Methods

_pg_array(v) click to toggle source

Handle multi-dimensional Java arrays by recursively mapping them to ruby arrays of ruby values.

# File lib/sequel/adapters/jdbc/postgresql.rb, line 130
def _pg_array(v)
  v.to_ary.map do |i|
    if i.respond_to?(:to_ary)
      _pg_array(i)
    elsif i
      if @conversion_proc.nil?
        @conversion_proc = @conversion_proc_method.call(i)
      end
      if @conversion_proc
        @conversion_proc.call(i)
      else
        i
      end
    else
      i
    end
  end
end