Class: Rack::Queries::App::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/queries/app.rb

Constant Summary collapse

STATIC =
::File.expand_path('static', __dir__)
FILES =
Dir[::File.join(STATIC, '*')].map do |path|
  "/#{::File.basename(path)}"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Static

Returns a new instance of Static.



54
55
56
57
# File 'lib/rack/queries/app.rb', line 54

def initialize(app)
  @app = app
  @server = File.new(STATIC)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



52
53
54
# File 'lib/rack/queries/app.rb', line 52

def app
  @app
end

#serverObject (readonly)

Returns the value of attribute server.



52
53
54
# File 'lib/rack/queries/app.rb', line 52

def server
  @server
end

Instance Method Details

#call(env) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/rack/queries/app.rb', line 59

def call(env)
  if env[PATH_INFO] == '/'
    render_index(env)
  elsif FILES.include?(env[PATH_INFO])
    server.call(env)
  else
    app.call(env)
  end
end