paquito 0.4.0 → 0.6.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: dd3a891430b40fa7fad9d50b8f383070cee22cba06d19c0db67670324c575613
4
- data.tar.gz: 752e27818f5781652fc91407b51a7f5c16e0a8a07baa0f1285b3e4a3c9029bb0
3
+ metadata.gz: d4a21000dd182ebc6975d8b6cbedf9702bb8e8b1590e5be3c6a048e2f827c54c
4
+ data.tar.gz: 6023594f29fbabdec9842ca1ea0d3a75c2f22a9bd519cbdab153dff75781a8cf
5
5
  SHA512:
6
- metadata.gz: 7b25933ab48ec3327e7e2c781f6502f90ed7a440163e58c3255d43bb1473fc5da5414b44d85f06de7f0d90ef05d57871bd8fcb3aabd22caa19d97df3422240d2
7
- data.tar.gz: aca4aa6e5d417d40926d9cf57045157d1eaffdae225cc051b97ad861e0dc2d19fecf1f6acdea1a9fa91982697cee231326d410a21b0c130f327fc21f967c914e
6
+ metadata.gz: 75ca51f0d7da3dc94b3b26454eeb7960af10102963f9d8d9dca8f2d1b260821e57f831ab7c95cb290fbf842f4473e8aa5d0d2fb2a150dc09d6e847ef4b45d1ba
7
+ data.tar.gz: 1d4b953529569f25bd8d345a0a968ed931ad23ea397f96b6e0e5ba10376c3a5e6cb2078230355fee37c65c50f829d4b32136ba2a8a9ccc4d616076c84e6a3c97
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Ruby
14
14
  uses: ruby/setup-ruby@v1
15
15
  with:
16
- ruby-version: '2.7'
16
+ ruby-version: '2.6'
17
17
  bundler-cache: true
18
18
  - name: Run test
19
19
  run: bundle exec rubocop
@@ -23,7 +23,7 @@ jobs:
23
23
  strategy:
24
24
  fail-fast: false
25
25
  matrix:
26
- ruby: [ ruby-head, '3.0', '2.7' ]
26
+ ruby: [ ruby-head, '3.0', '2.7', '2.6' ]
27
27
  steps:
28
28
  - name: Checkout
29
29
  uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -2,4 +2,4 @@ inherit_gem:
2
2
  rubocop-shopify: rubocop.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.7
5
+ TargetRubyVersion: 2.6
data/Gemfile CHANGED
@@ -5,11 +5,9 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in paquito.gemspec
6
6
  gemspec
7
7
 
8
- gem "msgpack", github: "msgpack/msgpack-ruby"
9
-
10
8
  gem "rake", "~> 13.0"
11
- gem "activesupport", ">= 7.0.0"
12
- gem "activerecord", ">= 7.0.0"
9
+ gem "activesupport"
10
+ gem "activerecord"
13
11
  gem "sqlite3"
14
12
  gem "benchmark-ips"
15
13
 
data/Gemfile.lock CHANGED
@@ -1,28 +1,23 @@
1
- GIT
2
- remote: https://github.com/msgpack/msgpack-ruby.git
3
- revision: b69e6d6965ef46890885ddf73f02b820f3185d80
4
- specs:
5
- msgpack (1.4.5)
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- paquito (0.4.0)
11
- msgpack
4
+ paquito (0.6.1)
5
+ msgpack (>= 1.5.2)
12
6
 
13
7
  GEM
14
8
  remote: https://rubygems.org/
15
9
  specs:
16
- activemodel (7.0.2.3)
17
- activesupport (= 7.0.2.3)
18
- activerecord (7.0.2.3)
19
- activemodel (= 7.0.2.3)
20
- activesupport (= 7.0.2.3)
21
- activesupport (7.0.2.3)
10
+ activemodel (6.1.5)
11
+ activesupport (= 6.1.5)
12
+ activerecord (6.1.5)
13
+ activemodel (= 6.1.5)
14
+ activesupport (= 6.1.5)
15
+ activesupport (6.1.5)
22
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
17
  i18n (>= 1.6, < 2)
24
18
  minitest (>= 5.1)
