-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: Fix mis-serializing hash keys that were suppose to be strings (#…
…111)
- Loading branch information
1 parent
162f17d
commit 485a6c7
Showing
11 changed files
with
88 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# typed: strict | ||
|
||
class SerializeValue | ||
extend T::Sig | ||
|
||
sig { params(value: T.untyped).returns(T.untyped) } | ||
def self.serialize(value) | ||
if value.is_a?(Hash) | ||
HashTransformer.serialize_values(value) | ||
elsif value.is_a?(Array) | ||
value.map { |item| serialize(item) } | ||
elsif value.is_a?(T::Struct) | ||
value.serialize_to(:hash).payload_or(value) | ||
elsif value.respond_to?(:serialize) | ||
value.serialize | ||
else | ||
value | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# typed: true | ||
|
||
require "test_helper" | ||
|
||
class SerializeValueTest < Minitest::Test | ||
def test_when_value_is_a_hash_returns_each_value_serialized | ||
assert_equal({:one => "1", "two" => "2"}, SerializeValue.serialize({:one => TestEnums::EnumOne, "two" => TestEnums::EnumTwo})) | ||
end | ||
|
||
def test_when_value_is_an_array_returns_each_value_serialized | ||
assert_equal(["1", "2"], SerializeValue.serialize([TestEnums::EnumOne, TestEnums::EnumTwo])) | ||
end | ||
|
||
def test_when_value_is_a_struct_returns_serialized_struct | ||
assert_equal({name: "DC", capital: true}, SerializeValue.serialize(DC_CITY)) | ||
end | ||
|
||
def test_when_value_implements_serialize_returns_serialized_value | ||
assert_equal("1", SerializeValue.serialize(TestEnums::EnumOne)) | ||
end | ||
|
||
def test_when_value_doesnt_serialize_returns_value | ||
assert_equal(1, SerializeValue.serialize(1)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters