Class: DummyOscar::Router

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

Defined Under Namespace

Classes: Route

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



6
7
8
# File 'lib/dummy_oscar/router.rb', line 6

def initialize
  @routes = []
end

Instance Method Details

#add(path:, method:, response:) ⇒ Object



10
11
12
# File 'lib/dummy_oscar/router.rb', line 10

def add(path:, method:, response:)
  @routes << Route.new(path, method.downcase, response)
end

#find(path:, method:) ⇒ Object



14
15
16
17
18
# File 'lib/dummy_oscar/router.rb', line 14

def find(path:, method:)
  @routes.detect do |route|
    /\A(?:#{route.path})\z/.match?(path) && route.method == method.downcase
  end
end