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

Change behavior to move an existing middleware to the requested position rather than ignoring existing middle wares.

This commit is contained in:
Jack Royal-Gordon 2012-12-19 09:18:28 -08:00
parent 71931fc0e1
commit 9d9f9732a2

View file

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