Class: Yuriita::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/yuriita/router.rb

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



3
4
5
# File 'lib/yuriita/router.rb', line 3

def initialize
  @routes = []
end

Instance Method Details

#append_route(collection, matcher, to:) ⇒ Object



7
8
9
# File 'lib/yuriita/router.rb', line 7

def append_route(collection, matcher, to:)
  routes.append Route.new(collection, matcher, to)
end

#match_for(input) ⇒ Object



18
19
20
# File 'lib/yuriita/router.rb', line 18

def match_for(input)
  routes.detect { |route| route.match?(input) }
end

#route(input, relation) ⇒ Object



11
12
13
14
15
16
# File 'lib/yuriita/router.rb', line 11

def route(input, relation)
  if route = match_for(input)
    collection = route.collection
    collection.dispatch(route.action, input, relation)
  end
end