Class: PG::CompositeCoder
- Defined in:
- ext/pg_coder.c,
lib/pg/coder.rb,
ext/pg_coder.c
Overview
This is the base class for all type cast classes of PostgreSQL types, that are made up of some sub type.
Direct Known Subclasses
Constant Summary
Constants inherited from Coder
PG::Coder::FORMAT_ERROR_MASK, PG::Coder::FORMAT_ERROR_TO_PARTIAL, PG::Coder::FORMAT_ERROR_TO_RAISE, PG::Coder::FORMAT_ERROR_TO_STRING, PG::Coder::TIMESTAMP_APP_LOCAL, PG::Coder::TIMESTAMP_APP_UTC, PG::Coder::TIMESTAMP_DB_LOCAL, PG::Coder::TIMESTAMP_DB_UTC
Instance Attribute Summary collapse
- #elements_type ⇒ Object readonly
Attributes inherited from Coder
Instance Method Summary collapse
-
#delimiter ⇒ String
The character that separates values within the composite type.
-
#delimiter=(String) ⇒ Object
Specifies the character that separates values within the composite type.
-
#elements_type(coder) ⇒ Object
readonly
Specifies the PG::Coder object that is used to encode or decode the single elementes of this composite type.
- #inspect ⇒ Object
-
#needs_quotation=(Boolean) ⇒ Object
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
-
#needs_quotation ⇒ Boolean
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
- #to_h ⇒ Object
Methods inherited from Coder
#==, #dup, #flags, #flags=, #format, #format=, #initialize, #inspect_short, #marshal_dump, #marshal_load, #oid, #oid=
Constructor Details
This class inherits a constructor from PG::Coder
Instance Attribute Details
#elements_type ⇒ Object (readonly)
Instance Method Details
#delimiter ⇒ String
The character that separates values within the composite type.
358 359 360 361 362 363 |
# File 'ext/pg_coder.c', line 358 static VALUE pg_coder_delimiter_get(VALUE self) { t_pg_composite_coder *this = DATA_PTR(self); return rb_str_new(&this->delimiter, 1); } |
#delimiter=(String) ⇒ Object
Specifies the character that separates values within the composite type. The default is a comma. This must be a single one-byte character.
341 342 343 344 345 346 347 348 349 350 |
# File 'ext/pg_coder.c', line 341 static VALUE pg_coder_delimiter_set(VALUE self, VALUE delimiter) { t_pg_composite_coder *this = DATA_PTR(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; } |
#elements_type=(coder) ⇒ Object (readonly)
Specifies the PG::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.
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'ext/pg_coder.c', line 374 static VALUE pg_coder_elements_type_set(VALUE self, VALUE elem_type) { t_pg_composite_coder *this = DATA_PTR( self ); if ( NIL_P(elem_type) ){ this->elem = NULL; } else if ( rb_obj_is_kind_of(elem_type, rb_cPG_Coder) ){ this->elem = DATA_PTR( 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 ⇒ Object
80 81 82 83 84 |
# File 'lib/pg/coder.rb', line 80 def inspect str = super str[-1,0] = " elements_type=#{elements_type.inspect} #{needs_quotation? ? 'needs' : 'no'} quotation" str end |
#needs_quotation=(Boolean) ⇒ Object
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.
311 312 313 314 315 316 317 |
# File 'ext/pg_coder.c', line 311 static VALUE pg_coder_needs_quotation_set(VALUE self, VALUE needs_quotation) { t_pg_composite_coder *this = DATA_PTR(self); this->needs_quotation = RTEST(needs_quotation); return needs_quotation; } |
#needs_quotation ⇒ Boolean
Specifies whether the assigned #elements_type requires quotation marks to be transferred safely.
326 327 328 329 330 331 |
# File 'ext/pg_coder.c', line 326 static VALUE pg_coder_needs_quotation_get(VALUE self) { t_pg_composite_coder *this = DATA_PTR(self); return this->needs_quotation ? Qtrue : Qfalse; } |
#to_h ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/pg/coder.rb', line 72 def to_h super.merge!({ elements_type: elements_type, needs_quotation: needs_quotation?, delimiter: delimiter, }) end |