Class: Rack::Cappuccino
- Inherits:
-
Object
- Object
- Rack::Cappuccino
- Defined in:
- lib/rack/cappuccino.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*args) ⇒ Cappuccino
constructor
A new instance of Cappuccino.
Constructor Details
#initialize(*args) ⇒ Cappuccino
Returns a new instance of Cappuccino.
10 11 12 13 |
# File 'lib/rack/cappuccino.rb', line 10 def initialize(*args) appname = args.last.delete(:appname) @root = "Build/Release/#{appname}" end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
8 9 10 |
# File 'lib/rack/cappuccino.rb', line 8 def root @root end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/cappuccino.rb', line 15 def call(env) info = Request.new(env).path_info info = "/index.html" if info == "/" path = Pathname.new(::File.join(@root, info)) mime = Mime.mime_type(path.extname) if path.exist? && !path.directory? && path.to_s !~ /\.\./ [200, { "Content-Type" => mime, "Content-Length" => path.size.to_s }, [path.read]] else [404, {"Content-Type" => "text/plain"}, [""]] end end |