Class: Kibosh::Router

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/kibosh/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(map) ⇒ Router

Returns a new instance of Router.



9
10
11
# File 'lib/kibosh/router.rb', line 9

def initialize map
  @map = map
end

Instance Method Details

#driver(session, to, route) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kibosh/router.rb', line 13

def driver session, to, route
  driver = @map.detect do |pair|
    key, value = pair
    case key
    when String
      key == to
    when Regexp
      key.match to
    end
  end
  raise HostUnknown.new session, "#{to} unknown/unreachable" if !driver
  driver[1]
end