paquito 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +14 -2
- data/lib/paquito/cache_entry_coder.rb +22 -0
- data/lib/paquito/version.rb +1 -1
- data/lib/paquito.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8270d4e3422ef944047a1a1832819ad3af49b90e4e2886423fcb4631a31586cf
|
4
|
+
data.tar.gz: 1cb40c98fbfc61c79fa677569925e212643b3bc878d6ac053fa711a2929ad325
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0218b3e4e731b81e21c2f16df0eaa1f86c5267b815b9059de8922e233ceae9a7f4646bce089b215c38347e950fe20636753fd57aa5a9b61ef4617126fd4e96b8'
|
7
|
+
data.tar.gz: 22b6023ea6c0edf6d5c23de9b36c908f5b323b449c14ecdab0562d59b131e5ed54341d19e6404cf22d351384531bf3943eba60c958aed9566fdc589b900b4ad4
|
data/Gemfile.lock
CHANGED
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
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paquito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
@@ -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
|