1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Merge pull request #600 from jackrg/master

Fix issue with #insert_before and #insert_after
This commit is contained in:
Jesse Cooke 2012-12-28 15:48:48 -08:00
commit 65e1a7edd8

View file

@ -77,13 +77,15 @@ module Sidekiq
end
def insert_before(oldklass, newklass, *args)
new_entry = entries.delete_if { |entry| entry.klass == newklass } || Entry.new(newklass, *args)
i = entries.index { |entry| entry.klass == newklass }
new_entry = i.nil? ? Entry.new(newklass, *args) : entries.delete_at(i)
i = entries.find_index { |entry| entry.klass == oldklass } || 0
entries.insert(i, new_entry)
end
def insert_after(oldklass, newklass, *args)
new_entry = entries.delete_if { |entry| entry.klass == newklass } || Entry.new(newklass, *args)
i = entries.index { |entry| entry.klass == newklass }
new_entry = i.nil? ? Entry.new(newklass, *args) : entries.delete_at(i)
i = entries.find_index { |entry| entry.klass == oldklass } || entries.count - 1
entries.insert(i+1, new_entry)
end