Class: MailView::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_view/mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, controller, prefix = "/mail_view") ⇒ Mapper

Returns a new instance of Mapper.



3
4
5
6
7
# File 'lib/mail_view/mapper.rb', line 3

def initialize(app, controller, prefix = "/mail_view")
  @app        = app
  @controller = controller.respond_to?(:name) ? controller.name : controller.to_s
  @prefix     = Regexp.compile("^#{prefix}")
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/mail_view/mapper.rb', line 9

def call(env)
  if env["PATH_INFO"].to_s =~ @prefix
    env["SCRIPT_NAME"] = $&
    env["PATH_INFO"]   = $'

    @controller.constantize.call(env)
  else
    @app.call(env)
  end
end