Class: RackDAV::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_dav/handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
9
10
# File 'lib/rack_dav/handler.rb', line 5

def initialize(options={})
  @options = {
    :resource_class => FileResource,
    :root => Dir.pwd
  }.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack_dav/handler.rb', line 12

def call(env)
  request = Rack::Request.new(env)
  response = Rack::Response.new

  begin
    controller = Controller.new(request, response, @options.dup)
    controller.send(request.request_method.downcase)
    
  rescue HTTPStatus::Status => status
    response.status = status.code
  end
  
  # Strings in Ruby 1.9 are no longer enumerable.  Rack still expects the response.body to be
  # enumerable, however.
  response.body = [response.body] if not response.body.respond_to? :each

  response.status = response.status ? response.status.to_i : 200
  response.finish
end