Class: Impression::RackApp

Inherits:
Resource show all
Defined in:
lib/impression/rack_app.rb

Overview

The ‘RackApp` class represents Rack apps as resources.

Constant Summary

Constants inherited from Resource

Impression::Resource::FIRST_PATH_SEGMENT_REGEXP

Instance Attribute Summary

Attributes inherited from Resource

#children, #parent, #path

Instance Method Summary collapse

Methods inherited from Resource

#absolute_path, #add_child, #each, #html_response, #json_response, #remount, #remove_child, #render_tree_to_static_files, #route, #text_response, #to_proc

Constructor Details

#initialize(app: nil, **props, &block) ⇒ RackApp

Returns a new instance of RackApp.



11
12
13
14
15
16
17
18
# File 'lib/impression/rack_app.rb', line 11

def initialize(app: nil, **props, &block)
  raise "No Rack app given" unless app || block

  # We pass nil as the block, otherwise the block will pass to
  # Resource#initialize, which will cause #call to be overidden.
  super(**props, &nil) 
  @handler = Tipi::RackAdapter.run(app || block)
end

Instance Method Details

#call(req) ⇒ Object



20
21
22
23
24
25
# File 'lib/impression/rack_app.rb', line 20

def call(req)
  if @path != '/'
    req.rewrite!(@path, '/')
  end
  @handler.(req)
end