Class: RReDisServer::SprocketsMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rredis/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ SprocketsMiddleware

Returns a new instance of SprocketsMiddleware.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rredis/server.rb', line 7

def initialize(app, options={})
  @app = app
  @root = options[:root]
  path   =  options[:path] || 'assets'
  @matcher = /^\/#{path}\/*/
  @environment = ::Sprockets::Environment.new(@root)
  @environment.append_path 'assets/javascripts'
  @environment.append_path 'assets/javascripts/vendor'
  @environment.append_path 'assets/stylesheets'
  @environment.append_path 'assets/stylesheets/vendor'
  @environment.append_path 'assets/images'
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rredis/server.rb', line 20

def call(env)
  return [301, { 'Location' => "#{env['SCRIPT_NAME']}/" }, []] if env['SCRIPT_NAME'] == env['REQUEST_PATH']

  return @app.call(env) unless @matcher =~ env["PATH_INFO"]
  env['PATH_INFO'].sub!(@matcher,'')
  @environment.call(env)
end