Class: PG::CompositeCoder
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Coder
|
|
Instance Chain:
self,
Coder
|
|
Inherits: | PG::Coder |
Defined in: | ext/pg_coder.c, ext/pg_coder.c, lib/pg/coder.rb |
Overview
This is the base class for all type cast classes of PostgreSQL types, that are made up of some sub type.
See TextEncoder::Array
, TextDecoder::Array
, BinaryEncoder::Array
, BinaryDecoder::Array
, etc.
Constant Summary
Coder
- Inherited
FORMAT_ERROR_MASK, FORMAT_ERROR_TO_PARTIAL, FORMAT_ERROR_TO_RAISE, FORMAT_ERROR_TO_STRING, TIMESTAMP_APP_LOCAL, TIMESTAMP_APP_UTC, TIMESTAMP_DB_LOCAL, TIMESTAMP_DB_UTC
Class Method Summary
Instance Attribute Summary
-
#delimiter ⇒ String
rw
The character that separates values within the composite type.
-
#delimiter=(String)
rw
Specifies the character that separates values within the composite type.
-
#dimensions ⇒ Integer | nil
rw
Get number of enforced array dimensions or
nil
if not set. -
#dimensions=(Integer)
rw
Set number of array dimensions to be encoded.
- #elements_type readonly
-
#needs_quotation=(Boolean)
rw
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
-
#needs_quotation ⇒ Boolean
rw
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
Coder
- Inherited
#flags | Get current bitwise OR-ed coder flags. |
#flags= | Set coder specific bitwise OR-ed flags. |
#format | The format code that is sent alongside with an encoded query parameter value. |
#format= | Specifies the format code that is sent alongside with an encoded query parameter value. |
#name | Name of the coder or the corresponding data type. |
#oid | The type OID that is sent alongside with an encoded query parameter value. |
#oid= | Specifies the type OID that is sent alongside with an encoded query parameter value. |
Instance Method Summary
-
#elements_type=(coder)
readonly
Specifies the
Coder
object that is used to encode or decode the single elementes of this composite type. - #inspect
- #to_h
Coder
- Inherited
#==, #dup, #inspect, #inspect_short, #marshal_dump, #marshal_load, | |
#to_h | Returns coder attributes as Hash. |
Constructor Details
This class inherits a constructor from PG::Coder
Instance Attribute Details
#delimiter ⇒ String
(rw)
The character that separates values within the composite type.
# File 'ext/pg_coder.c', line 419
static VALUE pg_coder_delimiter_get(VALUE self) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); return rb_str_new(&this->delimiter, 1); }
#delimiter=(String) (rw)
Specifies the character that separates values within the composite type. The default is a comma. This must be a single one-byte character.
# File 'ext/pg_coder.c', line 401
static VALUE pg_coder_delimiter_set(VALUE self, VALUE delimiter) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); StringValue(delimiter); if(RSTRING_LEN(delimiter) != 1) rb_raise( rb_eArgError, "delimiter size must be one byte"); this->delimiter = *RSTRING_PTR(delimiter); return delimiter; }
#dimensions ⇒ Integer
| nil
(rw)
Get number of enforced array dimensions or nil
if not set.
See #dimensions=
# File 'ext/pg_coder.c', line 462
static VALUE pg_coder_dimensions_get(VALUE self) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); return this->dimensions < 0 ? Qnil : INT2NUM(this->dimensions); }
#dimensions=(Integer) (rw)
#dimensions=(nil)
Set number of array dimensions to be encoded.
This property ensures, that this number of dimensions is always encoded. If less dimensions than this number are in the given value, an ArgumentError is raised. If more dimensions than this number are in the value, the Array value is passed to the next encoder.
Setting dimensions is especially useful, when a Record shall be encoded into an Array, since the Array encoder can not distinguish if the array shall be encoded as a higher dimension or as a record otherwise.
The default is nil
.
See #dimensions
# File 'ext/pg_coder.c', line 443
static VALUE pg_coder_dimensions_set(VALUE self, VALUE dimensions) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); if(!NIL_P(dimensions) && NUM2INT(dimensions) < 0) rb_raise( rb_eArgError, "dimensions must be nil or >= 0"); this->dimensions = NIL_P(dimensions) ? -1 : NUM2INT(dimensions); return dimensions; }
#elements_type (readonly)
[ GitHub ]#needs_quotation=(Boolean) (rw)
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely. Encoding with #needs_quotation=false is somewhat faster.
The default is true
. This option is ignored for decoding of values.
# File 'ext/pg_coder.c', line 370
static VALUE pg_coder_needs_quotation_set(VALUE self, VALUE needs_quotation) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); rb_check_frozen(self); this->needs_quotation = RTEST(needs_quotation); return needs_quotation; }
#needs_quotation ⇒ Boolean
(rw)
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
# File 'ext/pg_coder.c', line 386
static VALUE pg_coder_needs_quotation_get(VALUE self) { t_pg_composite_coder *this = RTYPEDDATA_DATA(self); return this->needs_quotation ? Qtrue : Qfalse; }
Instance Method Details
#elements_type=(coder) (readonly)
Specifies the Coder
object that is used to encode or decode the single elementes of this composite type.
If set to nil
all values are encoded and decoded as String objects.
# File 'ext/pg_coder.c', line 478
static VALUE pg_coder_elements_type_set(VALUE self, VALUE elem_type) { t_pg_composite_coder *this = RTYPEDDATA_DATA( self ); rb_check_frozen(self); if ( NIL_P(elem_type) ){ this->elem = NULL; } else if ( rb_obj_is_kind_of(elem_type, rb_cPG_Coder) ){ this->elem = RTYPEDDATA_DATA( elem_type ); } else { rb_raise( rb_eTypeError, "wrong elements type %s (expected some kind of PG::Coder)", rb_obj_classname( elem_type ) ); } rb_iv_set( self, "@elements_type", elem_type ); return elem_type; }
#inspect
[ GitHub ]# File 'lib/pg/coder.rb', line 83
def inspect str = super str[-1,0] = " elements_type=#{elements_type.inspect} #{needs_quotation? ? 'needs' : 'no'} quotation#{dimensions && " #{dimensions} dimensions"}" str end
#to_h
[ GitHub ]# File 'lib/pg/coder.rb', line 74
def to_h { **super, elements_type: elements_type, needs_quotation: needs_quotation?, delimiter: delimiter, dimensions: dimensions, } end