Class: DAV4Rack::Interceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/dav4rack/interceptor.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, args = {}) ⇒ Interceptor

Returns a new instance of Interceptor.



4
5
6
7
8
9
10
# File 'lib/dav4rack/interceptor.rb', line 4

def initialize(app, args={})
  @roots = args[:mappings].keys
  @args = args
  @app = app
  @intercept_methods = %w(OPTIONS PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK)
  @intercept_methods -= args[:ignore_methods] if args[:ignore_methods]
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/dav4rack/interceptor.rb', line 12

def call(env)
  path = env['PATH_INFO'].downcase
  method = env['REQUEST_METHOD'].upcase
  app = nil
  if(@roots.detect{|x| path =~ /^#{Regexp.escape(x.downcase)}\/?/}.nil? && @intercept_methods.include?(method))
    app = DAV4Rack::Handler.new(:resource_class => InterceptorResource, :mappings => @args[:mappings], :log_to => @args[:log_to])
  end
  app ? app.call(env) : @app.call(env)
end