Class: Fantasy::Plugins
- Inherits:
-
Object
- Object
- Fantasy::Plugins
- Defined in:
- lib/fantasy-irc/plugins.rb
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #add(plugin) ⇒ Object
- #command(command, data, args) ⇒ Object
-
#initialize ⇒ Plugins
constructor
A new instance of Plugins.
- #load(name) ⇒ Object
Constructor Details
#initialize ⇒ Plugins
Returns a new instance of Plugins.
5 6 7 |
# File 'lib/fantasy-irc/plugins.rb', line 5 def initialize @plugins = {} end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
3 4 5 |
# File 'lib/fantasy-irc/plugins.rb', line 3 def plugins @plugins end |
Instance Method Details
#add(plugin) ⇒ Object
9 10 11 12 |
# File 'lib/fantasy-irc/plugins.rb', line 9 def add plugin @plugins[plugin.name] = plugin puts "#{plugin.name} = #{plugin}" end |
#command(command, data, args) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fantasy-irc/plugins.rb', line 33 def command command, data, args if not args.nil? args = args.split(' ') else args = [] end @plugins.values.each do |plugin| puts "#{plugin}" plugin.handle! command, data, args end end |
#load(name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fantasy-irc/plugins.rb', line 14 def load name local = File.join(File.dirname($0), "plugins") vendor = File.join(File.dirname(__FILE__), "..", "plugins") [*name].each do |n| file = "#{n}.rb" local_file = File.join(local, file) vendor_file = File.join(vendor, file) if File.exists?(local_file) puts "[plugin] Loading #{file} (local)." Kernel.load local_file elsif File::exists?(vendor_file) puts "[plugin] Loading #{file} (vendor)." Kernel.load vendor_file else puts "[plugin] #{file} could not be found." end end end |