Class: Vop::CommandLoader
- Inherits:
-
Object
- Object
- Vop::CommandLoader
- Defined in:
- lib/vop/command_loader.rb
Instance Method Summary collapse
-
#initialize(plugin) ⇒ CommandLoader
constructor
A new instance of CommandLoader.
- #new_command(name) ⇒ Object
- #read_sources(named_commands) ⇒ Object
- #run(&block) ⇒ Object
Constructor Details
#initialize(plugin) ⇒ CommandLoader
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vop/command_loader.rb', line 7 def initialize(plugin) @plugin = plugin @op = plugin.op @commands = {} # we need to load both the general helpers of the plugin because they are # used inside commands as well as the helpers specific to the command_loader @plugin.inject_helpers(self) @plugin.inject_helpers(self, 'command_loader') end |
Instance Method Details
#new_command(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/vop/command_loader.rb', line 19 def new_command(name) @command = Command.new(@plugin, name) @commands[@command.name] = @command @command end |
#read_sources(named_commands) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vop/command_loader.rb', line 29 def read_sources(named_commands) # reads a hash of <command_name> => <source string> named_commands.each do |name, source| new_command(name) begin self.instance_eval(source[:code], source[:file_name]) rescue => detail raise "problem loading plugin #{name} : #{detail.message}\n#{detail.backtrace.join("\n")}" end end @commands end |
#run(&block) ⇒ Object
25 26 27 |
# File 'lib/vop/command_loader.rb', line 25 def run(&block) @command.block = block end |