requeue 0.7.0 → 0.7.2

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: b016469d47ba1bf79c6cf3e62421484e37ad5bb8
4
- data.tar.gz: 520c9c9729a56fa27d36f3a47381cb39af834882
3
+ metadata.gz: 16b7f85c1aa1c960e6ff842c6552d8a2f15da648
4
+ data.tar.gz: 0659835500d1aa2cbe07d6f1cb874d5d00684e4c
5
5
  SHA512:
6
- metadata.gz: ce9842d4de28ff5beb96a30c0e9f0b953f59647220af293a9425baa3fd79017f678c30ea7b583ea309d078e4e604204666dc5d904aa13c8194c4abf1e11ec5fa
7
- data.tar.gz: 93578e2a7496f5a2b1d3c7ba268b14cfe0039203790d402dd38ef2bd7558bdc4d257838da61aff2b99db5654c0915e344acfe29b102fce6ca7beb6e0b9efdad5
6
+ metadata.gz: 3eb5540f3996393bb6f2db1fd0590ad99fbd0321e3264e81aaf00dec1d47fd46e5f3011f2ef098e66c9e9b807839aae7d3a391e0d28c9b547fb096c72d9cd111
7
+ data.tar.gz: 0128cb11ff7c9b6ce4999d73ac7eb4e700d0e550c703ebe533002a750445429c943557482084e37ad3ea096e46777f233cf2b6bff69f39a7a827a0b96c2d0a13
data/.gitignore CHANGED
@@ -17,6 +17,8 @@ test/version_tmp
17
17
  tmp
18
18
  *.bundle
19
19
  *.so
20
+ *.swp
21
+ *.swo
20
22
  *.o
21
23
  *.a
22
24
  mkmf.log
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Requeue
2
2
 
3
- TODO: Write a gem description
3
+ Requeue is a rediciulosly simple queue backed by redis.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,57 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Usage is simple
22
+ ```ruby
23
+ #create a new queue
24
+ q = Requeue::Queue.new
25
+
26
+ #optionally you can specify your prefix or the redis object you want to use
27
+ q = Requeue::Queue.new(redis:Redis.new,prefix:'awesome')
28
+
29
+ #you can also tell the queue to only add unique items to it's self
30
+ q = Requeue::Queue.new(unique:true)
31
+
32
+ #All functions that change the state of the queue are suffixed with '!'
33
+ #To enqueue a thing
34
+ q.enqueue!('thing')
35
+
36
+ #To dequeue the first item
37
+ q.dequeue!
38
+
39
+ #To remove an item from the queue
40
+ q.remove!('thing')
41
+
42
+ #To clear the queue
43
+ q.clear!
44
+
45
+ #To steal the first place in the queue
46
+ q.steal!
47
+
48
+ #To get the position of a value
49
+ q.position('thing') => 0
50
+
51
+ #To see if an item is queued
52
+ q.queued?('thing') => true
53
+
54
+ #To see the the current first item of the queue
55
+ q.owner => 'thing'
56
+
57
+ #To get the queue as a hash
58
+ q.as_hash
59
+
60
+ #To get the queue as a json blob
61
+ q.as_json
62
+
63
+ #To get the internal name of the queue
64
+ q.name
65
+
66
+ #To get the length of the queue
67
+ q.length
68
+
69
+ #To get all of the items in the queue
70
+ q.list
71
+ ```
22
72
 
23
73
  ## Contributing
24
74
 
@@ -2,9 +2,10 @@ require 'redis'
2
2
 
3
3
  module Requeue
4
4
  class Queue
5
- def initialize(redis: Redis.current, prefix: 'queue')
5
+ def initialize(redis: Redis.current, prefix: 'queue', unique:true)
6
6
  @prefix = prefix
7
- @redis = redis
7
+ @unique = unique
8
+ @redis = redis
8
9
  end
9
10
 
10
11
  def name
@@ -24,7 +25,7 @@ module Requeue
24
25
  end
25
26
 
26
27
  def enqueue!(value)
27
- if (queued?(value) == false)
28
+ if (@unique == false || !queued?(value))
28
29
  @redis.rpush(name, value)
29
30
  else
30
31
  length
@@ -48,6 +49,10 @@ module Requeue
48
49
  end
49
50
 
50
51
  def owner
52
+ first
53
+ end
54
+
55
+ def first
51
56
  @redis.lrange(name,0,1).first
52
57
  end
53
58
 
@@ -1,3 +1,3 @@
1
1
  module Requeue
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.2"
3
3
  end
Binary file
@@ -46,6 +46,13 @@ describe Requeue::Queue do
46
46
  expect(@queue.enqueue!('eric')).to eq(2)
47
47
  expect(@queue.length).to eq(2)
48
48
  end
49
+
50
+ it 'should add non-unique values if the queue is set to non-unique' do
51
+ nonunique = Requeue::Queue.new(unique:false)
52
+ nonunique.enqueue!('eric')
53
+ nonunique.enqueue!('eric')
54
+ expect(nonunique.length).to eq(2)
55
+ end
49
56
  end
50
57
  end
51
58
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requeue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Fode
@@ -52,7 +52,6 @@ files:
52
52
  - LICENSE.txt
53
53
  - README.md
54
54
  - Rakefile
55
- - lib/.requeue.rb.swp
56
55
  - lib/requeue.rb
57
56
  - lib/requeue/version.rb
58
57
  - requeue.gemspec
Binary file