From 0ed7f553aa951c8b107bed3908b6bb0eedfdb3f1 Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@gmail.com> Date: Tue, 1 Jan 2013 19:46:41 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20m=C3=A9thode=20can=5Fhandle=20d?= =?UTF-8?q?ans=20SitePlugin.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cette méthode soulève une exception. Elle DOIT être implémentée par les classes filles. --- lib/playbot.rb | 3 +-- lib/site_plugin.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/playbot.rb b/lib/playbot.rb index 3f9203b..53b9411 100644 --- a/lib/playbot.rb +++ b/lib/playbot.rb @@ -3,9 +3,8 @@ require 'net/yail/irc_bot' require 'site_plugin' -# +# -- # Add plugins folder to LOAD_PATH and subsequently require all plugins. -# dir = '../plugins' $LOAD_PATH << dir Dir[File.join(dir, '*.rb')].each {|file| require File.basename(file) } diff --git a/lib/site_plugin.rb b/lib/site_plugin.rb index c59d975..3ac1c38 100644 --- a/lib/site_plugin.rb +++ b/lib/site_plugin.rb @@ -1,3 +1,6 @@ +# Implement a plugin system. +# +# Each plugin have to inherite from this class and implement a can_handle?(site) method. class SitePlugin @@repository = [] @@ -9,7 +12,13 @@ class SitePlugin @@repository << target end + # Return the plugin that can handle a given site. def self.for_site(site) @@repository.find {|handler| handler.can_handle? site } end + + # A place holder method. This method *must* be implemented in the subclasses. + def can_handle?(site) + raise "Method not implemented !" + end end -- GitLab