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 +4 -4
- data/.gitignore +2 -0
- data/README.md +52 -2
- data/lib/requeue.rb +8 -3
- data/lib/requeue/version.rb +1 -1
- data/spec/.requeue_spec.rb.swp +0 -0
- data/spec/requeue_spec.rb +7 -0
- metadata +1 -2
- data/lib/.requeue.rb.swp +0 -0
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 16b7f85c1aa1c960e6ff842c6552d8a2f15da648
         | 
| 4 | 
            +
              data.tar.gz: 0659835500d1aa2cbe07d6f1cb874d5d00684e4c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3eb5540f3996393bb6f2db1fd0590ad99fbd0321e3264e81aaf00dec1d47fd46e5f3011f2ef098e66c9e9b807839aae7d3a391e0d28c9b547fb096c72d9cd111
         | 
| 7 | 
            +
              data.tar.gz: 0128cb11ff7c9b6ce4999d73ac7eb4e700d0e550c703ebe533002a750445429c943557482084e37ad3ea096e46777f233cf2b6bff69f39a7a827a0b96c2d0a13
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # Requeue
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 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 | 
            -
             | 
| 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 |  | 
    
        data/lib/requeue.rb
    CHANGED
    
    | @@ -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 | 
            -
                  @ | 
| 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) | 
| 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 |  | 
    
        data/lib/requeue/version.rb
    CHANGED
    
    
    
        data/spec/.requeue_spec.rb.swp
    CHANGED
    
    | Binary file | 
    
        data/spec/requeue_spec.rb
    CHANGED
    
    | @@ -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. | 
| 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
         | 
    
        data/lib/.requeue.rb.swp
    DELETED
    
    | Binary file |