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

- (MiddlewareStack) initialize(*args, &block)



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

- (Object) active



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

- (Object) build(app = nil, &block)



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

- (Object) insert(index, *args, &block) 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

- (Object) insert_after(index, *args, &block)



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

- (Object) swap(target, *args, &block)



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

- (Object) use(*args, &block)



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