Class: ActionDispatch::MiddlewareStack

Inherits:
Array show all
Defined in:
actionpack/lib/action_dispatch/middleware/stack.rb

Direct Known Subclasses

ActionController::MiddlewareStack

Defined Under Namespace

Classes: Middleware

Instance Method Summary collapse

Methods inherited from Array

#as_json, #encode_json, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #sample, #second, #split, #third, #to, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml, #uniq_by, #uniq_by!, wrap

Constructor Details

#initialize(*args, &block) ⇒ MiddlewareStack

Returns a new instance of MiddlewareStack



43
44
45
46
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 43

def initialize(*args, &block)
  super(*args)
  block.call(self) if block_given?
end

Instance Method Details

#activeObject



71
72
73
74
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 71

def active
  ActiveSupport::Deprecation.warn "All middlewares in the chain are active since the laziness " <<
    "was removed from the middleware stack", caller
end

#build(app = nil, &block) ⇒ Object



76
77
78
79
80
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 76

def build(app = nil, &block)
  app ||= block
  raise "MiddlewareStack#build requires an app" unless app
  reverse.inject(app) { |a, e| e.build(a) }
end

#insert(index, *args, &block) ⇒ Object Also known as: insert_before



48
49
50
51
52
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 48

def insert(index, *args, &block)
  index = assert_index(index, :before)
  middleware = self.class::Middleware.new(*args, &block)
  super(index, middleware)
end

#insert_after(index, *args, &block) ⇒ Object



56
57
58
59
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 56

def insert_after(index, *args, &block)
  index = assert_index(index, :after)
  insert(index + 1, *args, &block)
end

#swap(target, *args, &block) ⇒ Object



61
62
63
64
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 61

def swap(target, *args, &block)
  insert_before(target, *args, &block)
  delete(target)
end

#use(*args, &block) ⇒ Object



66
67
68
69
# File 'actionpack/lib/action_dispatch/middleware/stack.rb', line 66

def use(*args, &block)
  middleware = self.class::Middleware.new(*args, &block)
  push(middleware)
end