25
19
  tzinfo (~> 2.0)
20
+ zeitwerk (~> 2.3)
26
21
  ast (2.4.2)
27
22
  benchmark-ips (2.10.0)
28
23
  byebug (11.1.3)
@@ -30,6 +25,7 @@ GEM
30
25
  i18n (1.10.0)
31
26
  concurrent-ruby (~> 1.0)
32
27
  minitest (5.15.0)
28
+ msgpack (1.5.2)
33
29
  parallel (1.21.0)
34
30
  parser (3.1.1.0)
35
31
  ast (~> 2.4.1)
@@ -56,6 +52,7 @@ GEM
56
52
  tzinfo (2.0.4)
57
53
  concurrent-ruby (~> 1.0)
58
54
  unicode-display_width (2.1.0)
55
+ zeitwerk (2.5.4)
59
56
 
60
57
  PLATFORMS
61
58
  ruby
@@ -63,12 +60,11 @@ PLATFORMS
63
60
  x86_64-linux
64
61
 
65
62
  DEPENDENCIES
66
- activerecord (>= 7.0.0)
67
- activesupport (>= 7.0.0)
63
+ activerecord
64
+ activesupport
68
65
  benchmark-ips
69
66
  byebug
70
67
  minitest (~> 5.0)
71
- msgpack!
72
68
  paquito!
73
69
  rake (~> 13.0)
74
70
  rubocop
@@ -77,4 +73,4 @@ DEPENDENCIES
77
73
  sqlite3
78
74
 
79
75
  BUNDLED WITH
80
- 2.2.33
76
+ 2.3.8
data/Rakefile CHANGED
@@ -3,7 +3,8 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
5
 
6
- suites = [:vanilla, :activesupport, :activerecord]
6
+ suites = [:vanilla, :activesupport]
7
+ suites << :activerecord if RUBY_VERSION >= "2.7"
7
8
  namespace :test do
8
9
  suites.each do |suite|
9
10
  Rake::TestTask.new(suite) do |t|
data/dev.yml CHANGED
@@ -2,7 +2,7 @@ name: paquito
2
2
 
3
3
  up:
4
4
  - ruby:
5
- version: 2.7.4
5
+ version: 2.6.9
6
6
  - bundler
7
7
 
8
8
  commands:
@@ -119,13 +119,14 @@ module Paquito
119
119
  @ids = {}.compare_by_identity
120
120
  end
121
121
 
122
- def map(...)
123
- @instances.map(...)
122
+ def map(&block)
123
+ @instances.map(&block)
124
124
  end
125
125
 
126
- def fetch(...)
127
- @instances.fetch(...)
126
+ def fetch(*args, &block)
127
+ @instances.fetch(*args, &block)
128
128
  end
129
+ ruby2_keywords :fetch if respond_to?(:ruby2_keywords, true)
129
130
 
130
131
  def push(instance)
131
132
  id = @ids[instance] = @instances.size
@@ -16,9 +16,6 @@ module Paquito
16
16
  Types.register_serializable_type(factory) if serializable_type
17
17
 
18
18
  if pool && pool > 0 && factory.respond_to?(:pool)
19
- if serializable_type || types.any? { |t| Types.recursive?(t) }
20
- pool *= 2
21
- end
22
19
  factory = factory.freeze.pool(pool, freeze: freeze)
23
20
  freeze = false
24
21
  end
@@ -53,7 +53,7 @@ module Paquito
53
53
  end
54
54
  end
55
55
 
56
- def initialize(...)
56
+ def initialize(*)
57
57
  super
58
58
  @permitted_classes = Set.new(@options[:permitted_classes])
59
59
  @dispatch_cache = DispatchCache.new(self, @dispatch_cache)
@@ -65,6 +65,7 @@ module Paquito
65
65
  h[klass] = true
66
66
  end.compare_by_identity
67
67
  end
68
+ ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
68
69
 
69
70
  def dump_coder(target)
70
71
  return unless permitted_class?(target.class)
