rack-redic 0.2.2 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9190ad054eec78d0314a378fb9617f826c05ab0
4
- data.tar.gz: 330593cae1a58e77bbcbfbbb516c984b5e1bb7cf
3
+ metadata.gz: 060c56a771cd80ea2e61cb4abbf91406e8766daa
4
+ data.tar.gz: 4f77b38762b713d241ea93a5daf9a70241f4e1f0
5
5
  SHA512:
6
- metadata.gz: 34b0c681b2aedc62288d23cd78accec23ff69c69c6c30aa8cbe1f5daeda69f294f5eb76d87c3a878b15dae7e011085a5ac56d64403b4b87351236b7c6143b1cd
7
- data.tar.gz: 35f31a99b9a287fc994a8953bde3617401a3313730ee52d5e7db5ff57a0642b011f9bdd99e89b0f0def166b20574d70d55df1f48e52e13ab53f7158ba7e207a1
6
+ metadata.gz: 21d1c9430203b82f90daabe32fcbd30050468b2f59c693ec454cbbcf2ff62398a580c86486cb60b7631467e0e7b74dca44e67bc317e20b3458e51b39b6cfface
7
+ data.tar.gz: c63d41ef4a89ae67783e12d70a0cd27c82a1a3803af6b3b7127575a398f25a8fe413baac3b365e93c36d64011c12457831f87a53d7df2f18f88e89cc176637b5
@@ -28,6 +28,8 @@ module Rack
28
28
  # Any other options will get passed to Rack::Session::Abstract::Persisted.
29
29
  #
30
30
  class Redic < Abstract::Persisted
31
+ REDIS_URL = 'REDIS_URL'.freeze
32
+
31
33
  def initialize(app, options = {})
32
34
  super
33
35
 
@@ -35,7 +37,7 @@ module Rack
35
37
  @storage = Storage.new(
36
38
  options[:expire_after],
37
39
  options.delete(:marshaller) { Marshal },
38
- options.delete(:url) { ENV.fetch('REDIS_URL') }
40
+ options.delete(:url) { ENV.fetch(REDIS_URL) }
39
41
  )
40
42
  end
41
43
 
@@ -48,7 +50,7 @@ module Rack
48
50
  end
49
51
 
50
52
  # Find the session (or generate a blank one).
51
- def find_session(req, sid)
53
+ def find_session(_req, sid)
52
54
  @mutex.synchronize do
53
55
  unless sid and session = @storage.get(sid)
54
56
  sid, session = generate_sid, {}
@@ -60,7 +62,7 @@ module Rack
60
62
  end
61
63
 
62
64
  # Write the session.
63
- def write_session(req, session_id, new_session, options)
65
+ def write_session(_req, session_id, new_session, _options)
64
66
  @mutex.synchronize do
65
67
  @storage.set(session_id, new_session)
66
68
 
@@ -69,7 +71,7 @@ module Rack
69
71
  end
70
72
 
71
73
  # Kill the session.
72
- def delete_session(req, session_id, options)
74
+ def delete_session(_req, session_id, options)
73
75
  @mutex.synchronize do
74
76
  @storage.delete(session_id)
75
77
  generate_sid unless options[:drop]
@@ -80,10 +82,16 @@ module Rack
80
82
 
81
83
  # A wrapper around Redic to simplify calls.
82
84
  class Storage
83
- DELETE = 'DEL'
84
- EXISTS = 'EXISTS'
85
- GET = 'GET'
86
- SET = 'SET'
85
+ # Redis commands.
86
+ DELETE = 'DEL'.freeze
87
+ EX = 'EX'.freeze
88
+ EXISTS = 'EXISTS'.freeze
89
+ GET = 'GET'.freeze
90
+ SET = 'SET'.freeze
91
+
92
+ # Assorted.
93
+ PACK = 'm'.freeze
94
+ ZERO = 0
87
95
 
88
96
  def initialize(expires, marshaller, url)
89
97
  @expires = expires
@@ -92,7 +100,7 @@ module Rack
92
100
  end
93
101
 
94
102
  def exists?(id)
95
- @storage.call(EXISTS, id) != 0
103
+ @storage.call(EXISTS, id) != ZERO
96
104
  end
97
105
 
98
106
  def get(id)
@@ -101,7 +109,7 @@ module Rack
101
109
 
102
110
  def set(id, object)
103
111
  arguments = [SET, id, serialize(object)]
104
- arguments = arguments + ['EX', @expires] if @expires
112
+ arguments = arguments + [EX, @expires] if @expires
105
113
 
106
114
  @storage.call(*arguments)
107
115
  end
@@ -114,13 +122,12 @@ module Rack
114
122
 
115
123
  # Should always return a string.
116
124
  def serialize(object)
117
- [Zlib::Deflate.deflate(@marshaller.dump(object))].pack('m')
125
+ [Zlib::Deflate.deflate(@marshaller.dump(object))].pack(PACK)
118
126
  end
119
127
 
120
128
  # Should always return the session object.
121
129
  def deserialize(string)
122
- return unless string
123
- @marshaller.load(Zlib::Inflate.inflate(string.unpack('m').first))
130
+ @marshaller.load(Zlib::Inflate.inflate(string.unpack(PACK).first))
124
131
  end
125
132
  end
126
133
  end
data/rack-redic.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'rack-redic'
5
- spec.version = '0.2.2'
5
+ spec.version = '0.3.0'
6
6
  spec.authors = ['Evan Lecklider']
7
7
  spec.email = ['evan@lecklider.com']
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-redic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Lecklider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack