Class: CampfireBot::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/plugin.rb

Constant Summary collapse

@@config_defaults =
{}

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePlugin

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_commandsObject (readonly)

Returns the value of attribute registered_commands.



12
13
14
# File 'lib/plugin.rb', line 12

def registered_commands
  @registered_commands
end

.registered_intervalsObject (readonly)

Returns the value of attribute registered_intervals.



12
13
14
# File 'lib/plugin.rb', line 12

def registered_intervals
  @registered_intervals
end

.registered_messagesObject (readonly)

Returns the value of attribute registered_messages.



12
13
14
# File 'lib/plugin.rb', line 12

def registered_messages
  @registered_messages
end

.registered_pluginsObject (readonly)

Returns the value of attribute registered_plugins.



12
13
14
# File 'lib/plugin.rb', line 12

def registered_plugins
  @registered_plugins
end

.registered_speakersObject (readonly)

Returns the value of attribute registered_speakers.



12
13
14
# File 'lib/plugin.rb', line 12

def registered_speakers
  @registered_speakers
end

.registered_timesObject (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(timestamp, *methods)
  methods.each do |method|
    Plugin.registered_times << Event::Time.new(timestamp, 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 on_message(regexp, *methods)
  methods.each do |method|
    Plugin.registered_messages << 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