Skip to content

Commit

Permalink
Don't print a warning when bigdecimal is required on ruby-3.4+
Browse files Browse the repository at this point in the history
Ruby-3.4+ prints a warning, if bigdecimal is required but not in the Gemfile.
But it's a false positive, since we enable bigdecimal depending features only if it's available.
And most people don't need these features.

Fixes #569
  • Loading branch information
larskanis committed Jul 28, 2024
1 parent 1a94b12 commit a629d14
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ext/pg_text_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pg_text_dec_numeric(t_pg_coder *conv, const char *val, int len, int tuple, int f
static VALUE
init_pg_text_decoder_numeric(VALUE rb_mPG_TextDecoder)
{
rb_require("bigdecimal");
rb_funcall(rb_mPG, rb_intern("require_bigdecimal_without_warning"), 0);
s_id_BigDecimal = rb_intern("BigDecimal");

/* dummy = rb_define_class_under( rb_mPG_TextDecoder, "Numeric", rb_cPG_SimpleDecoder ); */
Expand Down
2 changes: 1 addition & 1 deletion ext/pg_text_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ init_pg_text_encoder_numeric(VALUE rb_mPG_TextDecoder)
{
s_str_F = rb_str_freeze(rb_str_new_cstr("F"));
rb_global_variable(&s_str_F);
rb_require("bigdecimal");
rb_funcall(rb_mPG, rb_intern("require_bigdecimal_without_warning"), 0);
s_cBigDecimal = rb_const_get(rb_cObject, rb_intern("BigDecimal"));

/* dummy = rb_define_class_under( rb_mPG_TextEncoder, "Numeric", rb_cPG_SimpleEncoder ); */
Expand Down
10 changes: 10 additions & 0 deletions lib/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ def warn(str, category=nil)
Warning.extend(TruffleFixWarn)
end

# Ruby-3.4+ prints a warning, if bigdecimal is required but not in the Gemfile.
# But it's a false positive, since we enable bigdecimal depending features only if it's available.
# And most people don't need these features.
def self.require_bigdecimal_without_warning
oldverb, $VERBOSE = $VERBOSE, nil
require "bigdecimal"
ensure
$VERBOSE = oldverb
end

end # module PG
2 changes: 1 addition & 1 deletion lib/pg/basic_type_map_for_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_array_type(value)
end

begin
require "bigdecimal"
PG.require_bigdecimal_without_warning
has_bigdecimal = true
rescue LoadError
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pg/basic_type_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def register_default_types
alias_type 0, 'oid', 'int2'

begin
require "bigdecimal"
PG.require_bigdecimal_without_warning
register_type 0, 'numeric', PG::TextEncoder::Numeric, PG::TextDecoder::Numeric
rescue LoadError
end
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ def set_etc_hosts(hostaddr)
config.filter_run_excluding( :ipv6 ) if Addrinfo.getaddrinfo("localhost", nil, nil, :STREAM).size < 2
config.filter_run_excluding( :ractor ) unless defined?(Ractor)
begin
require "bigdecimal"
PG.require_bigdecimal_without_warning
rescue LoadError
config.filter_run_excluding( :bigdecimal )
end
Expand Down

0 comments on commit a629d14

Please sign in to comment.