paquito 0.1.0 → 0.3.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: fdea3e761f0c5cf3d5a99a42f31e55b645921e6597fb027c560de421b55f7ae3
4
- data.tar.gz: f3dc6d6b15d149bb1d00115b79ef7f337af01197b5961a14fa9baead46e2586a
3
+ metadata.gz: d00c743e791d4a17131842b2f515d58cff0e62190c8509666aff3d0d34e2d005
4
+ data.tar.gz: b6760e6c8ceefa78e77f6b7c1a5668d40930c0d80fb8f841ea0a3deda82a77dd
5
5
  SHA512:
6
- metadata.gz: ac2d37fe39cace2096b041200eb2c2fac5fa2b6024747420a69645097642bce3ef35d66dce1c53d0ff801a921c46f84ca68fdb5a123ffd5c71e52f2a492bc0b8
7
- data.tar.gz: e0e6e8329734bfed770fc1cf8b1c964e7c7902a55686d7182cd078c26a3255d4e7af91e17e2898e35ef9c3515df1d38c5243417d18190cd968f4232e85231e59
6
+ metadata.gz: 189792644f661fd6a5455921928ff94f911d972c971590ff6754bee2f0e27c3386199d0444286e279d6b658d755c3ad0e9deff2e6338620c5a1b81efe542365a
7
+ data.tar.gz: c4f9cb2d28a8598627497bf3e7f8c1de1a29e2fa0a37e54e06310af438fdd5f34b6c77c533a90b121559d5e77353b5fe316a8099b4d1f8b588873363edb43c3a
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" # Waiting for release of https://github.com/msgpack/msgpack-ruby/pull/220
9
-
10
8
  gem "rake", "~> 13.0"
11
- gem "activesupport", ">= 7.0.0.alpha2"
12
- gem "activerecord", ">= 7.0.0.alpha2"
9
+ gem "activesupport", ">= 7.0.0"
10
+ gem "activerecord", ">= 7.0.0"
13
11
  gem "sqlite3"
14
12
 
15
13
  gem "minitest", "~> 5.0"
data/Gemfile.lock CHANGED
@@ -1,24 +1,18 @@
1
- GIT
2
- remote: https://github.com/msgpack/msgpack-ruby.git
3
- revision: ea20842ea732f4d625fd30c7b8f67655d73652f2
4
- specs:
5
- msgpack (1.4.2)
6
-
7
1
  PATH
8
2
  remote: .
9
3
  specs:
10
- paquito (0.1.0)
4
+ paquito (0.3.1)
11
5
  msgpack
12
6
 
13
7
  GEM
14
8
  remote: https://rubygems.org/
15
9
  specs:
16
- activemodel (7.0.0.alpha2)
17
- activesupport (= 7.0.0.alpha2)
18
- activerecord (7.0.0.alpha2)
19
- activemodel (= 7.0.0.alpha2)
20
- activesupport (= 7.0.0.alpha2)
21
- activesupport (7.0.0.alpha2)
10
+ activemodel (7.0.1)
11
+ activesupport (= 7.0.1)
12
+ activerecord (7.0.1)
13
+ activemodel (= 7.0.1)
14
+ activesupport (= 7.0.1)
15
+ activesupport (7.0.1)
22
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
23
17
  i18n (>= 1.6, < 2)
24
18
  minitest (>= 5.1)
@@ -26,9 +20,10 @@ GEM
26
20
  ast (2.4.2)
27
21
  byebug (11.1.3)
28
22
  concurrent-ruby (1.1.9)
29
- i18n (1.8.10)
23
+ i18n (1.9.1)
30
24
  concurrent-ruby (~> 1.0)
31
25
  minitest (5.14.4)
26
+ msgpack (1.4.4)
32
27
  parallel (1.21.0)
33
28
  parser (3.0.2.0)
34
29
  ast (~> 2.4.1)
@@ -62,11 +57,10 @@ PLATFORMS
62
57
  x86_64-linux
63
58
 
64
59
  DEPENDENCIES
65
- activerecord (>= 7.0.0.alpha2)
66
- activesupport (>= 7.0.0.alpha2)
60
+ activerecord (>= 7.0.0)
61
+ activesupport (>= 7.0.0)
67
62
  byebug
