summaryrefslogtreecommitdiff
path: root/bocelli/module
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-08-18 21:39:05 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-08-18 21:39:05 -0700
commit2af0cbd96d523b9ed6c4489e2dc71ca23c757d42 (patch)
tree84712ccfd7fa97d95f8de696cee2ecd0df047fb6 /bocelli/module
parent5900db6fa61e2c6537e6a33bd3be61d50812c5a6 (diff)
downloadbocelli-2af0cbd96d523b9ed6c4489e2dc71ca23c757d42.tar.gz
bocelli-2af0cbd96d523b9ed6c4489e2dc71ca23c757d42.tar.xz
Move matching/detection logic to modules.
Diffstat (limited to 'bocelli/module')
-rw-r--r--bocelli/module/base.rb13
1 files changed, 13 insertions, 0 deletions
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