turnpike 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/turnpike.rb +13 -8
  2. data/lib/turnpike/version.rb +1 -1
  3. metadata +5 -5
@@ -3,9 +3,19 @@ require 'redis'
3
3
  # A Redis-backed queue.
4
4
  class Turnpike
5
5
  class << self
6
+ def options
7
+ @options ||= {}
8
+ end
9
+
6
10
  # Timeout, in seconds, for blocking `pop` or `shift`.
7
11
  attr_accessor :timeout
8
12
 
13
+ @timeout = 0
14
+
15
+ def connect(options)
16
+ @options = options
17
+ end
18
+
9
19
  def configure(&block)
10
20
  yield self
11
21
  end
@@ -82,7 +92,7 @@ class Turnpike
82
92
  # the connection when the queue is empty. This argument defaults to false.
83
93
  def pop(blocking = false)
84
94
  if blocking
85
- redis.brpop(name, timeout)[1] rescue nil
95
+ redis.brpop(name, Turnpike.timeout)[1] rescue nil
86
96
  else
87
97
  redis.rpop(name)
88
98
  end
@@ -100,7 +110,7 @@ class Turnpike
100
110
  # the connection when the queue is empty. This argument defaults to false.
101
111
  def shift(blocking = false)
102
112
  if blocking
103
- redis.blpop(name, timeout)[1] rescue nil
113
+ redis.blpop(name, Turnpike.timeout)[1] rescue nil
104
114
  else
105
115
  redis.lpop(name)
106
116
  end
@@ -114,11 +124,6 @@ class Turnpike
114
124
  private
115
125
 
116
126
  def redis
117
- Redis.current
118
- end
119
-
120
- def timeout
121
- # Timeout will default to 0, which blocks indefinitely.
122
- self.class.timeout.to_i
127
+ Redis.current ||= Redis.connect(Turnpike.options)
123
128
  end
124
129
  end
@@ -1,3 +1,3 @@
1
1
  class Turnpike
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paper Cavalier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-07-18 00:00:00 +01:00
17
+ date: 2011-07-19 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -80,7 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- hash: 1142159480707083776
83
+ hash: 233113184440690465
84
84
  segments:
85
85
  - 0
86
86
  version: "0"
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- hash: 1142159480707083776
92
+ hash: 233113184440690465
93
93
  segments:
94
94
  - 0
95
95
  version: "0"