Class: PG::Coder
Overview
This is the base class for all type cast encoder and decoder classes.
It can be used for implicit type casts by a TypeMap
or to convert single values to/from their string representation by #encode
and #decode
.
Ruby nil
values are not handled by encoders, but are always transmitted as SQL NULL
value. Vice versa SQL NULL
values are not handled by decoders, but are always returned as a nil
value.
Constant Summary
-
FORMAT_ERROR_MASK =
# File 'ext/pg_coder.c', line 579INT2NUM(PG_CODER_FORMAT_ERROR_MASK)
-
FORMAT_ERROR_TO_PARTIAL =
# File 'ext/pg_coder.c', line 582INT2NUM(PG_CODER_FORMAT_ERROR_TO_PARTIAL)
-
FORMAT_ERROR_TO_RAISE =
# File 'ext/pg_coder.c', line 580INT2NUM(PG_CODER_FORMAT_ERROR_TO_RAISE)
-
FORMAT_ERROR_TO_STRING =
# File 'ext/pg_coder.c', line 581INT2NUM(PG_CODER_FORMAT_ERROR_TO_STRING)
-
TIMESTAMP_APP_LOCAL =
# File 'ext/pg_coder.c', line 578INT2NUM(PG_CODER_TIMESTAMP_APP_LOCAL)
-
TIMESTAMP_APP_UTC =
# File 'ext/pg_coder.c', line 577INT2NUM(PG_CODER_TIMESTAMP_APP_UTC)
-
TIMESTAMP_DB_LOCAL =
# File 'ext/pg_coder.c', line 576INT2NUM(PG_CODER_TIMESTAMP_DB_LOCAL)
-
TIMESTAMP_DB_UTC =
:Coder#flags=
define flags to be used with PG
Class Method Summary
-
.new(hash = nil, **kwargs) ⇒ Coder
constructor
Create a new coder object based on the attribute Hash.
Instance Attribute Summary
-
#flags ⇒ Integer
rw
Get current bitwise OR-ed coder flags.
-
#flags=(Integer)
rw
Set coder specific bitwise OR-ed flags.
-
#format ⇒ Integer
rw
The format code that is sent alongside with an encoded query parameter value.
-
#format=(Integer)
rw
Specifies the format code that is sent alongside with an encoded query parameter value.
-
#name
rw
Name of the coder or the corresponding data type.
-
#oid ⇒ Integer
rw
The type OID that is sent alongside with an encoded query parameter value.
-
#oid=(Integer)
rw
Specifies the type OID that is sent alongside with an encoded query parameter value.
Instance Method Summary
- #==(v)
- #dup
- #inspect
- #inspect_short
- #marshal_dump
- #marshal_load(str)
-
#to_h
Returns coder attributes as Hash.
Constructor Details
.new(hash = nil, **kwargs) ⇒ Coder
Create a new coder object based on the attribute Hash.
# File 'lib/pg/coder.rb', line 17
def initialize(hash=nil, **kwargs) warn("PG::Coder.new(hash) is deprecated. Please use keyword arguments instead! Called from #{caller.first}", category: :deprecated) if hash (hash || kwargs).each do |key, val| send("#{key}=", val) end end
Instance Attribute Details
#flags ⇒ Integer
(rw)
Get current bitwise OR-ed coder flags.
# File 'ext/pg_coder.c', line 351
static VALUE pg_coder_flags_get(VALUE self) { t_pg_coder *this = RTYPEDDATA_DATA(self); return INT2NUM(this->flags); }
#flags=(Integer) (rw)
Set coder specific bitwise OR-ed flags. See the particular en- or decoder description for available flags.
The default is 0
.
# File 'ext/pg_coder.c', line 336
static VALUE pg_coder_flags_set(VALUE self, VALUE flags) { t_pg_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); this->flags = NUM2INT(flags); return flags; }
#format ⇒ Integer
(rw)
The format code that is sent alongside with an encoded query parameter value.
# File 'ext/pg_coder.c', line 320
static VALUE pg_coder_format_get(VALUE self) { t_pg_coder *this = RTYPEDDATA_DATA(self); return INT2NUM(this->format); }
#format=(Integer) (rw)
Specifies the format code that is sent alongside with an encoded query parameter value.
The default is 0
.
# File 'ext/pg_coder.c', line 304
static VALUE pg_coder_format_set(VALUE self, VALUE format) { t_pg_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); this->format = NUM2INT(format); return format; }
#name (rw)
Name of the coder or the corresponding data type.
This accessor is only used in #inspect .
#oid ⇒ Integer
(rw)
The type OID that is sent alongside with an encoded query parameter value.
# File 'ext/pg_coder.c', line 288
static VALUE pg_coder_oid_get(VALUE self) { t_pg_coder *this = RTYPEDDATA_DATA(self); return UINT2NUM(this->oid); }
#oid=(Integer) (rw)
Specifies the type OID that is sent alongside with an encoded query parameter value.
The default is 0
.
# File 'ext/pg_coder.c', line 272
static VALUE pg_coder_oid_set(VALUE self, VALUE oid) { t_pg_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); this->oid = NUM2UINT(oid); return oid; }
Instance Method Details
#==(v)
[ GitHub ]#dup
[ GitHub ]#inspect
[ GitHub ]#inspect_short
[ GitHub ]#marshal_dump
[ GitHub ]# File 'lib/pg/coder.rb', line 43
def marshal_dump Marshal.dump(to_h) end
#marshal_load(str)
[ GitHub ]# File 'lib/pg/coder.rb', line 47
def marshal_load(str) initialize(**Marshal.load(str)) end
#to_h
Returns coder attributes as Hash.