Skip to content

Commit

Permalink
Add missing documentation to some coder classes
Browse files Browse the repository at this point in the history
... and mention that they require extensions on first use.
  • Loading branch information
larskanis committed Aug 2, 2024
1 parent 0ac827c commit 0c850b3
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/pg_binary_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ j2date(int jd, int *year, int *month, int *day)
*
* This is a decoder class for conversion of PostgreSQL binary date
* to Ruby Date objects.
*
* As soon as this class is used, it requires the ruby standard library 'date'.
*/
static VALUE
pg_bin_dec_date(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
Expand Down
3 changes: 3 additions & 0 deletions ext/pg_text_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pg_text_dec_integer(t_pg_coder *conv, const char *val, int len, int tuple, int f
* This is a decoder class for conversion of PostgreSQL numeric types
* to Ruby BigDecimal objects.
*
* As soon as this class is used, it requires the 'bigdecimal' gem.
*
*/
static VALUE
pg_text_dec_numeric(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
Expand Down Expand Up @@ -811,6 +813,7 @@ static VALUE pg_text_dec_timestamp(t_pg_coder *conv, const char *val, int len, i
* This is a decoder class for conversion of PostgreSQL inet type
* to Ruby IPAddr values.
*
* As soon as this class is used, it requires the ruby standard library 'ipaddr'.
*/
static VALUE
pg_text_dec_inet(t_pg_coder *conv, const char *val, int len, int tuple, int field, int enc_idx)
Expand Down
2 changes: 2 additions & 0 deletions ext/pg_text_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ pg_text_enc_float(t_pg_coder *conv, VALUE value, char *out, VALUE *intermediate,
*
* It converts Integer, Float and BigDecimal objects.
* All other objects are expected to respond to +to_s+.
*
* As soon as this class is used, it requires the 'bigdecimal' gem.
*/
static int
pg_text_enc_numeric(t_pg_coder *this, VALUE value, char *out, VALUE *intermediate, int enc_idx)
Expand Down
3 changes: 3 additions & 0 deletions lib/pg/text_decoder/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

module PG
module TextDecoder
# This is a decoder class for conversion of PostgreSQL date type to Ruby Date values.
#
# As soon as this class is used, it requires the ruby standard library 'date'.
class Date < SimpleDecoder
def decode(string, tuple=nil, field=nil)
if string =~ /\A(\d{4})-(\d\d)-(\d\d)\z/
Expand Down
3 changes: 3 additions & 0 deletions lib/pg/text_decoder/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

module PG
module TextDecoder
# This is a decoder class for conversion of PostgreSQL JSON/JSONB type to Ruby Hash, Array, String, Numeric, nil values.
#
# As soon as this class is used, it requires the ruby standard library 'json'.
class JSON < SimpleDecoder
def decode(string, tuple=nil, field=nil)
::JSON.parse(string, quirks_mode: true)
Expand Down
1 change: 1 addition & 0 deletions lib/pg/text_encoder/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

module PG
module TextEncoder
# This is a encoder class for conversion of Ruby Date values to PostgreSQL date type.
class Date < SimpleEncoder
def encode(value)
value.respond_to?(:strftime) ? value.strftime("%Y-%m-%d") : value
Expand Down
3 changes: 3 additions & 0 deletions lib/pg/text_encoder/inet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

module PG
module TextEncoder
# This is a encoder class for conversion of Ruby IPAddr values to PostgreSQL inet type.
#
# As soon as this class is used, it requires the ruby standard library 'ipaddr'.
class Inet < SimpleEncoder
def encode(value)
case value
Expand Down
3 changes: 3 additions & 0 deletions lib/pg/text_encoder/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

module PG
module TextEncoder
# This is a encoder class for conversion of Ruby Hash, Array, String, Numeric, nil values to PostgreSQL JSON/JSONB type.
#
# As soon as this class is used, it requires the ruby standard library 'json'.
class JSON < SimpleEncoder
def encode(value)
::JSON.generate(value, quirks_mode: true)
Expand Down

0 comments on commit 0c850b3

Please sign in to comment.