Module: Takeoff::Ext::MiddlewareBuilder
- Defined in:
- lib/takeoff/ext/middleware_builder.rb
Instance Method Summary collapse
- #delete(index) ⇒ Object
- #index(object) ⇒ Object
- #insert(index, middlewares, *args, &block) ⇒ Object (also: #insert_before)
- #insert_after(index, middlewares, *args, &block) ⇒ Object
- #middlewares ⇒ Object
Instance Method Details
#delete(index) ⇒ Object
45 46 47 48 49 |
# File 'lib/takeoff/ext/middleware_builder.rb', line 45 def delete(index) index = self.index(index) unless index.is_a?(Integer) raise "no such middleware to delete: #{index.inspect}" unless index stack.delete_at(index) end |
#index(object) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/takeoff/ext/middleware_builder.rb', line 10 def index(object) stack.each_with_index do |item, i| klass = item[0] return i if klass == object || (klass.respond_to?(:name) && klass.name.split("::").last == object) end nil end |
#insert(index, middlewares, *args, &block) ⇒ Object Also known as: insert_before
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/takeoff/ext/middleware_builder.rb', line 19 def insert(index, middlewares, *args, &block) index = self.index(index) unless index.is_a?(Integer) if middlewares.is_a?(Array) middlewares.each_with_index do |middleware, i| super(index + i, middleware, *args, &block) end else super end end |
#insert_after(index, middlewares, *args, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/takeoff/ext/middleware_builder.rb', line 33 def insert_after(index, middlewares, *args, &block) index = self.index(index) unless index.is_a?(Integer) if middlewares.is_a?(Array) middlewares.each_with_index do |middleware, i| super(index + i, middleware, *args, &block) end else super end end |
#middlewares ⇒ Object
6 7 8 |
# File 'lib/takeoff/ext/middleware_builder.rb', line 6 def middlewares self.stack.map(&:first) end |