From 05f949ebbff5c2b6cce01598cc069472bfbe52d2 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 24 Apr 2025 18:21:23 +0200 Subject: [PATCH] [ruby/json] Bring back JSON::PRETTY_STATE_PROTOTYPE with a deprecation Fix: https://github.com/ruby/json/issues/788 `multi_json` rely on it, even though it was never documented as public API. Bringing it back as a method so it can emit a deprecation warning. https://github.com/ruby/json/commit/123121bba2 --- ext/json/lib/json/common.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb index 77d024dea0..98bc0ac85a 100644 --- a/ext/json/lib/json/common.rb +++ b/ext/json/lib/json/common.rb @@ -961,6 +961,24 @@ module JSON load(...) end module_function :restore + + class << self + private + + def const_missing(const_name) + case const_name + when :PRETTY_STATE_PROTOTYPE + if RUBY_VERSION >= "3.0" + warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1, category: :deprecated + else + warn "JSON::PRETTY_STATE_PROTOTYPE is deprecated and will be removed in json 3.0.0, just use JSON.pretty_generate", uplevel: 1 + end + state.new(PRETTY_GENERATE_OPTIONS) + else + super + end + end + end # :startdoc: # JSON::Coder holds a parser and generator configuration.