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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1184809d63cb5abaad091e433a5e150579f5ca634a5522c57b7dd49c3465a3c
4
- data.tar.gz: a0e2bddde883737a82369d14cd4bc75235ea1dee366c7a0234a262e29930a74c
3
+ metadata.gz: 688b4cadc720651eea003b72298c1d53fe5c26d88754b3cedf5a0440a02d14c1
4
+ data.tar.gz: 01daf2b3a26693038ebd7ff58de4179acbb8824432c1ad0402eee3ddd23b126f
5
5
  SHA512:
6
- metadata.gz: ee23262517dba8436c182542b02bd3e1b15df0225b84eae7dedb106c4d155cf6dd78db791e9a98d44c57654dcf87d9aa8110e87cde6bface0943952199f8e2a5
7
- data.tar.gz: 8b23bfbd305587fde6d6fef4a714840a73e4415d27902c3169dd06561f141b127944d64f13029a37f9aaf10d88bdab5b1059554ae132fc4584c899f6ecb3148e
6
+ metadata.gz: 23206989db193d8ae172d64af0657f669d47bc2c745877720c5c9098a80aaf4882af598d2e58d9c5ecca9394593e23c2e0b0512f9ac7311c7d97d707186cc270
7
+ data.tar.gz: 60ac5e22b4721b904aad13509e82813839d149cabf18eed18579185e4f623a3c9894f4ce5053439da9b3d8b5c0737cf85dceb49ef139539d4534d6d697a232ac
data/.rubocop.yml CHANGED
@@ -16,6 +16,9 @@ Style/StringLiteralsInInterpolation:
16
16
  Layout/LineLength:
17
17
  Max: 120
18
18
 
19
+ Metrics/AbcSize:
20
+ Max: 18
21
+
19
22
  Metrics/ParameterLists:
20
23
  Enabled: true
21
24
  CountKeywordArgs: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transmutation (0.3.0)
4
+ transmutation (0.3.3)
5
5
  zeitwerk (~> 2.6.15)
6
6
 
7
7
  GEM
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ unless Array.method_defined?(:as_json)
4
+ class Array # :nodoc:
5
+ def as_json(options = {})
6
+ if options
7
+ map { |v| v.as_json(options.dup) }
8
+ else
9
+ map(&:as_json)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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.reverse
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(_options = {})
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(object.send(association_name), namespace: namespace, serializer: serializer, depth: @depth + 1)
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 }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Transmutation
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.3"
5
5
  end
data/lib/transmutation.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "transmutation/core_ext/array"
4
+
3
5
  require "zeitwerk"
4
6
  loader = Zeitwerk::Loader.for_gem
5
7
  loader.setup
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.0
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-06-06 00:00:00.000000000 Z
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.9
81
+ rubygems_version: 3.5.16
81
82
  signing_key:
82
83
  specification_version: 4
83
84
  summary: Ruby JSON serialization library