transmutation 0.3.1 → 0.3.4

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: 3f47031b9ba7f42582eb94bf4656a767ab0d80571cac2dbab539586ee1026717
4
- data.tar.gz: bf8324685ee7b78dce729d5d9d3862f252516d3601078029936ed16cfc193a17
3
+ metadata.gz: eacb3ed46df9b85dd1389904de77e391c195c09da0739122eefe90d227cdc0bc
4
+ data.tar.gz: 7f958f8ed0214d4fc328a27d66f5c1c220ee15ccf857e93b801e683687dba3a6
5
5
  SHA512:
6
- metadata.gz: 4cd441a3d1f40bfea4dd9090eb2ed58aad496166f986a1e2d086ef564302153c1381bfd4bf5868bea20cff125447aab012c3fc04488d545f4e7b436721b9edb1
7
- data.tar.gz: 3931c97882ba5f3bd972f9cb540904f1ef71296dc8fda76c7d79770ec760c54c8f4490557a3ea5e1f6315177099e63b762d4cfe7f24bad5e6fd80d1906c9f608
6
+ metadata.gz: 796af841f34b29f39f657344eb0e26da00e84c311de57755fd0812a12db05711c46ad33de58394f76e61c0ba760e8b5a92b1a1cb07fcc3fa090e092a4cef589e
7
+ data.tar.gz: 12b00efad9d71654a791a6eae379804ec669f98472c1cf469ce6c9bdeeeec27d7fb752c232485cf60f91c50009454fb1c9dcbcf30fa72ca899a85ae434d5a753
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.1)
4
+ transmutation (0.3.4)
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
@@ -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.1"
4
+ VERSION = "0.3.4"
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.1
4
+ version: 0.3.4
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-10 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