Class: Hanami::API::Middleware::App Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/api/middleware/app.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Hanami::API middleware stack

Since:

  • 0.1.1

Instance Method Summary collapse

Constructor Details

#initialize(app, mapping) ⇒ App

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of App.

Since:

  • 0.1.1



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hanami/api/middleware/app.rb', line 15

def initialize(app, mapping)
  @trie = Hanami::API::Middleware::Trie.new(app)

  mapping.each do |path, stack|
    builder = Rack::Builder.new

    stack.each do |middleware, args, blk|
      builder.use(middleware, *args, &blk)
    end

    builder.run(app)

    @trie.add(path, builder.to_app.freeze)
  end

  @trie.freeze
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.1



35
36
37
# File 'lib/hanami/api/middleware/app.rb', line 35

def call(env)
  @trie.find(env["PATH_INFO"]).call(env)
end