transmutation 0.3.6 → 0.4.1

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: 4efa99a5b3a708cc7d22b71e887288f4e10d9d1dda254810dbbb8ae71afd4921
4
- data.tar.gz: 71e10e32a7053dd9d761d14c70e28e438484fd37d4c32cdaedaa9a455f8ff77f
3
+ metadata.gz: aea5b5857533b8d0afc9b4ba77c600e83cd995450212ae71186bdc6e38d7d565
4
+ data.tar.gz: 0a66ba31d44d3dc55abfcf9fba5fc2ba74e5b0559c7be90fc9769870810bbf9f
5
5
  SHA512:
6
- metadata.gz: 3d8a736b3179ee2915f8dd5a56727fd989ef9bf7a8baa138d2d4a133e5cbc65b563d0b8036764f3c8959dd67ce9e0d53a5ff48409a7933fef205e8e19cfe68c4
7
- data.tar.gz: 84c594805cb025274e8342d481b104fb06d1189d24e63d04857bf0c86cbe89be28b26839d8dde2bf8dec6f009665e07640414173f58436e070c7eff186b9e610
6
+ metadata.gz: 6bbbe86595fa57f35a98a285e29f2be5076e6dd6d3fb30051793ee6f3f9fe5ad6962d0bc144765a987513e98498c2c2142fb49892f0e4f29de18edd2d0146669
7
+ data.tar.gz: 6b3c4a09fa072391e01204df07eec9dae1bcbd33592d0ff4335e6beda3d7dfafe46107f6399bc64963f7c93de5da4c6b92da4d547ec053568e988b77e0f6a78a
data/.rubocop.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 3.0
4
+ TargetRubyVersion: 3.2.5
5
5
  NewCops: disable
6
6
  SuggestExtensions: false
7
7
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.6
1
+ 3.2.5
data/Gemfile.lock CHANGED
@@ -1,22 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- transmutation (0.3.6)
4
+ transmutation (0.4.1)
5
+ activesupport (~> 7.2)
5
6
  zeitwerk (~> 2.6.15)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
11
+ activesupport (7.2.1.2)
12
+ base64
13
+ bigdecimal
14
+ concurrent-ruby (~> 1.0, >= 1.3.1)
15
+ connection_pool (>= 2.2.5)
16
+ drb
17
+ i18n (>= 1.6, < 2)
18
+ logger (>= 1.4.2)
19
+ minitest (>= 5.1)
20
+ securerandom (>= 0.3)
21
+ tzinfo (~> 2.0, >= 2.0.5)
10
22
  ast (2.4.2)
23
+ base64 (0.2.0)
11
24
  bigdecimal (3.1.7)
12
25
  coderay (1.1.3)
26
+ concurrent-ruby (1.3.4)
27
+ connection_pool (2.4.1)
13
28
  diff-lcs (1.5.1)
14
29
  docile (1.4.0)
30
+ drb (2.2.1)
31
+ i18n (1.14.6)
32
+ concurrent-ruby (~> 1.0)
15
33
  imagen (0.1.8)
16
34
  parser (>= 2.5, != 2.5.1.1)
17
35
  json (2.7.2)
18
36
  language_server-protocol (3.17.0.3)
37
+ logger (1.6.1)
19
38
  method_source (1.1.0)
39
+ minitest (5.25.1)
20
40
  parallel (1.24.0)
21
41
  parser (3.3.1.0)
22
42
  ast (~> 2.4.1)
@@ -69,6 +89,7 @@ GEM
69
89
  rubocop (~> 1.40)
70
90
  ruby-progressbar (1.13.0)
71
91
  rugged (1.7.2)
92
+ securerandom (0.3.1)
72
93
  simplecov (0.22.0)
73
94
  docile (~> 1.1)
74
95
  simplecov-html (~> 0.11)
@@ -77,6 +98,8 @@ GEM
77
98
  simplecov-lcov (0.8.0)
78
99
  simplecov_json_formatter (0.1.4)
79
100
  strscan (3.1.0)
