Class: Vop::CommandLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/vop/parts/command_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(plugin) ⇒ CommandLoader

Returns a new instance of CommandLoader.


8
9
10
11
12
13
14
15
16
17
# File 'lib/vop/parts/command_loader.rb', line 8

def initialize(plugin)
  @plugin = plugin
  @op = plugin.op

  @commands = []

  @plugin.inject_helpers(self)

  extend CommandSyntax
end

Instance Method Details

#new_command(name) ⇒ Object


19
20
21
22
23
# File 'lib/vop/parts/command_loader.rb', line 19

def new_command(name)
  @command = Command.new(@plugin, name)
  @commands << @command
  @command
end

#read_sources(named_commands) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vop/parts/command_loader.rb', line 25

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 Exception
      raise Errors::CommandLoadError.new("problem loading command #{name}")
    end
  end

  @commands
end