Class: Sidekiq::Middleware::Chain
- Inherits:
-
Object
- Object
- Sidekiq::Middleware::Chain
- Defined in:
- lib/sidekiq/middleware/chain.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(klass, *args) ⇒ Object
- #clear ⇒ Object
- #exists?(klass) ⇒ Boolean
-
#initialize {|_self| ... } ⇒ Chain
constructor
A new instance of Chain.
- #invoke(*args, &final_action) ⇒ Object
- #remove(klass) ⇒ Object
- #retrieve ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Chain
Returns a new instance of Chain.
46 47 48 49 |
# File 'lib/sidekiq/middleware/chain.rb', line 46 def initialize @entries = [] yield self if block_given? end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
44 45 46 |
# File 'lib/sidekiq/middleware/chain.rb', line 44 def entries @entries end |
Instance Method Details
#add(klass, *args) ⇒ Object
55 56 57 |
# File 'lib/sidekiq/middleware/chain.rb', line 55 def add(klass, *args) entries << Entry.new(klass, *args) unless exists?(klass) end |
#clear ⇒ Object
67 68 69 |
# File 'lib/sidekiq/middleware/chain.rb', line 67 def clear entries.clear end |
#exists?(klass) ⇒ Boolean
59 60 61 |
# File 'lib/sidekiq/middleware/chain.rb', line 59 def exists?(klass) entries.any? { |entry| entry.klass == klass } end |
#invoke(*args, &final_action) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sidekiq/middleware/chain.rb', line 71 def invoke(*args, &final_action) chain = retrieve.dup traverse_chain = lambda do if chain.empty? final_action.call else chain.shift.call(*args, &traverse_chain) end end traverse_chain.call end |
#remove(klass) ⇒ Object
51 52 53 |
# File 'lib/sidekiq/middleware/chain.rb', line 51 def remove(klass) entries.delete_if { |entry| entry.klass == klass } end |
#retrieve ⇒ Object
63 64 65 |
# File 'lib/sidekiq/middleware/chain.rb', line 63 def retrieve entries.map(&:make_new) end |