Class: PG::TypeMapByMriType
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
TypeMap
|
|
Instance Chain:
|
|
Inherits: |
PG::TypeMap
|
Defined in: | ext/pg_type_map_by_mri_type.c |
Overview
This type map casts values based on the Ruby object type code of the given value to be sent.
This type map is usable for type casting query bind parameters and COPY data for Connection#put_copy_data . Therefore only encoders might be assigned by the #[]= method.
Note : This type map is not portable across Ruby implementations and is less flexible than TypeMapByClass
. It is kept only for performance comparisons, but TypeMapByClass
proved to be equally fast in almost all cases.
Instance Attribute Summary
TypeMap::DefaultTypeMappable
- Included
#default_type_map | Returns the default |
#default_type_map= | Set the default |
Instance Method Summary
-
#[](mri_type) ⇒ coder
Returns the encoder object for the given
mri_type
-
#[]=(mri_type, coder)
Assigns a new
Coder
object to the type map. -
#coders ⇒ Hash
Returns all mri types and their assigned encoder object.
TypeMap::DefaultTypeMappable
- Included
#with_default_type_map | Set the default |
Instance Method Details
#[](mri_type) ⇒ coder
Returns the encoder object for the given mri_type
See #[]= for allowed mri_type
.
# File 'ext/pg_type_map_by_mri_type.c', line 248
static VALUE pg_tmbmt_aref( VALUE self, VALUE mri_type ) { VALUE coder; t_tmbmt *this = RTYPEDDATA_DATA( self ); char *p_mri_type; p_mri_type = StringValueCStr(mri_type); if(0){} FOR_EACH_MRI_TYPE( COMPARE_AND_GET ) else{ VALUE mri_type_inspect = rb_inspect( mri_type ); rb_raise(rb_eArgError, "unknown mri_type %s", StringValueCStr(mri_type_inspect)); } return coder; }
#[]=(mri_type, coder)
Assigns a new Coder
object to the type map. The encoder is registered for type casts of the given mri_type
.
coder
can be one of the following:
-
nil
- Values are forwarded to the#default_type_map
. -
a
Coder
- Values are encoded by the given encoder -
a Symbol - The method of this type map (or a derivation) that is called for each value to sent. It must return a PG::Coder.
-
a Proc - The Proc object is called for each value. It must return a
Coder
.
mri_type
must be one of the following strings:
-
T_FIXNUM
-
T_TRUE
-
T_FALSE
-
T_FLOAT
-
T_BIGNUM
-
T_COMPLEX
-
T_RATIONAL
-
T_ARRAY
-
T_STRING
-
T_SYMBOL
-
T_OBJECT
-
T_CLASS
-
T_MODULE
-
T_REGEXP
-
T_HASH
-
T_STRUCT
-
T_FILE
-
T_DATA
# File 'ext/pg_type_map_by_mri_type.c', line 217
static VALUE pg_tmbmt_aset( VALUE self, VALUE mri_type, VALUE coder ) { t_tmbmt *this = RTYPEDDATA_DATA( self ); char *p_mri_type; p_mri_type = StringValueCStr(mri_type); if(0){} FOR_EACH_MRI_TYPE( COMPARE_AND_ASSIGN ) else{ VALUE mri_type_inspect = rb_inspect( mri_type ); rb_raise(rb_eArgError, "unknown mri_type %s", StringValueCStr(mri_type_inspect)); } return self; }
#coders ⇒ Hash
Returns all mri types and their assigned encoder object.
# File 'ext/pg_type_map_by_mri_type.c', line 277
static VALUE pg_tmbmt_coders( VALUE self ) { t_tmbmt *this = RTYPEDDATA_DATA( self ); VALUE hash_coders = rb_hash_new(); FOR_EACH_MRI_TYPE( ADD_TO_HASH ); return rb_obj_freeze(hash_coders); }