transmutation 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/transmutation/serializer.rb +11 -9
- data/lib/transmutation/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfdba62ded204b2a1007b3f4194ada3d25cfdb1851d21a23d3d0d8baa4b69c78
|
4
|
+
data.tar.gz: 97c1a41fb6a6550adce185f402a9d9db738cdc912bbd15a7ab13f133fa1a83e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db4415229791b74647ffd4441d4b930f3ab98a2a7c9e1fb84de94537f6eec1a370116745860fe1bf2a98bb3b8dc6541d7c6ac5933779a022e97e96bbe0113ebc
|
7
|
+
data.tar.gz: ea012d8cc51843103d938a1953619f33bc603a0a51b70787cbaebcc653bae9e83eded5a3807407ad143ffd50300f063ae4b15d254c03c079674a64701a9781fd
|
data/Gemfile
CHANGED
@@ -44,7 +44,7 @@ module Transmutation
|
|
44
44
|
# Define an attribute to be serialized
|
45
45
|
#
|
46
46
|
# @param attribute_name [Symbol] The name of the attribute to serialize
|
47
|
-
# @
|
47
|
+
# @yield [object] The block to call to get the value of the attribute
|
48
48
|
# - The block is called in the context of the serializer instance
|
49
49
|
#
|
50
50
|
# @example
|
@@ -66,21 +66,23 @@ module Transmutation
|
|
66
66
|
# @param association_name [Symbol] The name of the association to serialize
|
67
67
|
# @param namespace [String, Symbol, Module] The namespace to lookup the association's serializer in
|
68
68
|
# @param serializer [String, Symbol, Class] The serializer to use for the association's serialization
|
69
|
+
# @yield [object] The block to call to get the value of the association
|
70
|
+
# - The block is called in the context of the serializer instance
|
71
|
+
# - The return value from the block is automatically serialized
|
69
72
|
#
|
70
73
|
# @example
|
71
74
|
# class UserSerializer < Transmutation::Serializer
|
72
75
|
# association :posts
|
73
76
|
# association :comments, namespace: "Nested", serializer: "User::CommentSerializer"
|
77
|
+
# association :archived_posts do
|
78
|
+
# object.posts.archived
|
79
|
+
# end
|
74
80
|
# end
|
75
|
-
def association(association_name, namespace: nil, serializer: nil)
|
81
|
+
def association(association_name, namespace: nil, serializer: nil, &custom_block)
|
76
82
|
block = lambda do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
serializer:,
|
81
|
-
depth: @depth + 1,
|
82
|
-
max_depth: @max_depth
|
83
|
-
)
|
83
|
+
association_instance = custom_block ? instance_exec(&custom_block) : object.send(association_name)
|
84
|
+
|
85
|
+
serialize(association_instance, namespace:, serializer:, depth: @depth + 1, max_depth: @max_depth)
|
84
86
|
end
|
85
87
|
|
86
88
|
attributes_config[association_name] = { block:, association: true }
|
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.5.0
|
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:
|
12
|
+
date: 2025-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|