data/lib/paquito/types.rb CHANGED
@@ -75,8 +75,8 @@ module Paquito
75
75
  TYPES = {
76
76
  "Symbol" => {
77
77
  code: 0,
78
- packer: Symbol.method_defined?(:name) ? :name : :to_s,
79
- unpacker: :to_sym,
78
+ packer: Symbol.method_defined?(:name) ? :name.to_proc : :to_s.to_proc,
79
+ unpacker: :to_sym.to_proc,
80
80
  optimized_symbols_parsing: true,
81
81
  }.freeze,
82
82
  "Time" => {
@@ -153,14 +153,15 @@ module Paquito
153
153
  }.freeze,
154
154
  "ActiveSupport::HashWithIndifferentAccess" => {
155
155
  code: 7,
156
- packer: ->(factory, value) do
156
+ packer: ->(value, packer) do
157
157
  unless value.instance_of?(ActiveSupport::HashWithIndifferentAccess)
158
158
  raise PackError.new("cannot pack HashWithIndifferentClass subclass", value)
159
159
  end
160
160
 
161
- factory.dump(value.to_h)
161
+ packer.write(value.to_h)
162
162
  end,
163
- unpacker: ->(factory, value) { HashWithIndifferentAccess.new(factory.load(value)) },
163
+ unpacker: ->(unpacker) { HashWithIndifferentAccess.new(unpacker.read) },
164
+ recursive: true,
164
165
  },
165
166
  "ActiveSupport::TimeWithZone" => {
166
167
  code: 8,
@@ -180,8 +181,9 @@ module Paquito
180
181
  },
181
182
  "Set" => {
182
183
  code: 9,
183
- packer: ->(factory, value) { factory.dump(value.to_a) },
184
- unpacker: ->(factory, value) { factory.load(value).to_set },
184
+ packer: ->(value, packer) { packer.write(value.to_a) },
185
+ unpacker: ->(unpacker) { unpacker.read.to_set },
186
+ recursive: true,
185
187
  },
186
188
  # Integer => { code: 10 }, reserved for oversized Integer
187
189
  # Object => { code: 127 }, reserved for serializable Object type
@@ -212,10 +214,6 @@ module Paquito
212
214
  end
213
215
 
214
216
  type_attributes = TYPES.fetch(name)
215
- type_attributes = type_attributes.merge(
216
- packer: curry_callback(type_attributes.fetch(:packer), factory),
217
- unpacker: curry_callback(type_attributes.fetch(:unpacker), factory),
218
- )
219
217
  factory.register_type(
220
218
  type_attributes.fetch(:code),
221
219
  type,
@@ -224,11 +222,6 @@ module Paquito
224
222
  end
225
223
  end
226
224
 
227
- def recursive?(type)
228
- type_attributes = TYPES.fetch(type.name)
229
- recursive_callback?(type_attributes[:packer]) || recursive_callback?(type_attributes[:unpacker])
230
- end
231
-
232
225
  def register_serializable_type(factory)
233
226
  factory.register_type(
234
227
  0x7f,
@@ -256,19 +249,6 @@ module Paquito
256
249
  def define_custom_type(klass, packer: nil, unpacker:)
257
250
  CustomTypesRegistry.register(klass, packer: packer, unpacker: unpacker)
258
251
  end
259
-
260
- private
261
-
262
- def recursive_callback?(callback)
263
- callback.respond_to?(:arity) && callback.arity != 1
264
- end
265
-
266
- def curry_callback(callback, factory)
267
- return callback.to_proc if callback.is_a?(Symbol)
268
- return callback if callback.arity == 1
269
-
270
- callback.curry.call(factory)
271
- end
272
252
  end
273
253
  end
274
254
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paquito
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.1"
5
5
  end
data/paquito.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Framework for defining efficient and extendable serializers"
13
13
  spec.homepage = "https://github.com/Shopify/paquito"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
16
 
17
17
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
18
 
@@ -28,5 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency("msgpack")
31
+ spec.add_dependency("msgpack", ">= 1.5.2")
32
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paquito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-09 00:00:00.000000000 Z
11
+ date: 2022-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.5.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.5.2
27
27
  description: Framework for defining efficient and extendable serializers
28
28
  email:
29
29
  - jean.boussier@gmail.com
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 2.7.0
81
+ version: 2.6.0
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="