Class: Adhearsion::Router

Inherits:
Object show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/adhearsion/router.rb,
lib/adhearsion/router/route.rb

Defined Under Namespace

Classes: Route

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Router) initialize(&block)

A new instance of Router



11
12
13
14
# File 'lib/adhearsion/router.rb', line 11

def initialize(&block)
  @routes = []
  instance_exec(&block)
end

Instance Attribute Details

- (Object) routes (readonly)

Returns the value of attribute routes



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

def routes
  @routes
end

Instance Method Details

- (Object) handle(call)



26
27
28
29
30
# File 'lib/adhearsion/router.rb', line 26

def handle(call)
  return unless route = match(call)
  logger.info "Call #{call.id} selected route \"#{route.name}\" (#{route.target})"
  route.dispatcher
end

- (Object) match(call)



22
23
24
# File 'lib/adhearsion/router.rb', line 22

def match(call)
  @routes.find { |route| route.match? call }
end

- (Object) route(*args, &block)



16
17
18
19
20
# File 'lib/adhearsion/router.rb', line 16

def route(*args, &block)
  Route.new(*args, &block).tap do |route|
    @routes << route
  end
end