request_queue 0.2.1 → 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: 042f07181bbcaf2cbcad92425d4423307777d86e
4
- data.tar.gz: f77eb50b1867efb676ca1e0e09e69c37f20990ee
3
+ metadata.gz: fb4fadeffad30cc58d4d70f10ab82ba428a0716d
4
+ data.tar.gz: d3b1f3ca280bad3c268d152a7682289cab0985d2
5
5
  SHA512:
6
- metadata.gz: 00c83e64dce04e59c9251ef87f85f829ac3e4e83046e1b3323351fd9b5a925a6d274faca3f2e77cbd41c3134f72cf0c8ad296d170161c401e8f15267d2e8e86c
7
- data.tar.gz: fb1092d7dab38124eec22a64e69980034cd08762ed0b4b096c149adf44715dbe6135b4922348b064cc4ad711613dd9ad68054f0a1034b086fecb675b44c215ea
6
+ metadata.gz: ae9b1bf0a3a381c85a134ca470e976dd45d9bb52c1c3cf281de18241b133bf07c505d83fec9eba5bc78d06eccb1f4d434aba16f7417feede8dae59b3a7bc8abc
7
+ data.tar.gz: 47cde5ad4130e189775c6936e04dc533cb0bc859075b1405fb1cf80e147dc5cbfef61abad3ebf91c7494b1e86734f0227f8290f504cc8381044ca1ca49d81069
data/README.md CHANGED
@@ -90,14 +90,14 @@ When testing, sometimes you want a little more control. As such, `RequestQueue`
90
90
  * `:fake` - Never runs jobs, and allows you to inspect the queue with `RequestQueue.queue.queue`.
91
91
  * `:inline` - Runs jobs immediately and never adds them to the queue.
92
92
 
93
- To change the queueing backend, you can just say `RequestQueue.use`:
93
+ To change the queueing backend, you can just give the backend name as an argument to process.
94
94
 
95
95
  ```ruby
96
- RequestQueue.use :inline
96
+ RequestQueue.process :inline do
97
+ # ...
98
+ end
97
99
  ```
98
100
 
99
- **NOTE:** Only use the `use` method in the testing environment. It is not thread-safe.
100
-
101
101
  ## Development
102
102
 
103
103
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/request_queue.rb CHANGED
@@ -17,14 +17,6 @@ module RequestQueue
17
17
  end
18
18
 
19
19
  class << self
20
- def backend
21
- @backend || BACKENDS[:default]
22
- end
23
-
24
- def use(type)
25
- @backend = BACKENDS.fetch(type)
26
- end
27
-
28
20
  def queue=(value)
29
21
  RequestStore.store[:request_queue] = value
30
22
  end
@@ -41,12 +33,21 @@ module RequestQueue
41
33
  queue << message
42
34
  end
43
35
 
44
- def process
45
- self.queue = backend.new
46
- yield if block_given?
47
- queue.process
36
+ def process(backend = :default)
37
+ restore do
38
+ self.queue = BACKENDS.fetch(backend).new
39
+ yield if block_given?
40
+ queue.process
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def restore
47
+ original_queue = self.queue
48
+ yield
48
49
  ensure
49
- self.queue = nil
50
+ self.queue = original_queue
50
51
  end
51
52
  end
52
53
  end
@@ -1,3 +1,3 @@
1
1
  module RequestQueue
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_queue
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
  - Ray Zane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: request_store