transmutation 0.3.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/lib/transmutation/core_ext/array.rb +13 -0
- data/lib/transmutation/serialization/lookup.rb +4 -2
- data/lib/transmutation/serializer.rb +9 -3
- data/lib/transmutation/version.rb +1 -1
- data/lib/transmutation.rb +2 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 688b4cadc720651eea003b72298c1d53fe5c26d88754b3cedf5a0440a02d14c1
|
4
|
+
data.tar.gz: 01daf2b3a26693038ebd7ff58de4179acbb8824432c1ad0402eee3ddd23b126f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23206989db193d8ae172d64af0657f669d47bc2c745877720c5c9098a80aaf4882af598d2e58d9c5ecca9394593e23c2e0b0512f9ac7311c7d97d707186cc270
|
7
|
+
data.tar.gz: 60ac5e22b4721b904aad13509e82813839d149cabf18eed18579185e4f623a3c9894f4ce5053439da9b3d8b5c0737cf85dceb49ef139539d4534d6d697a232ac
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -52,13 +52,15 @@ module Transmutation
|
|
52
52
|
@potential_namespaces ||= begin
|
53
53
|
namespace_parts = serializer_namespace.split("::")
|
54
54
|
|
55
|
-
namespace_parts.filter_map.with_index do |part, index|
|
55
|
+
namespaces = namespace_parts.filter_map.with_index do |part, index|
|
56
56
|
namespace = [*namespace_parts[...index], part].join("::")
|
57
57
|
|
58
58
|
next if namespace.empty?
|
59
59
|
|
60
60
|
Object.const_get(namespace) if Object.const_defined?(namespace)
|
61
|
-
end
|
61
|
+
end
|
62
|
+
|
63
|
+
[*namespaces.reverse, Object]
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -30,10 +30,10 @@ module Transmutation
|
|
30
30
|
as_json(options).to_json
|
31
31
|
end
|
32
32
|
|
33
|
-
def as_json(
|
33
|
+
def as_json(options = {})
|
34
34
|
attributes_config.each_with_object({}) do |(attr_name, attr_options), hash|
|
35
35
|
if attr_options[:association]
|
36
|
-
hash[attr_name.to_s] = instance_exec(&attr_options[:block]) if @depth + 1 <= @max_depth
|
36
|
+
hash[attr_name.to_s] = instance_exec(&attr_options[:block]).as_json(options) if @depth + 1 <= @max_depth
|
37
37
|
else
|
38
38
|
hash[attr_name.to_s] = attr_options[:block] ? instance_exec(&attr_options[:block]) : object.send(attr_name)
|
39
39
|
end
|
@@ -74,7 +74,13 @@ module Transmutation
|
|
74
74
|
# end
|
75
75
|
def association(association_name, namespace: nil, serializer: nil)
|
76
76
|
block = lambda do
|
77
|
-
serialize(
|
77
|
+
serialize(
|
78
|
+
object.send(association_name),
|
79
|
+
namespace: namespace,
|
80
|
+
serializer: serializer,
|
81
|
+
depth: @depth + 1,
|
82
|
+
max_depth: @max_depth
|
83
|
+
)
|
78
84
|
end
|
79
85
|
|
80
86
|
attributes_config[association_name] = { block: block, association: true }
|
data/lib/transmutation.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nitemaeric
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zeitwerk
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- Rakefile
|
47
47
|
- lib/transmutation.rb
|
48
48
|
- lib/transmutation/class_attributes.rb
|
49
|
+
- lib/transmutation/core_ext/array.rb
|
49
50
|
- lib/transmutation/serialization.rb
|
50
51
|
- lib/transmutation/serialization/lookup.rb
|
51
52
|
- lib/transmutation/serialization/lookup/serializer_not_found.rb
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
- !ruby/object:Gem::Version
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
|
-
rubygems_version: 3.5.
|
81
|
+
rubygems_version: 3.5.16
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: Ruby JSON serialization library
|