Class: MobSpawner::Command

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

Overview

Represents a command to be called by the spawner. Can also hold environment variables and arbitrary client data to identify the object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Command #initialize(cmd, env = {}, data = nil) ⇒ Command

Creates a new command.

Overloads:

  • #initialize(opts = {}) ⇒ Command

    Parameters:

    • opts (Hash{Symbol=>Object}) (defaults to: {})

      option data to be passed during initialization. Keys can be any attribute defined on this class, such as #command, #env or #data.

  • #initialize(cmd, env = {}, data = nil) ⇒ Command

    Parameters:

    • cmd (String)

      the command to execute

    • env (Hash{String=>String}) (defaults to: {})

      environment variables to be set when running the command

    • data (Object) (defaults to: nil)

      any client data to be set on the command object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mob_spawner.rb', line 34

def initialize(cmd, env = {}, data = nil)
  self.env = {}
  if cmd.is_a?(Hash)
    cmd.each do |k, v|
      meth = "#{k}="
      send(meth, v) if respond_to?(meth)
    end
  else
    self.command = cmd
    self.env = env
    self.data = data
  end
end

Instance Attribute Details

#commandString

Returns the command to be executed by the spawner.

Returns:

  • (String)

    the command to be executed by the spawner



13
14
15
# File 'lib/mob_spawner.rb', line 13

def command
  @command
end

#dataObject

Returns arbitrary client data used to identify the command object.

Returns:

  • (Object)

    arbitrary client data used to identify the command object.



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

def data
  @data
end

#envHash{String=>String}

Returns any environment variables to be set when running the command.

Returns:

  • (Hash{String=>String})

    any environment variables to be set when running the command.



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

def env
  @env
end