basket 0.0.5 → 0.0.6

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: d504bc414e4f443644bd06aa327dbeaabd175ff27b0ec29ef29a9c39a699f62f
4
- data.tar.gz: 11ad15d5ce03c2876d4ae11bb555df30497c5901474eeceeaf7e12a3ccedbb7b
3
+ metadata.gz: 0a3e9da361b2587c986144240ada1490a812ae9a9d0f6f639c0e38c167874ac8
4
+ data.tar.gz: 936a8d8b31d126cd35913cc1c087ecffbca722a2d5cc06747b23f26ba90d9055
5
5
  SHA512:
6
- metadata.gz: 243ffd026cdf35b1e8a284c6c7f4f518f0ebb552ec89cc7fa6eca98ae481d1122db2f67d442a7e0b39e0efe89ada816f7d1d5ad2a4ae5f8eba7bde070c1dad5a
7
- data.tar.gz: e290079ae4dd146465549cb5d891eb7739dbb9e3b807f23a4d2406d4a74dbc52b1de4305dd276b98312ec7be1b1c9feb92373e47dc8d71c4ee7017d3f00258d0
6
+ metadata.gz: 551534c644dbb4a269f2de9de81ae43aef66f7e41dedef2e27845d4edcd17584d74067339110611628052282f5601ca9d5c39dd7962a4a71103110b9d1b37b1a
7
+ data.tar.gz: 96af7b3698edec4b70b3fa13acbb007ee17a03750c2df6583ed42df0e144bc32da8074378425ac24a655e6630070d2bcadd5b9870f2e4523804003fcdbd72fb6
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- basket (0.0.5)
4
+ basket (0.0.6)
5
5
  redis
6
6
  redis-namespace
7
7
 
data/README.md CHANGED
@@ -32,7 +32,7 @@ while chicken.laying? do
32
32
  end
33
33
  ```
34
34
 
35
- The item added to the basket can be any data you want! If you are using the in memory Queue, it is fine to store Ruby objects, but if you have a different backend, it might be better to stick to easily serializable objects.
35
+ The item added to the basket can be any data you want! If you are using the in memory Queue, it is fine to store Ruby objects, but if you have a different backend, must be JSON serializable via `to_json`.
36
36
 
37
37
  ```ruby
38
38
  class QuicheBasket
@@ -100,7 +100,7 @@ end
100
100
 
101
101
  The defaults for a redis backend are the standard `"127.0.0.1"`, `6379`, `15` with a namespace of `:basket`.
102
102
 
103
- The default for the backend is the HashBackend, which can be set by passing `:hash` to `config.backend`, but you don't have to do that. Because it's the default!
103
+ The default for the backend is the MemoryBackend, which can be set by passing `:memory` to `config.backend`, but you don't have to do that. Because it's the default!
104
104
 
105
105
  For the redis configuration, you can alternatively pass a url, thusly:
106
106
 
@@ -1,6 +1,6 @@
1
1
  module Basket
2
2
  class BackendAdapter
3
- class HashBackend < Basket::BackendAdapter
3
+ class MemoryBackend < Basket::BackendAdapter
4
4
  def initialize
5
5
  @data = {}
6
6
  end
@@ -1,4 +1,5 @@
1
1
  require "redis-namespace"
2
+ require "json"
2
3
 
3
4
  module Basket
4
5
  class BackendAdapter
@@ -25,9 +26,7 @@ module Basket
25
26
  end
26
27
 
27
28
  def push(queue, data)
28
- # TODO: should we use JSON vs Marshal?
29
- marshalled_data = Marshal.dump(data)
30
- @client.lpush(queue, marshalled_data)
29
+ @client.lpush(queue, serialize_data(data))
31
30
  end
32
31
 
33
32
  def length(queue)
@@ -44,8 +43,12 @@ module Basket
44
43
 
45
44
  private
46
45
 
46
+ def serialize_data(data)
47
+ JSON.generate(data)
48
+ end
49
+
47
50
  def deserialized_queue_data(queue)
48
- @client.lrange(queue, 0, -1).reverse.map { |marshalled_data| Marshal.load(marshalled_data) }
51
+ @client.lrange(queue, 0, -1).reverse.map { |serialized_data| JSON.parse(serialized_data) }
49
52
  end
50
53
 
51
54
  def select_redis_connection
@@ -7,15 +7,15 @@ module Basket
7
7
  @redis_host = "127.0.0.1"
8
8
  @redis_port = 6379
9
9
  @redis_db = 15
10
- @backend = BackendAdapter::HashBackend
10
+ @backend = BackendAdapter::MemoryBackend
11
11
  @namespace = :basket
12
12
  @redis_url = nil
13
13
  end
14
14
 
15
15
  def backend=(backend)
16
16
  case backend
17
- when :hash
18
- @backend = BackendAdapter::HashBackend
17
+ when :memory
18
+ @backend = BackendAdapter::MemoryBackend
19
19
  when :redis
20
20
  @backend = BackendAdapter::RedisBackend
21
21
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Basket
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
data/lib/basket.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "basket/backend_adapter"
4
- require_relative "basket/backend_adapter/hash_backend"
4
+ require_relative "basket/backend_adapter/memory_backend"
5
5
  require_relative "basket/backend_adapter/redis_backend"
6
6
  require_relative "basket/batcher"
7
7
  require_relative "basket/configuration"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: basket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - nichol alexander
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-04-04 00:00:00.000000000 Z
12
+ date: 2023-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -62,6 +62,7 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".rspec"
65
+ - ".ruby-version"
65
66
  - ".standard.yml"
66
67
  - CHANGELOG.md
67
68
  - CODE_OF_CONDUCT.md
@@ -74,7 +75,7 @@ files:
74
75
  - basket.gemspec
75
76
  - lib/basket.rb
76
77
  - lib/basket/backend_adapter.rb
77
- - lib/basket/backend_adapter/hash_backend.rb
78
+ - lib/basket/backend_adapter/memory_backend.rb
78
79
  - lib/basket/backend_adapter/redis_backend.rb
79
80
  - lib/basket/batcher.rb
80
81
  - lib/basket/configuration.rb
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []
108
- rubygems_version: 3.4.7
109
+ rubygems_version: 3.3.3
109
110
  signing_key:
110
111
  specification_version: 4
111
112
  summary: Wait until you have a bunch of things, then do something.