Class | Sequel::Postgres::PGRow::Parser
In: | lib/sequel/extensions/pg_row.rb
Parent: | Object

The Parser is responsible for taking the input string from PostgreSQL, and returning an appropriate ruby object that the type represents, such as an ArrayRow or HashRow.

### Methods

call new typecast

### Attributes

column_converters | [R] | Converters for each member in the composite type. If not present, no conversion will be done, so values will remain strings. If present, should be an array of callable objects.
column_oids | [R] | The OIDs for each member in the composite type. Not currently used, but made available for user code.
columns | [R] | The columns for the parser, if any. If the parser has no columns, it will treat the input as an array. If it has columns, it will treat the input as a hash. If present, should be an array of strings.
converter | [R] | A converter for the object as a whole. Used to wrap the returned array/hash in another object, such as an ArrayRow or HashRow. If present, should be callable.
oid | [R] | The oid for the composite type itself.
typecaster | [R] | A callable object used for typecasting the object. This is similar to the converter, but it is called by the typecasting code, which has different assumptions than the converter. For instance, the converter should be called with all of the member values already typecast, but the typecaster may not be.

### Public Class methods

new(h={})

Sets each of the parser‘s attributes, using options with the same name (e.g. :columns sets the columns attribute).

[Source]

         # File lib/sequel/extensions/pg_row.rb, line 274
    274:         def initialize(h={})
    275:           @columns = h[:columns]
    276:           @column_converters = h[:column_converters]
    277:           @column_oids = h[:column_oids]
    278:           @converter = h[:converter]
    279:           @typecaster = h[:typecaster]
    280:           @oid = h[:oid]
    281:         end

### Public Instance methods

call(s)

Convert the PostgreSQL composite type input format into an appropriate ruby object.

[Source]

         # File lib/sequel/extensions/pg_row.rb, line 285
    285:         def call(s)
    286:           convert(convert_format(convert_columns(Splitter.new(s).parse)))
    287:         end

typecast(obj)

Typecast the given object to the appropriate type using the typecaster. Note that this does not conversion for the members of the composite type, since those conversion expect strings and strings may not be provided.

[Source]

         # File lib/sequel/extensions/pg_row.rb, line 293
    293:         def typecast(obj)
    294:           case obj
    295:           when Array
    296:             _typecast(convert_format(obj))
    297:           when Hash
    298:             unless @columns
    299:               raise Error, 'PGRow::Parser without columns cannot typecast from a hash'
    300:             end
    301:             _typecast(obj)
    302:           else
    303:             raise Error, 'PGRow::Parser can only typecast arrays and hashes'
    304:           end
    305:         end

[Validate]