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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39130469c67108ad173209647cc7462624e53c27a7d4e582c9a41d25cad18b22
4
- data.tar.gz: dbbfaab64d02de0cd2614670b03abbd579e90845ec361f9e2bce7c1a579de788
3
+ metadata.gz: bfdba62ded204b2a1007b3f4194ada3d25cfdb1851d21a23d3d0d8baa4b69c78
4
+ data.tar.gz: 97c1a41fb6a6550adce185f402a9d9db738cdc912bbd15a7ab13f133fa1a83e8
5
5
  SHA512:
6
- metadata.gz: 9501c5f696fed8cab886f52d4fdfa64a17e6bdd2166c0c6e86fbe2f045500baeb0128b2b72845b47efc2e99a86247196cb009e0e567686a5f67ab39dd16cf931
7
- data.tar.gz: a2740709abf68970709355628e90b6ee7c37b0f590028001693b60aa066e763661cc887c3dc3961166af8dc5bdd53b162473b77c346dbd1c4895fafb2c7e2b69
6
+ metadata.gz: db4415229791b74647ffd4441d4b930f3ab98a2a7c9e1fb84de94537f6eec1a370116745860fe1bf2a98bb3b8dc6541d7c6ac5933779a022e97e96bbe0113ebc
7
+ data.tar.gz: ea012d8cc51843103d938a1953619f33bc603a0a51b70787cbaebcc653bae9e83eded5a3807407ad143ffd50300f063ae4b15d254c03c079674a64701a9781fd
data/Gemfile CHANGED
@@ -17,3 +17,5 @@ gem "simplecov-lcov"
17
17
  gem "undercover"
18
18
 
19
19
  gem "pry"
20
+
21
+ gem "gem-release", require: false
@@ -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
- # @param block [Proc] The block to call to get the value of the attribute
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
- serialize(
78
- object.send(association_name),
79
- namespace:,
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Transmutation
4
- VERSION = "0.4.5"
4
+ VERSION = "0.5.0"
5
5
  end
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.5
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: 2024-11-24 00:00:00.000000000 Z
12
+ date: 2025-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport