Class: Hyraft::PreloadedStatic

Inherits:
Object
  • Object
show all
Defined in:
lib/hyraft/boot/preloaded_static.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PreloadedStatic.



6
7
8
9
# File 'lib/hyraft/boot/preloaded_static.rb', line 6

def initialize(app, options = {})
  @app = app
  @urls = options[:urls] || ["/styles", "/css", "/images", "/js", "/favicon.ico"]
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/hyraft/boot/preloaded_static.rb', line 11

def call(env)
  path = env['PATH_INFO']
  
  # Check if this is a static asset we should handle
  if @urls.any? { |url| path.start_with?(url) }
    serve_preloaded_asset(path)
  else
    @app.call(env)
  end
end