paquito 0.1.0 → 0.3.1
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 +4 -4
- data/Gemfile +2 -4
- data/Gemfile.lock +12 -18
- data/README.md +14 -2
- data/lib/paquito/cache_entry_coder.rb +22 -0
- data/lib/paquito/codec_factory.rb +4 -0
- data/lib/paquito/conditional_compressor.rb +1 -1
- data/lib/paquito/errors.rb +1 -0
- data/lib/paquito/safe_yaml.rb +19 -14
- data/lib/paquito/struct.rb +1 -0
- data/lib/paquito/types.rb +7 -3
- data/lib/paquito/version.rb +1 -1
- data/lib/paquito.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d00c743e791d4a17131842b2f515d58cff0e62190c8509666aff3d0d34e2d005
|
4
|
+
data.tar.gz: b6760e6c8ceefa78e77f6b7c1a5668d40930c0d80fb8f841ea0a3deda82a77dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
12
|
-
gem "activerecord", ">= 7.0.0
|
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
|
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.
|
17
|
-
activesupport (= 7.0.
|
18
|
-
activerecord (7.0.
|
19
|
-
activemodel (= 7.0.
|
20
|
-
activesupport (= 7.0.
|
21
|
-
activesupport (7.0.
|
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.
|
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
|
66
|
-
activesupport (>= 7.0.0
|
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.
|
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
|
-
##
|
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
|
-
|
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
|
data/lib/paquito/errors.rb
CHANGED
data/lib/paquito/safe_yaml.rb
CHANGED
@@ -43,31 +43,36 @@ module Paquito
|
|
43
43
|
|
44
44
|
class RestrictedYAMLTree < Psych::Visitors::YAMLTree
|
45
45
|
class DispatchCache
|
46
|
-
def initialize(visitor, cache
|
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 @
|
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
|
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
|
data/lib/paquito/struct.rb
CHANGED
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
|
-
|
200
|
-
unpacker: curry_callback(type_attributes.fetch(:unpacker), factory),
|
204
|
+
type_attributes
|
201
205
|
)
|
202
206
|
end
|
203
207
|
end
|
data/lib/paquito/version.rb
CHANGED
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
|
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:
|
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
|