Class: Plugin

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(plgn) ⇒ Object

Registers the current plugin with the system.

Returns nothing.



35
36
37
38
39
# File 'lib/twke/plugin.rb', line 35

def inherited(plgn)
  Plugin.plugins << plgn
  Twke.plugin(plgn)
  super
end

.load_pluginObject

Invoked to load this plugin. Will initialize and add to the loaded plugins list. TODO: Add initialization parameters here??



28
29
30
# File 'lib/twke/plugin.rb', line 28

def load_plugin
  Plugin.loaded_plugins << new()
end

.loaded_pluginsObject



21
22
23
# File 'lib/twke/plugin.rb', line 21

def loaded_plugins
  @loaded_plugins ||= []
end

.plugin_nameObject

Returns a short name for the plugin



6
7
8
9
10
11
12
13
# File 'lib/twke/plugin.rb', line 6

def plugin_name
  @plugin_name ||= begin
    str = name.dup
    str.downcase!
    str.sub! /.*:/, ''
    str
  end
end

.pluginsObject

Track all the available plugins



17
18
19
# File 'lib/twke/plugin.rb', line 17

def plugins
  @plugins ||= []
end

Instance Method Details

#event(name, rp, opts) ⇒ Object

Invoked to send an event to this plugin. Checks if plugins responds to the event. All events take a routing prefix and the CLI options.



46
47
48
49
50
# File 'lib/twke/plugin.rb', line 46

def event(name, rp, opts)
  if self.respond_to?(name.to_sym)
    self.send(name.to_sym, rp, opts)
  end
end