101
+ tzinfo (2.0.6)
102
+ concurrent-ruby (~> 1.0)
80
103
  undercover (0.5.0)
81
104
  bigdecimal
82
105
  imagen (>= 0.1.8)
@@ -10,8 +10,8 @@ module Transmutation
10
10
  instance_writer: instance_accessor,
11
11
  default: nil
12
12
  )
13
- class_attribute_reader(*names, instance_reader: instance_reader, default: default)
14
- class_attribute_writer(*names, instance_writer: instance_writer, default: default)
13
+ class_attribute_reader(*names, instance_reader:, default:)
14
+ class_attribute_writer(*names, instance_writer:, default:)
15
15
  end
16
16
 
17
17
  def class_attribute_reader(*names, instance_reader: true, default: nil)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Transmutation
4
+ # Default object serializer.
5
+ # This is used when no serializer is found for the given object.
6
+ class ObjectSerializer < Serializer
7
+ def as_json(options = {})
8
+ object.as_json(options)
9
+ end
10
+ end
11
+ end
@@ -26,15 +26,15 @@ module Transmutation
26
26
  # - Api::Chat::UserSerializer
27
27
  # - Chat::UserSerializer
28
28
  def serializer_for(object, serializer: nil)
29
- serializer_name = serializer_name_for(object, serializer: serializer)
29
+ serializer_name = serializer_name_for(object, serializer:)
30
30
 
31
- return constantize_serializer!(Object, serializer_name, object: object) if serializer_name.start_with?("::")
31
+ return constantize_serializer!(Object, serializer_name, object:) if serializer_name.start_with?("::")
32
32
 
33
33
  potential_namespaces.each do |potential_namespace|
34
34
  return potential_namespace.const_get(serializer_name) if potential_namespace.const_defined?(serializer_name)
35
35
  end
36
36
 
37
- raise SerializerNotFound.new(object, namespace: serializer_namespace, name: serializer_name)
37
+ Transmutation::ObjectSerializer
38
38
  end
39
39
 
40
40
  # Returns the highest specificity serializer name for the given object.
@@ -76,7 +76,7 @@ module Transmutation
76
76
  end
77
77
 
78
78
  def constantize_serializer!(namespace, name, object:)
79
- raise SerializerNotFound.new(object, namespace: namespace, name: name) unless namespace.const_defined?(name)
79
+ raise SerializerNotFound.new(object, namespace:, name:) unless namespace.const_defined?(name)
80
80
 
81
81
  namespace.const_get(name)
82
82
  end
@@ -5,9 +5,9 @@ module Transmutation
5
5
  module Rendering
6
6
  def render(json: nil, serialize: true, namespace: nil, serializer: nil, max_depth: 1, **args)
7
7
  return super(**args) unless json
8
- return super(**args, json: json) unless serialize
8
+ return super(**args, json:) unless serialize
9
9
 
10
- super(**args, json: serialize(json, namespace: namespace, serializer: serializer, max_depth: max_depth))
10
+ super(**args, json: serialize(json, namespace:, serializer:, max_depth:))
11
11
  end
12
12
  end
13
13
  end
@@ -4,7 +4,6 @@ module Transmutation
4
4
  module Serialization
5
5
  # Serialize a given object with the looked up serializer.
6
6
  #
7
- #
8
7
  # @param object [Object] The object to serialize.
9
8
  # @param namespace [String, Symbol, Module] The namespace to lookup the serializer in.
10
9
  # @param serializer [String, Symbol, Class] The serializer to use.
@@ -12,14 +11,14 @@ module Transmutation
12
11
  #
13
12
  # @return [Transmutation::Serializer] The serialized object. This will respond to `#as_json` and `#to_json`.
14
13
  def serialize(object, namespace: nil, serializer: nil, depth: 0, max_depth: 1)
15
- if object.respond_to?(:map)
14
+ if object.respond_to?(:map) && !object.respond_to?(:to_hash)
16
15
  return object.map do |item|
17
- serialize(item, namespace: namespace, serializer: serializer, depth: depth, max_depth: max_depth)
16
+ serialize(item, namespace:, serializer:, depth:, max_depth:)
18
17
  end
