Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't print a warning when bigdecimal is required on ruby-3.4+ #574

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading