transmutation 0.3.6 → 0.4.5

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: 4efa99a5b3a708cc7d22b71e887288f4e10d9d1dda254810dbbb8ae71afd4921
4
- data.tar.gz: 71e10e32a7053dd9d761d14c70e28e438484fd37d4c32cdaedaa9a455f8ff77f
3
+ metadata.gz: 39130469c67108ad173209647cc7462624e53c27a7d4e582c9a41d25cad18b22
4
+ data.tar.gz: dbbfaab64d02de0cd2614670b03abbd579e90845ec361f9e2bce7c1a579de788
5
5
  SHA512:
6
- metadata.gz: 3d8a736b3179ee2915f8dd5a56727fd989ef9bf7a8baa138d2d4a133e5cbc65b563d0b8036764f3c8959dd67ce9e0d53a5ff48409a7933fef205e8e19cfe68c4
7
- data.tar.gz: 84c594805cb025274e8342d481b104fb06d1189d24e63d04857bf0c86cbe89be28b26839d8dde2bf8dec6f009665e07640414173f58436e070c7eff186b9e610
6
+ metadata.gz: 9501c5f696fed8cab886f52d4fdfa64a17e6bdd2166c0c6e86fbe2f045500baeb0128b2b72845b47efc2e99a86247196cb009e0e567686a5f67ab39dd16cf931
7
+ data.tar.gz: a2740709abf68970709355628e90b6ee7c37b0f590028001693b60aa066e763661cc887c3dc3961166af8dc5bdd53b162473b77c346dbd1c4895fafb2c7e2b69
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
@@ -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.5"
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"
metadata CHANGED
@@ -1,31 +1,45 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitemaeric
8
8
  - borrabeer
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-10-08 00:00:00.000000000 Z
12
+ date: 2024-11-24 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
17
31
  requirements:
18
32
  - - "~>"
19
33
  - !ruby/object:Gem::Version
20
- version: 2.6.15
34
+ version: '2.6'
21
35
  type: :runtime
22
36
  prerelease: false
23
37
  version_requirements: !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - "~>"
26
40
  - !ruby/object:Gem::Version
27
- version: 2.6.15
28
- description:
41
+ version: '2.6'
42
+ description:
29
43
  email:
30
44
  - daniel@spellbook.tech
31
45
  - worapath.pakkavesa@spellbook.tech
@@ -40,13 +54,12 @@ files:
40
54
  - CHANGELOG.md
41
55
  - CODE_OF_CONDUCT.md
42
56
  - Gemfile
43
- - Gemfile.lock
44
57
  - LICENSE
45
58
  - README.md
46
59
  - Rakefile
47
60
  - lib/transmutation.rb
48
61
  - lib/transmutation/class_attributes.rb
49
- - lib/transmutation/core_ext/array.rb
62
+ - lib/transmutation/object_serializer.rb
50
63
  - lib/transmutation/serialization.rb
51
64
  - lib/transmutation/serialization/lookup.rb
52
65
  - lib/transmutation/serialization/lookup/serializer_not_found.rb
@@ -54,7 +67,6 @@ files:
54
67
  - lib/transmutation/serializer.rb
55
68
  - lib/transmutation/version.rb
56
69
  - sig/transmutation.rbs
57
- - transmutation.gemspec
58
70
  homepage: https://github.com/spellbook-technology/transmutation
59
71
  licenses:
60
72
  - MIT
@@ -63,7 +75,7 @@ metadata:
63
75
  source_code_uri: https://github.com/spellbook-technology/transmutation
64
76
  changelog_uri: https://github.com/spellbook-technology/transmutation/CHANGELOG.md
65
77
  documentation_uri: https://rubydoc.info/gems/transmutation
66
- post_install_message:
78
+ post_install_message:
67
79
  rdoc_options: []
68
80
  require_paths:
69
81
  - lib
@@ -71,15 +83,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
71
83
  requirements:
72
84
  - - ">="
73
85
  - !ruby/object:Gem::Version
74
- version: '3.0'
86
+ version: 3.2.5
75
87
  required_rubygems_version: !ruby/object:Gem::Requirement
76
88
  requirements:
77
89
  - - ">="
78
90
  - !ruby/object:Gem::Version
79
91
  version: '0'
80
92
  requirements: []
81
- rubygems_version: 3.2.33
82
- signing_key:
93
+ rubygems_version: 3.4.19
94
+ signing_key:
83
95
  specification_version: 4
84
96
  summary: Ruby JSON serialization library
85
97
  test_files: []
data/Gemfile.lock DELETED
@@ -1,104 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- transmutation (0.3.6)
5
- zeitwerk (~> 2.6.15)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- ast (2.4.2)
11
- bigdecimal (3.1.7)
12
- coderay (1.1.3)
13
- diff-lcs (1.5.1)
14
- docile (1.4.0)
15
- imagen (0.1.8)
16
- parser (>= 2.5, != 2.5.1.1)
17
- json (2.7.2)
18
- language_server-protocol (3.17.0.3)
19
- method_source (1.1.0)
20
- parallel (1.24.0)
21
- parser (3.3.1.0)
22
- ast (~> 2.4.1)
23
- racc
24
- pry (0.14.2)
25
- coderay (~> 1.1)
26
- method_source (~> 1.0)
27
- racc (1.7.3)
28
- rainbow (3.1.1)
29
- rake (13.2.1)
30
- regexp_parser (2.9.0)
31
- rexml (3.3.6)
32
- strscan
33
- rspec (3.13.0)
34
- rspec-core (~> 3.13.0)
35
- rspec-expectations (~> 3.13.0)
36
- rspec-mocks (~> 3.13.0)
37
- rspec-core (3.13.0)
38
- rspec-support (~> 3.13.0)
39
- rspec-expectations (3.13.0)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.13.0)
42
- rspec-mocks (3.13.0)
43
- diff-lcs (>= 1.2.0, < 2.0)
44
- rspec-support (~> 3.13.0)
45
- rspec-support (3.13.1)
46
- rubocop (1.63.4)
47
- json (~> 2.3)
48
- language_server-protocol (>= 3.17.0)
49
- parallel (~> 1.10)
50
- parser (>= 3.3.0.2)
51
- rainbow (>= 2.2.2, < 4.0)
52
- regexp_parser (>= 1.8, < 3.0)
53
- rexml (>= 3.2.5, < 4.0)
54
- rubocop-ast (>= 1.31.1, < 2.0)
55
- ruby-progressbar (~> 1.7)
56
- unicode-display_width (>= 2.4.0, < 3.0)
57
- rubocop-ast (1.31.3)
58
- parser (>= 3.3.1.0)
59
- rubocop-capybara (2.20.0)
60
- rubocop (~> 1.41)
61
- rubocop-factory_bot (2.25.1)
62
- rubocop (~> 1.41)
63
- rubocop-rspec (2.29.2)
64
- rubocop (~> 1.40)
65
- rubocop-capybara (~> 2.17)
66
- rubocop-factory_bot (~> 2.22)
67
- rubocop-rspec_rails (~> 2.28)
68
- rubocop-rspec_rails (2.28.3)
69
- rubocop (~> 1.40)
70
- ruby-progressbar (1.13.0)
71
- rugged (1.7.2)
72
- simplecov (0.22.0)
73
- docile (~> 1.1)
74
- simplecov-html (~> 0.11)
75
- simplecov_json_formatter (~> 0.1)
76
- simplecov-html (0.12.3)
77
- simplecov-lcov (0.8.0)
78
- simplecov_json_formatter (0.1.4)
79
- strscan (3.1.0)
80
- undercover (0.5.0)
81
- bigdecimal
82
- imagen (>= 0.1.8)
83
- rainbow (>= 2.1, < 4.0)
84
- rugged (>= 0.27, < 1.8)
85
- unicode-display_width (2.5.0)
86
- zeitwerk (2.6.15)
87
-
88
- PLATFORMS
89
- arm64-darwin-23
90
- ruby
91
-
92
- DEPENDENCIES
93
- pry
94
- rake (~> 13.0)
95
- rspec (~> 3.0)
96
- rubocop (~> 1.21)
97
- rubocop-rspec
98
- simplecov
99
- simplecov-lcov
100
- transmutation!
101
- undercover
102
-
103
- BUNDLED WITH
104
- 2.5.11
@@ -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
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/transmutation/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "transmutation"
7
- spec.version = Transmutation::VERSION
8
- spec.authors = %w[nitemaeric borrabeer]
9
- spec.email = %w[daniel@spellbook.tech worapath.pakkavesa@spellbook.tech]
10
-
11
- spec.summary = "Ruby JSON serialization library"
12
- spec.homepage = "https://github.com/spellbook-technology/transmutation"
13
- spec.license = "MIT"
14
- spec.required_ruby_version = ">= 3.0"
15
-
16
- spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/spellbook-technology/transmutation"
18
- spec.metadata["changelog_uri"] = "https://github.com/spellbook-technology/transmutation/CHANGELOG.md"
19
- spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/transmutation"
20
-
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(__dir__) do
24
- `git ls-files -z`.split("\x0").reject do |f|
25
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
- end
27
- end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
31
-
32
- spec.add_dependency "zeitwerk", "~> 2.6.15"
33
-
34
- # For more information and examples about making a new gem, check out our
35
- # guide at: https://bundler.io/guides/creating_gem.html
36
- end