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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bd75bf76fc877be94ad6310f8fa90840492b2854eab2e98a58f2e5eab976fa9
4
- data.tar.gz: 388742a39bfecd9b415eddc0581c19ae76fbada06beef2e929b060059e2b3efa
3
+ metadata.gz: 8270d4e3422ef944047a1a1832819ad3af49b90e4e2886423fcb4631a31586cf
4
+ data.tar.gz: 1cb40c98fbfc61c79fa677569925e212643b3bc878d6ac053fa711a2929ad325
5
5
  SHA512:
6
- metadata.gz: 1183ea104b4426acee742d3554662564edd7c09b99c9eafd5a5edf96dbecdb4bcb8bf723ed78734f32cb260b312e02da50299b981ad641f85b9077e140e2c49a
7
- data.tar.gz: 5ec3f301e10bc80b69bddfeeaeab44dd4ca89bbaf08e4e40b77386d99ff8e90001a1c17c90c6917dc3a737a766d700995789c5257278ee1f8e3caf4c62220004
6
+ metadata.gz: '0218b3e4e731b81e21c2f16df0eaa1f86c5267b815b9059de8922e233ceae9a7f4646bce089b215c38347e950fe20636753fd57aa5a9b61ef4617126fd4e96b8'
7
+ data.tar.gz: 22b6023ea6c0edf6d5c23de9b36c908f5b323b449c14ecdab0562d59b131e5ed54341d19e6404cf22d351384531bf3943eba60c958aed9566fdc589b900b4ad4
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- paquito (0.2.1)
10
+ paquito (0.3.0)
11
11
  msgpack
12
12
 
13
13
  GEM
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paquito
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paquito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
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