68
63
  minitest (~> 5.0)
69
- msgpack!
70
64
  paquito!
71
65
  rake (~> 13.0)
72
66
  rubocop
@@ -75,4 +69,4 @@ DEPENDENCIES
75
69
  sqlite3
76
70
 
77
71
  BUNDLED WITH
78
- 2.2.22
72
+ 2.2.33
data/README.md CHANGED
@@ -120,6 +120,7 @@ coder.load(coder.dump(%i(foo bar).to_set)) # => #<Set: {:foo, :bar}>
120
120
  `Paquito::TypedStruct` is a opt-in Sorbet runtime plugin that allows `T::Struct` classes to be serializable. You need to explicitly include the module in the `T::Struct` classes that you will be serializing.
121
121
 
122
122
  Example
123
+
123
124
  ```ruby
124
125
  class MyStruct < T::Struct
125
126
  include Paquito::TypedStruct
@@ -134,9 +135,20 @@ my_struct.as_pack # => [26450, "foo", 1]
134
135
  MyStruct.from_pack([26450, "foo", 1]) # => <MyStruct bar=1, foo="foo">
135
136
  ```
136
137
 
137
- ## Active Record utilities
138
+ ## Rails utilities
139
+
140
+ `paquito` doesn't not depend on `rails` nor any of its components, however it does provide some optional utilities for it.
141
+
142
+ ### `CacheEntryCoder`
143
+
144
+ `Paquito::CacheEntryCoder` turns an `ActiveSupport::Cache::Entry` instance into a simple `Array` instance. This allows to
145
+ implement custom coders for `ActiveSupport::Cache`.
138
146
 
139
- `paquito` doesn't not depend on `rails` nor any of it's componement, however it does provide some optional utilities for it.
147
+ Example:
148
+
149
+ ```ruby
150
+ ActiveSupport::Cache::FileStore.new("tmp/cache", coder: Paquito.chain(Paquito::CacheEntryCoder, JSON))
151
+ ```
140
152
 
141
153
  ### `SerializedColumn`
142
154
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Paquito
4
+ module CacheEntryCoder
5
+ def self.dump(entry)
6
+ attrs = [entry.value, entry.expires_at, entry.version]
7
+ # drop any trailing nil values to save a couple bytes
8
+ attrs.pop until !attrs.last.nil? || attrs.empty?
9
+ attrs
10
+ end
11
+
12
+ def self.load(payload)
13
+ entry = ::ActiveSupport::Cache::Entry.allocate
14
+ value, expires_in, version = payload
15
+ entry.instance_variable_set(:@value, value)
16
+ entry.instance_variable_set(:@expires_in, expires_in)
17
+ entry.instance_variable_set(:@created_at, 0.0)
18
+ entry.instance_variable_set(:@version, version)
19
+ entry
20
+ end
21
+ end
22
+ end
@@ -27,12 +27,16 @@ module Paquito
27
27
  @factory.dump(object)
28
28
  rescue NoMethodError => error
29
29
  raise PackError.new(error.message, error.receiver)
30
+ rescue RangeError => error
31
+ raise PackError, "#{error.class.name}, #{error.message}"
30
32
  end
31
33
 
32
34
  def load(payload)
33
35
  @factory.load(payload, freeze: @freeze)
34
36
  rescue MessagePack::UnpackError => error
35
37
  raise UnpackError, error.message
38
+ rescue IOError => error
39
+ raise UnpackError, "#{error.class.name}, #{error.message}"
36
40
  end
37
41
  end
38
42
  end
@@ -35,7 +35,7 @@ module Paquito
35
35
  when COMPRESSED
36
36
  @compressor.load(data)
37
37
  else
38
- raise ArgumentError, "invalid ConditionalCompressor version"
38
+ raise UnpackError, "invalid ConditionalCompressor version"
39
39
  end
40
40
  end
41
41
  end
@@ -5,6 +5,7 @@ module Paquito
5
5
 
6
6
  class PackError < Error
7
7
  attr_reader :receiver
8
+
8
9
  def initialize(msg, receiver = nil)
