Class: Poundie::Plugin
- Inherits:
-
Object
show all
- Defined in:
- lib/poundie/plugin.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(room) ⇒ Plugin
Returns a new instance of Plugin.
34
35
36
|
# File 'lib/poundie/plugin.rb', line 34
def initialize(room)
@room = room
end
|
Class Method Details
.action(&block) ⇒ Object
20
21
22
|
# File 'lib/poundie/plugin.rb', line 20
def self.action(&block)
define_method(:perform, &block)
end
|
.active ⇒ Object
7
8
9
|
# File 'lib/poundie/plugin.rb', line 7
def self.active
@active ||= []
end
|
.list ⇒ Object
3
4
5
|
# File 'lib/poundie/plugin.rb', line 3
def self.list
@list ||= {}
end
|
.match(&block) ⇒ Object
16
17
18
|
# File 'lib/poundie/plugin.rb', line 16
def self.match(&block)
define_method(:match?, &block)
end
|
.prefix(regex, &block) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/poundie/plugin.rb', line 24
def self.prefix(regex, &block)
match do |message|
message.body =~ regex
end
action do |message|
instance_exec(message.body.gsub(regex, ''), &block)
end
end
|
.register(name) ⇒ Object
11
12
13
14
|
# File 'lib/poundie/plugin.rb', line 11
def self.register(name)
puts "Registering #{name}: #{self}"
Poundie::Plugin.list[name] = self
end
|
Instance Method Details
#call(message) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/poundie/plugin.rb', line 38
def call(message)
message = Poundie::Campfire::Message.new(@room, message)
return if message.timestamp?
begin
match?(message) && perform(message)
rescue => e
puts "ERROR: #{e.message}"
puts e.backtrace.join("\n")
raise e
end
end
|