module Twitchbot::TimedPlugin
Base Plugin
module that registers methods that should be called periodically
Constants
- COMMANDS
Public Class Methods
included(klass)
click to toggle source
Define a class method called register on each class that includes this module, which allows the user to add methods to the COMMANDS
constant
def self.register(command:, method:) COMMANDS[base] = {} if COMMANDS[base].nil? COMMANDS[base][params[:command]] = params[:method] end
# File lib/twitchbot/timed_plugin.rb, line 38 def self.included(klass) klass.instance_eval do define_singleton_method 'register' do |params| COMMANDS[klass] = {} if COMMANDS[klass].nil? COMMANDS[klass][params[:method]] = params[:interval] end end end
Public Instance Methods
close(event)
click to toggle source
Method that can be overriden to react to the eventmachine :close
event
# File lib/twitchbot/timed_plugin.rb, line 29 def close(event) end
error(event)
click to toggle source
Method that can be overriden to react to the eventmachine :error
event
# File lib/twitchbot/timed_plugin.rb, line 26 def error(event) end
message(event)
click to toggle source
Method that can be overriden to react to the eventmachine :message
event
# File lib/twitchbot/timed_plugin.rb, line 23 def message(event) end
open(handler)
click to toggle source
Method that reacts to the eventmachine :open
event and creates a new eventmachine periodic timer for each plugin of this type
It is not recommended to override this method unless you plan on handling all logic for managing timed plugins yourself
# File lib/twitchbot/timed_plugin.rb, line 14 def open(handler) COMMANDS[self.class].each do |command, interval| EM::PeriodicTimer.new(interval) do send(command, handler) end end end