Class: CampfireBot::Plugin
- Inherits:
-
Object
- Object
- CampfireBot::Plugin
- Defined in:
- lib/plugin.rb
Constant Summary collapse
- @@config_defaults =
{}
Class Attribute Summary collapse
-
.registered_commands ⇒ Object
readonly
Returns the value of attribute registered_commands.
-
.registered_intervals ⇒ Object
readonly
Returns the value of attribute registered_intervals.
-
.registered_messages ⇒ Object
readonly
Returns the value of attribute registered_messages.
-
.registered_plugins ⇒ Object
readonly
Returns the value of attribute registered_plugins.
-
.registered_speakers ⇒ Object
readonly
Returns the value of attribute registered_speakers.
-
.registered_times ⇒ Object
readonly
Returns the value of attribute registered_times.
Class Method Summary collapse
- .at_interval(interval, *methods) ⇒ Object
- .at_time(timestamp, *methods) ⇒ Object
-
.config_var(name, default) ⇒ Object
Declare a plugin configuration parameter with its default value.
-
.inherited(child) ⇒ Object
Registering plugins.
-
.on_command(command, *methods) ⇒ Object
Event handlers.
- .on_message(regexp, *methods) ⇒ Object
- .on_speaker(speaker, *methods) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Plugin
constructor
A new instance of Plugin.
Constructor Details
#initialize ⇒ Plugin
Returns a new instance of Plugin.
67 68 69 70 71 72 73 74 75 |
# File 'lib/plugin.rb', line 67 def initialize # initialize attr_readers setup with config_var config_prefix = self.class.to_s.underscore (@@config_defaults[self.class.name] || {}).each_pair { |name, default| instance_variable_set("@#{name.to_s}", bot.config["#{config_prefix}_#{name.to_s}"] || default) } end |
Class Attribute Details
.registered_commands ⇒ Object (readonly)
Returns the value of attribute registered_commands.
12 13 14 |
# File 'lib/plugin.rb', line 12 def registered_commands @registered_commands end |
.registered_intervals ⇒ Object (readonly)
Returns the value of attribute registered_intervals.
12 13 14 |
# File 'lib/plugin.rb', line 12 def registered_intervals @registered_intervals end |
.registered_messages ⇒ Object (readonly)
Returns the value of attribute registered_messages.
12 13 14 |
# File 'lib/plugin.rb', line 12 def @registered_messages end |
.registered_plugins ⇒ Object (readonly)
Returns the value of attribute registered_plugins.
12 13 14 |
# File 'lib/plugin.rb', line 12 def registered_plugins @registered_plugins end |
.registered_speakers ⇒ Object (readonly)
Returns the value of attribute registered_speakers.
12 13 14 |
# File 'lib/plugin.rb', line 12 def registered_speakers @registered_speakers end |
.registered_times ⇒ Object (readonly)
Returns the value of attribute registered_times.
12 13 14 |
# File 'lib/plugin.rb', line 12 def registered_times @registered_times end |
Class Method Details
.at_interval(interval, *methods) ⇒ Object
47 48 49 50 51 |
# File 'lib/plugin.rb', line 47 def at_interval(interval, *methods) methods.each do |method| Plugin.registered_intervals << Event::Interval.new(interval, self.to_s, method) end end |
.at_time(timestamp, *methods) ⇒ Object
53 54 55 56 57 |
# File 'lib/plugin.rb', line 53 def at_time(, *methods) methods.each do |method| Plugin.registered_times << Event::Time.new(, self.to_s, method) end end |
.config_var(name, default) ⇒ Object
Declare a plugin configuration parameter with its default value
60 61 62 63 64 65 |
# File 'lib/plugin.rb', line 60 def config_var(name, default) attr_reader name @@config_defaults ||= {} @@config_defaults[self.name] ||= {} @@config_defaults[self.name][name] = default end |
.inherited(child) ⇒ Object
Registering plugins
23 24 25 |
# File 'lib/plugin.rb', line 23 def inherited(child) Plugin.registered_plugins[child.to_s] = child end |
.on_command(command, *methods) ⇒ Object
Event handlers
29 30 31 32 33 |
# File 'lib/plugin.rb', line 29 def on_command(command, *methods) methods.each do |method| Plugin.registered_commands << Event::Command.new(command, self.to_s, method) end end |
.on_message(regexp, *methods) ⇒ Object
35 36 37 38 39 |
# File 'lib/plugin.rb', line 35 def (regexp, *methods) methods.each do |method| Plugin. << Event::Message.new(regexp, self.to_s, method) end end |
.on_speaker(speaker, *methods) ⇒ Object
41 42 43 44 45 |
# File 'lib/plugin.rb', line 41 def on_speaker(speaker, *methods) methods.each do |method| Plugin.registered_speakers << Event::Speaker.new(speaker, self.to_s, method) end end |