Class: Embarista::DynamicIndex::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/embarista/dynamic_index/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Middleware

Returns a new instance of Middleware.



4
5
6
7
8
9
# File 'lib/embarista/dynamic_index/middleware.rb', line 4

def initialize(app, opts = {})
  @app = app
  @erb_path = opts[:erb] || 'app/index.html.erb'
  @path_info = opts.fetch(:path_info)
  @generator = Embarista::DynamicIndex::Generator.generator(@erb_path, 'dev')
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/embarista/dynamic_index/middleware.rb', line 11

def call(env)
  path = env["PATH_INFO"]
  if path == @path_info
    [
      200,
      { 'Content-Type' => "text/html" },
      [ @generator.html ]
    ]
  else
    @app.call(env)
  end
end