Class: Artifact::Static
- Inherits:
-
Object
- Object
- Artifact::Static
- Defined in:
- lib/artifact/static.rb
Constant Summary collapse
- SUFFIXES =
['', '.html', '/index.html']
- NOT_FOUND =
'Not found mister.'
- DEFAULTS =
for static
{ # for static :root => 'build', :urls => ['/'], }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(options = {}) ⇒ Static
constructor
A new instance of Static.
Constructor Details
#initialize(options = {}) ⇒ Static
Returns a new instance of Static.
15 16 17 18 19 20 21 22 23 |
# File 'lib/artifact/static.rb', line 15 def initialize( = {}) not_found = .delete(:not_found) || NOT_FOUND text = IO.read(not_found) if File.exist?(not_found) @suffixes = .delete(:suffixes) || SUFFIXES @not_found = [404, {"Content-Type" => 'text/html'}, [text]] @static = ::Rack::Static.new( lambda { [404, {}, []] }, DEFAULTS.merge()) end |
Instance Method Details
#call(env) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/artifact/static.rb', line 25 def call(env) # resp = Rack::Head.call(env) # return resp if resp[0] != 404 found = nil @suffixes.each do |suffix| url = env['PATH_INFO'] + suffix resp = @static.call(env.merge({'PATH_INFO' => url})) break if resp[0] != 404 && found = resp end found or @not_found end |