From 2af0cbd96d523b9ed6c4489e2dc71ca23c757d42 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 18 Aug 2014 21:39:05 -0700 Subject: Move matching/detection logic to modules. --- bocelli/module/base.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bocelli/module/base.rb') diff --git a/bocelli/module/base.rb b/bocelli/module/base.rb index 1306830..45b09d7 100644 --- a/bocelli/module/base.rb +++ b/bocelli/module/base.rb @@ -13,6 +13,19 @@ module Bocelli @routes[route] = block end + def match?(str, route) + case route + when Regexp + str =~ route + when String + str == route + end + end + + def match(str) + @routes.detect { |k, _| match?(str, k) } + end + class << self def extended(mod) super -- cgit v1.2.3-70-g09d2