19
18
  end
20
19
 
21
- lookup_serializer(object, namespace: namespace, serializer: serializer)
22
- .new(object, depth: depth, max_depth: max_depth)
20
+ lookup_serializer(object, namespace:, serializer:)
21
+ .new(object, depth:, max_depth:)
23
22
  end
24
23
 
25
24
  # Lookup the serializer for the given object.
@@ -33,7 +32,7 @@ module Transmutation
33
32
  # @return [Class<Transmutation::Serializer>] The serializer for the given object.
34
33
  #
35
34
  def lookup_serializer(object, namespace: nil, serializer: nil)
36
- Lookup.new(self, namespace: namespace).serializer_for(object, serializer: serializer)
35
+ Lookup.new(self, namespace:).serializer_for(object, serializer:)
37
36
  end
38
37
 
39
38
  private_class_method def self.included(base)
@@ -56,7 +56,7 @@ module Transmutation
56
56
  # end
57
57
  # end
58
58
  def attribute(attribute_name, &block)
59
- attributes_config[attribute_name] = { block: block }
59
+ attributes_config[attribute_name] = { block: }
60
60
  end
61
61
 
62
62
  # Define an association to be serialized
@@ -76,14 +76,14 @@ module Transmutation
76
76
  block = lambda do
77
77
  serialize(
78
78
  object.send(association_name),
79
- namespace: namespace,
80
- serializer: serializer,
79
+ namespace:,
80
+ serializer:,
81
81
  depth: @depth + 1,
82
82
  max_depth: @max_depth
83
83
  )
84
84
  end
85
85
 
86
- attributes_config[association_name] = { block: block, association: true }
86
+ attributes_config[association_name] = { block:, association: true }
87
87
  end
88
88
 
89
89
  alias belongs_to association
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Transmutation
4
- VERSION = "0.3.6"
4
+ VERSION = "0.4.1"
5
5
  end
data/lib/transmutation.rb CHANGED
@@ -46,4 +46,5 @@ loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
46
46
  loader.ignore("#{__dir__}/transmutation/core_ext")
47
47
  loader.setup
48
48
 
49
- require "transmutation/core_ext/array"
49
+ require "active_support"
50
+ require "active_support/core_ext/object/json"
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "Ruby JSON serialization library"
12
12
  spec.homepage = "https://github.com/spellbook-technology/transmutation"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.0"
14
+ spec.required_ruby_version = ">= 3.2.5"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
17
  spec.metadata["source_code_uri"] = "https://github.com/spellbook-technology/transmutation"
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
+ spec.add_dependency "activesupport", "~> 7.2"
32
33
  spec.add_dependency "zeitwerk", "~> 2.6.15"
33
34
 
34
35
  # For more information and examples about making a new gem, check out our
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.6
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitemaeric
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-10-08 00:00:00.000000000 Z
12
+ date: 2024-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '7.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '7.2'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: zeitwerk
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -46,7 +60,7 @@ files:
46
60
  - Rakefile
47
61
  - lib/transmutation.rb
48
62
  - lib/transmutation/class_attributes.rb
49
- - lib/transmutation/core_ext/array.rb
63
+ - lib/transmutation/object_serializer.rb
50
64
  - lib/transmutation/serialization.rb
51
65
  - lib/transmutation/serialization/lookup.rb
52
66
  - lib/transmutation/serialization/lookup/serializer_not_found.rb
@@ -71,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
85
  requirements:
72
86
  - - ">="
73
87
  - !ruby/object:Gem::Version
74
- version: '3.0'
88
+ version: 3.2.5
75
89
  required_rubygems_version: !ruby/object:Gem::Requirement
76
90
  requirements:
77
91
  - - ">="
78
92
  - !ruby/object:Gem::Version
79
93
  version: '0'
80
94
  requirements: []
81
- rubygems_version: 3.2.33
95
+ rubygems_version: 3.4.19
82
96
  signing_key:
83
97
  specification_version: 4
84
98
  summary: Ruby JSON serialization library
@@ -1,13 +0,0 @@
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