Class: Xencap::RequestDispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/xencap/request_dispatcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ RequestDispatcher

Returns a new instance of RequestDispatcher.



2
3
4
5
6
7
# File 'lib/xencap/request_dispatcher.rb', line 2

def initialize(session)
  @session = session
  @proxy_classes = Dir[File.expand_path("../session_proxy/*rb", __FILE__)]
  @proxies = {}

end

Instance Method Details

#dispatch(scope, *args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/xencap/request_dispatcher.rb', line 9

def dispatch(scope, *args)
  if @proxies.has_key?(scope)
    # nothing to do here
  elsif filename = @proxy_classes.detect {|file| File.basename(file, ".rb").downcase == scope.to_s}
    require filename
    @proxies[scope] = Xencap::SessionProxy.const_get(scope.capitalize).new(@session)
  else
    @proxies[scope] = Xencap::SessionProxy.new(@session, scope)
  end

  @proxies[scope]
end