diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-18 23:24:32 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-08-18 23:24:32 -0700 |
commit | 36b3ad8cd10a2635723e847e2c801a1cd8fb5415 (patch) | |
tree | 3c01e2a99d86fb9d7680abfeb2432475bbb5b165 /bocelli/core/router.rb | |
parent | 597840b750de571ee87dd34806fe5f188f45d667 (diff) | |
download | bocelli-36b3ad8cd10a2635723e847e2c801a1cd8fb5415.tar.gz bocelli-36b3ad8cd10a2635723e847e2c801a1cd8fb5415.tar.xz |
Diffstat (limited to 'bocelli/core/router.rb')
-rw-r--r-- | bocelli/core/router.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bocelli/core/router.rb b/bocelli/core/router.rb new file mode 100644 index 0000000..16b4371 --- /dev/null +++ b/bocelli/core/router.rb @@ -0,0 +1,28 @@ +module Bocelli + module Core + module Router + def setup_router + @routes = {} + end + + def on(route, &block) + raise 'no block given' if block.nil? + + @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 + end + end +end |