Class: Hanami::Middleware::App Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/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.

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(router, 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.

Parameters:

Since:

  • 2.0.0



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/hanami/middleware/app.rb', line 18

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

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

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

    builder.run(router)

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

  @trie.freeze
  @inspector = router.inspector.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:

  • 2.0.0



39
40
41
# File 'lib/hanami/middleware/app.rb', line 39

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

#to_inspectObject

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:

  • 2.0.0



45
46
47
# File 'lib/hanami/middleware/app.rb', line 45

def to_inspect
  @inspector&.call.to_s
end