diff options
Diffstat (limited to 'bocelli')
| -rw-r--r-- | bocelli/base.rb | 2 | ||||
| -rw-r--r-- | bocelli/module/base.rb | 13 | 
2 files changed, 14 insertions, 1 deletions
diff --git a/bocelli/base.rb b/bocelli/base.rb index e4998c1..990a819 100644 --- a/bocelli/base.rb +++ b/bocelli/base.rb @@ -62,7 +62,7 @@ module Bocelli            if $3 =~ /\A(\S+) (.*)/              if (mod = Hash[@modules.map { |k, v| [k.to_s, v] }][$1]) -              if (match = mod.routes.detect { |k, _| match($2, k) }) +              if (match = mod.match($2))                  route, block = match                  return new(str, route, block, metadata).execute 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  | 
