transmutation 0.3.6 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +24 -1
- data/lib/transmutation/class_attributes.rb +2 -2
- data/lib/transmutation/object_serializer.rb +11 -0
- data/lib/transmutation/serialization/lookup.rb +4 -4
- data/lib/transmutation/serialization/rendering.rb +2 -2
- data/lib/transmutation/serialization.rb +5 -6
- data/lib/transmutation/serializer.rb +4 -4
- data/lib/transmutation/version.rb +1 -1
- data/lib/transmutation.rb +2 -1
- data/transmutation.gemspec +2 -1
- metadata +19 -5
- data/lib/transmutation/core_ext/array.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea5b5857533b8d0afc9b4ba77c600e83cd995450212ae71186bdc6e38d7d565
|
4
|
+
data.tar.gz: 0a66ba31d44d3dc55abfcf9fba5fc2ba74e5b0559c7be90fc9769870810bbf9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bbbe86595fa57f35a98a285e29f2be5076e6dd6d3fb30051793ee6f3f9fe5ad6962d0bc144765a987513e98498c2c2142fb49892f0e4f29de18edd2d0146669
|
7
|
+
data.tar.gz: 6b3c4a09fa072391e01204df07eec9dae1bcbd33592d0ff4335e6beda3d7dfafe46107f6399bc64963f7c93de5da4c6b92da4d547ec053568e988b77e0f6a78a
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.5
|
data/Gemfile.lock
CHANGED
@@ -1,22 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
transmutation (0.
|
4
|
+
transmutation (0.4.1)
|
5
|
+
activesupport (~> 7.2)
|
5
6
|
zeitwerk (~> 2.6.15)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
activesupport (7.2.1.2)
|
12
|
+
base64
|
13
|
+
bigdecimal
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
logger (>= 1.4.2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
securerandom (>= 0.3)
|
21
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
10
22
|
ast (2.4.2)
|
23
|
+
base64 (0.2.0)
|
11
24
|
bigdecimal (3.1.7)
|
12
25
|
coderay (1.1.3)
|
26
|
+
concurrent-ruby (1.3.4)
|
27
|
+
connection_pool (2.4.1)
|
13
28
|
diff-lcs (1.5.1)
|
14
29
|
docile (1.4.0)
|
30
|
+
drb (2.2.1)
|
31
|
+
i18n (1.14.6)
|
32
|
+
concurrent-ruby (~> 1.0)
|
15
33
|
imagen (0.1.8)
|
16
34
|
parser (>= 2.5, != 2.5.1.1)
|
17
35
|
json (2.7.2)
|
18
36
|
language_server-protocol (3.17.0.3)
|
37
|
+
logger (1.6.1)
|
19
38
|
method_source (1.1.0)
|
39
|
+
minitest (5.25.1)
|
20
40
|
parallel (1.24.0)
|
21
41
|
parser (3.3.1.0)
|
22
42
|
ast (~> 2.4.1)
|
@@ -69,6 +89,7 @@ GEM
|
|
69
89
|
rubocop (~> 1.40)
|
70
90
|
ruby-progressbar (1.13.0)
|
71
91
|
rugged (1.7.2)
|
92
|
+
securerandom (0.3.1)
|
72
93
|
simplecov (0.22.0)
|
73
94
|
docile (~> 1.1)
|
74
95
|
simplecov-html (~> 0.11)
|
@@ -77,6 +98,8 @@ GEM
|
|
77
98
|
simplecov-lcov (0.8.0)
|
78
99
|
simplecov_json_formatter (0.1.4)
|
79
100
|
strscan (3.1.0)
|
101
|
+
tzinfo (2.0.6)
|
102
|
+
concurrent-ruby (~> 1.0)
|
80
103
|
undercover (0.5.0)
|
81
104
|
bigdecimal
|
82
105
|
imagen (>= 0.1.8)
|
@@ -10,8 +10,8 @@ module Transmutation
|
|
10
10
|
instance_writer: instance_accessor,
|
11
11
|
default: nil
|
12
12
|
)
|
13
|
-
class_attribute_reader(*names, instance_reader
|
14
|
-
class_attribute_writer(*names, instance_writer
|
13
|
+
class_attribute_reader(*names, instance_reader:, default:)
|
14
|
+
class_attribute_writer(*names, instance_writer:, default:)
|
15
15
|
end
|
16
16
|
|
17
17
|
def class_attribute_reader(*names, instance_reader: true, default: nil)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Transmutation
|
4
|
+
# Default object serializer.
|
5
|
+
# This is used when no serializer is found for the given object.
|
6
|
+
class ObjectSerializer < Serializer
|
7
|
+
def as_json(options = {})
|
8
|
+
object.as_json(options)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -26,15 +26,15 @@ module Transmutation
|
|
26
26
|
# - Api::Chat::UserSerializer
|
27
27
|
# - Chat::UserSerializer
|
28
28
|
def serializer_for(object, serializer: nil)
|
29
|
-
serializer_name = serializer_name_for(object, serializer:
|
29
|
+
serializer_name = serializer_name_for(object, serializer:)
|
30
30
|
|
31
|
-
return constantize_serializer!(Object, serializer_name, object:
|
31
|
+
return constantize_serializer!(Object, serializer_name, object:) if serializer_name.start_with?("::")
|
32
32
|
|
33
33
|
potential_namespaces.each do |potential_namespace|
|
34
34
|
return potential_namespace.const_get(serializer_name) if potential_namespace.const_defined?(serializer_name)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
Transmutation::ObjectSerializer
|
38
38
|
end
|
39
39
|
|
40
40
|
# Returns the highest specificity serializer name for the given object.
|
@@ -76,7 +76,7 @@ module Transmutation
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def constantize_serializer!(namespace, name, object:)
|
79
|
-
raise SerializerNotFound.new(object, namespace
|
79
|
+
raise SerializerNotFound.new(object, namespace:, name:) unless namespace.const_defined?(name)
|
80
80
|
|
81
81
|
namespace.const_get(name)
|
82
82
|
end
|
@@ -5,9 +5,9 @@ module Transmutation
|
|
5
5
|
module Rendering
|
6
6
|
def render(json: nil, serialize: true, namespace: nil, serializer: nil, max_depth: 1, **args)
|
7
7
|
return super(**args) unless json
|
8
|
-
return super(**args, json:
|
8
|
+
return super(**args, json:) unless serialize
|
9
9
|
|
10
|
-
super(**args, json: serialize(json, namespace
|
10
|
+
super(**args, json: serialize(json, namespace:, serializer:, max_depth:))
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -4,7 +4,6 @@ module Transmutation
|
|
4
4
|
module Serialization
|
5
5
|
# Serialize a given object with the looked up serializer.
|
6
6
|
#
|
7
|
-
#
|
8
7
|
# @param object [Object] The object to serialize.
|
9
8
|
# @param namespace [String, Symbol, Module] The namespace to lookup the serializer in.
|
10
9
|
# @param serializer [String, Symbol, Class] The serializer to use.
|
@@ -12,14 +11,14 @@ module Transmutation
|
|
12
11
|
#
|
13
12
|
# @return [Transmutation::Serializer] The serialized object. This will respond to `#as_json` and `#to_json`.
|
14
13
|
def serialize(object, namespace: nil, serializer: nil, depth: 0, max_depth: 1)
|
15
|
-
if object.respond_to?(:map)
|
14
|
+
if object.respond_to?(:map) && !object.respond_to?(:to_hash)
|
16
15
|
return object.map do |item|
|
17
|
-
serialize(item, namespace
|
16
|
+
serialize(item, namespace:, serializer:, depth:, max_depth:)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
lookup_serializer(object, namespace
|
22
|
-
.new(object, depth
|
20
|
+
lookup_serializer(object, namespace:, serializer:)
|
21
|
+
.new(object, depth:, max_depth:)
|
23
22
|
end
|
24
23
|
|
25
24
|
# Lookup the serializer for the given object.
|
@@ -33,7 +32,7 @@ module Transmutation
|
|
33
32
|
# @return [Class<Transmutation::Serializer>] The serializer for the given object.
|
34
33
|
#
|
35
34
|
def lookup_serializer(object, namespace: nil, serializer: nil)
|
36
|
-
Lookup.new(self, namespace:
|
35
|
+
Lookup.new(self, namespace:).serializer_for(object, serializer:)
|
37
36
|
end
|
38
37
|
|
39
38
|
private_class_method def self.included(base)
|
@@ -56,7 +56,7 @@ module Transmutation
|
|
56
56
|
# end
|
57
57
|
# end
|
58
58
|
def attribute(attribute_name, &block)
|
59
|
-
attributes_config[attribute_name] = { block:
|
59
|
+
attributes_config[attribute_name] = { block: }
|
60
60
|
end
|
61
61
|
|
62
62
|
# Define an association to be serialized
|
@@ -76,14 +76,14 @@ module Transmutation
|
|
76
76
|
block = lambda do
|
77
77
|
serialize(
|
78
78
|
object.send(association_name),
|
79
|
-
namespace
|
80
|
-
serializer
|
79
|
+
namespace:,
|
80
|
+
serializer:,
|
81
81
|
depth: @depth + 1,
|
82
82
|
max_depth: @max_depth
|
83
83
|
)
|
84
84
|
end
|
85
85
|
|
86
|
-
attributes_config[association_name] = { block
|
86
|
+
attributes_config[association_name] = { block:, association: true }
|
87
87
|
end
|
88
88
|
|
89
89
|
alias belongs_to association
|
data/lib/transmutation.rb
CHANGED
data/transmutation.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = "Ruby JSON serialization library"
|
12
12
|
spec.homepage = "https://github.com/spellbook-technology/transmutation"
|
13
13
|
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 3.
|
14
|
+
spec.required_ruby_version = ">= 3.2.5"
|
15
15
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
spec.metadata["source_code_uri"] = "https://github.com/spellbook-technology/transmutation"
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
31
|
|
32
|
+
spec.add_dependency "activesupport", "~> 7.2"
|
32
33
|
spec.add_dependency "zeitwerk", "~> 2.6.15"
|
33
34
|
|
34
35
|
# For more information and examples about making a new gem, check out our
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transmutation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nitemaeric
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-10-
|
12
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '7.2'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '7.2'
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: zeitwerk
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +60,7 @@ files:
|
|
46
60
|
- Rakefile
|
47
61
|
- lib/transmutation.rb
|
48
62
|
- lib/transmutation/class_attributes.rb
|
49
|
-
- lib/transmutation/
|
63
|
+
- lib/transmutation/object_serializer.rb
|
50
64
|
- lib/transmutation/serialization.rb
|
51
65
|
- lib/transmutation/serialization/lookup.rb
|
52
66
|
- lib/transmutation/serialization/lookup/serializer_not_found.rb
|
@@ -71,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
85
|
requirements:
|
72
86
|
- - ">="
|
73
87
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
88
|
+
version: 3.2.5
|
75
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
90
|
requirements:
|
77
91
|
- - ">="
|
78
92
|
- !ruby/object:Gem::Version
|
79
93
|
version: '0'
|
80
94
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.4.19
|
82
96
|
signing_key:
|
83
97
|
specification_version: 4
|
84
98
|
summary: Ruby JSON serialization library
|