9
10
  super(msg)
10
11
  @receiver = receiver
@@ -43,31 +43,36 @@ module Paquito
43
43
 
44
44
  class RestrictedYAMLTree < Psych::Visitors::YAMLTree
45
45
  class DispatchCache
46
- def initialize(visitor, cache, permitted_classes)
46
+ def initialize(visitor, cache)
47
47
  @visitor = visitor
48
48
  @cache = cache
49
- @permitted_classes = permitted_classes
50
-
51
- @permitted_cache = Hash.new do |h, klass|
52
- unless @permitted_classes.include?(klass.name)
53
- raise UnsupportedType, "Tried to dump unspecified class: #{klass.name.inspect}"
54
- end
55
-
56
- h[klass] = true
57
- end.compare_by_identity
58
49
  end
59
50
 
60
51
  def [](klass)
61
- if @permitted_cache[klass]
62
- @cache[klass]
63
- end
52
+ @cache[klass] if @visitor.permitted_class?(klass)
64
53
  end
65
54
  end
66
55
 
67
56
  def initialize(...)
68
57
  super
69
58
  @permitted_classes = Set.new(@options[:permitted_classes])
70
- @dispatch_cache = DispatchCache.new(self, @dispatch_cache, @permitted_classes)
59
+ @dispatch_cache = DispatchCache.new(self, @dispatch_cache)
60
+ @permitted_cache = Hash.new do |h, klass|
61
+ unless @permitted_classes.include?(klass.name)
62
+ raise UnsupportedType, "Tried to dump unspecified class: #{klass.name.inspect}"
63
+ end
64
+
65
+ h[klass] = true
66
+ end.compare_by_identity
67
+ end
68
+
69
+ def dump_coder(target)
70
+ return unless permitted_class?(target.class)
71
+ super
72
+ end
73
+
74
+ def permitted_class?(klass)
75
+ @permitted_cache[klass]
71
76
  end
72
77
  end
73
78
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "paquito/errors"
3
4
 
4
5
  module Paquito
data/lib/paquito/types.rb CHANGED
@@ -73,8 +73,9 @@ module Paquito
73
73
  TYPES = {
74
74
  "Symbol" => {
75
75
  code: 0x00,
76
- packer: :to_s,
76
+ packer: Symbol.method_defined?(:name) ? :name : :to_s,
77
77
  unpacker: :to_sym,
78
+ optimized_symbols_parsing: true,
78
79
  }.freeze,
79
80
  "Time" => {
80
81
  code: 0x01,
@@ -193,11 +194,14 @@ module Paquito
193
194
  end
194
195
 
195
196
  type_attributes = TYPES.fetch(name)
197
+ type_attributes = type_attributes.merge(
198
+ packer: curry_callback(type_attributes.fetch(:packer), factory),
199
+ unpacker: curry_callback(type_attributes.fetch(:unpacker), factory),
200
+ )
196
201
  factory.register_type(
197
202
  type_attributes.fetch(:code),
198
203
  type,
199
- packer: curry_callback(type_attributes.fetch(:packer), factory),
200
- unpacker: curry_callback(type_attributes.fetch(:unpacker), factory),
204
+ type_attributes
201
205
  )
202
206
  end
203
207
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paquito
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/paquito.rb CHANGED
@@ -14,6 +14,7 @@ require "paquito/allow_nil"
14
14
  require "paquito/translate_errors"
15
15
  require "paquito/safe_yaml"
16
16
  require "paquito/conditional_compressor"
17
+ require "paquito/cache_entry_coder"
17
18
  require "paquito/single_byte_prefix_version"
18
19
  require "paquito/comment_prefix_version"
19
20
  require "paquito/types"
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.1.0
4
+ version: 0.3.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: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -45,6 +45,7 @@ files:
45
45
  - lib/paquito.rb
46
46
  - lib/paquito/active_record_coder.rb
47
47
  - lib/paquito/allow_nil.rb
48
+ - lib/paquito/cache_entry_coder.rb
48
49
  - lib/paquito/codec_factory.rb
49
50
  - lib/paquito/coder_chain.rb
50
51
  - lib/paquito/comment_prefix_version.rb