From 36b3ad8cd10a2635723e847e2c801a1cd8fb5415 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 18 Aug 2014 23:24:32 -0700 Subject: Less code duplication. --- bocelli/base.rb | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) (limited to 'bocelli/base.rb') diff --git a/bocelli/base.rb b/bocelli/base.rb index bc7e617..1b4ffa9 100644 --- a/bocelli/base.rb +++ b/bocelli/base.rb @@ -1,4 +1,5 @@ require_relative 'core/irc' +require_relative 'core/router' module Bocelli class Base @@ -21,9 +22,11 @@ module Bocelli class << self include Bocelli::Core::IRC + include Bocelli::Core::Router def setup - @routes = {} + setup_router + @modules = {} end @@ -33,27 +36,10 @@ module Bocelli subclass.setup end - def on(route, &block) - @routes[route] = block - end - def register(mod) @modules[mod.name[/[^:]+$/].downcase.intern] ||= mod 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 - def mod_match(str) if str =~ /\A(\S+) (.*)/ if (mod = Hash[@modules.map { |k, v| [k.to_s, v] }][$1]) -- cgit v1.2.3-70-g09d2