Class: Mailman::Middleware
- Inherits:
-
Object
- Object
- Mailman::Middleware
- Defined in:
- lib/mailman/middleware.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #add(klass) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize {|_self| ... } ⇒ Middleware
constructor
A new instance of Middleware.
- #insert_after(oldklass, newklass) ⇒ Object
- #insert_before(oldklass, newklass) ⇒ Object
- #remove(klass) ⇒ Object
- #run(*args, &final_action) ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 8 |
# File 'lib/mailman/middleware.rb', line 5 def initialize @entries = [] yield self if block_given? end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
3 4 5 |
# File 'lib/mailman/middleware.rb', line 3 def entries @entries end |
Instance Method Details
#add(klass) ⇒ Object
10 11 12 |
# File 'lib/mailman/middleware.rb', line 10 def add(klass) entries << klass end |
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/mailman/middleware.rb', line 43 def each(&block) entries.each(&block) end |
#insert_after(oldklass, newklass) ⇒ Object
23 24 25 26 |
# File 'lib/mailman/middleware.rb', line 23 def insert_after(oldklass, newklass) idx = entries.rindex(oldklass) || entries.count - 1 entries.insert(idx+1, newklass) end |
#insert_before(oldklass, newklass) ⇒ Object
18 19 20 21 |
# File 'lib/mailman/middleware.rb', line 18 def insert_before(oldklass, newklass) idx = entries.index(oldklass) || 0 entries.insert(idx, newklass) end |
#remove(klass) ⇒ Object
14 15 16 |
# File 'lib/mailman/middleware.rb', line 14 def remove(klass) entries.delete(klass) end |
#run(*args, &final_action) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mailman/middleware.rb', line 28 def run(*args, &final_action) final_return = nil stack = @entries.map {|m| m.new} traverse_stack = lambda do if stack.empty? final_return = final_action.call else stack.shift.call(*args, &traverse_stack) end end traverse_stack.call final_return end |