Rename `Puma::JSON` to `Puma::JSONSerialization` (#2640)

In the context of user-defined hooks (e.g. in `before_fork`), the previous naming had the unfortunate side-effect of causing `JSON` to resolve to `Puma::JSON` rather than, the likely more expected, `::JSON` module.

Closes #2639
This commit is contained in:
Robin Wallin 2021-06-09 16:55:45 +02:00 committed by GitHub
parent ef1a9f57c5
commit 0256d71e60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 14 deletions

View File

@ -12,7 +12,7 @@ require 'thread'
require 'puma/puma_http11'
require 'puma/detect'
require 'puma/json'
require 'puma/json_serialization'
module Puma
autoload :Const, 'puma/const'
@ -60,7 +60,7 @@ module Puma
# @!attribute [rw] stats_object
def self.stats
Puma::JSON.generate @get_stats.stats
Puma::JSONSerialization.generate @get_stats.stats
end
# @!attribute [r] stats_hash

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'puma/json'
require 'puma/json_serialization'
module Puma
module App
@ -46,17 +46,17 @@ module Puma
GC.start ; 200
when 'gc-stats'
Puma::JSON.generate GC.stat
Puma::JSONSerialization.generate GC.stat
when 'stats'
Puma::JSON.generate @launcher.stats
Puma::JSONSerialization.generate @launcher.stats
when 'thread-backtraces'
backtraces = []
@launcher.thread_status do |name, backtrace|
backtraces << { name: name, backtrace: backtrace }
end
Puma::JSON.generate backtraces
Puma::JSONSerialization.generate backtraces
else
return rack_response(404, "Unsupported action", 'text/plain')

View File

@ -17,7 +17,7 @@ module Puma
# be particularly full-featured or fast. It just has to handle the few places
# where Puma relies on JSON serialization internally.
module JSON
module JSONSerialization
QUOTE = /"/
BACKSLASH = /\\/
CONTROL_CHAR_TO_ESCAPE = /[\x00-\x1F]/ # As required by ECMA-404

View File

@ -1,8 +1,8 @@
require_relative "helper"
require "json"
require "puma/json"
require "puma/json_serialization"
class TestJSON < Minitest::Test
class TestJSONSerialization < Minitest::Test
parallelize_me! unless JRUBY_HEAD
def test_json_generates_string_for_hash_with_string_keys
@ -17,8 +17,8 @@ class TestJSON < Minitest::Test
def test_generate_raises_error_for_unexpected_key_type
value = { [1] => 'b' }
ex = assert_raises Puma::JSON::SerializationError do
Puma::JSON.generate value
ex = assert_raises Puma::JSONSerialization::SerializationError do
Puma::JSONSerialization.generate value
end
assert_equal 'Could not serialize object of type Array as object key', ex.message
end
@ -85,8 +85,8 @@ class TestJSON < Minitest::Test
def test_generate_raises_error_for_unexpected_value_type
value = /abc/
ex = assert_raises Puma::JSON::SerializationError do
Puma::JSON.generate value
ex = assert_raises Puma::JSONSerialization::SerializationError do
Puma::JSONSerialization.generate value
end
assert_equal 'Unexpected value of type Regexp', ex.message
end
@ -94,7 +94,7 @@ class TestJSON < Minitest::Test
private
def assert_puma_json_generates_string(expected_output, value_to_serialize, expected_roundtrip: nil)
actual_output = Puma::JSON.generate(value_to_serialize)
actual_output = Puma::JSONSerialization.generate(value_to_serialize)
assert_equal expected_output, actual_output
if value_to_serialize.nil?