Created
April 6, 2012 19:01
-
-
Save tenderlove/2322092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/resque.rb b/lib/resque.rb | |
index 5dc8c2e..f5e06f7 100644 | |
--- a/lib/resque.rb | |
+++ b/lib/resque.rb | |
@@ -140,7 +140,7 @@ module Resque | |
# | |
# Returns nothing | |
def push(queue, item) | |
- @queues[queue] << item | |
+ queue(queue) << item | |
end | |
# Pops a job off a queue. Queue name should be a string. | |
@@ -148,7 +148,7 @@ module Resque | |
# Returns a Ruby object. | |
def pop(queue) | |
begin | |
- @queues[queue].pop(true) | |
+ queue(queue).pop(true) | |
rescue ThreadError | |
nil | |
end | |
@@ -157,7 +157,7 @@ module Resque | |
# Returns an integer representing the size of a queue. | |
# Queue name should be a string. | |
def size(queue) | |
- @queues[queue].size | |
+ queue(queue).size | |
end | |
# Returns an array of items currently queued. Queue name should be | |
@@ -169,7 +169,7 @@ module Resque | |
# To get the 3rd page of a 30 item, paginatied list one would use: | |
# Resque.peek('my_list', 59, 30) | |
def peek(queue, start = 0, count = 1) | |
- @queues[queue].slice start, count | |
+ queue(queue).slice start, count | |
end | |
# Does the dirty work of fetching a range of items from a Redis list | |
@@ -192,7 +192,12 @@ module Resque | |
# Given a queue name, completely deletes the queue. | |
def remove_queue(queue) | |
redis.srem(:queues, queue.to_s) | |
- @queues[queue].destroy | |
+ queue(queue).destroy | |
+ end | |
+ | |
+ # Return the Resque::Queue object for a given name | |
+ def queue(name) | |
+ @queues[name.to_s] | |
end | |
diff --git a/test/resque_test.rb b/test/resque_test.rb | |
index b7d8545..bf6d155 100644 | |
--- a/test/resque_test.rb | |
+++ b/test/resque_test.rb | |
@@ -16,6 +16,10 @@ describe "Resque" do | |
Resque.redis = @original_redis | |
end | |
+ it 'treats symbols and strings the same' do | |
+ assert_equal Resque.queue(:people), Resque.queue('people') | |
+ end | |
+ | |
it "can set a namespace through a url-like string" do | |
assert Resque.redis | |
assert_equal :resque, Resque.redis.namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment