Class: Command::CommandSetup

Inherits:
Object
  • Object
show all
Defined in:
lib/command-set/command.rb

Overview

An abstraction of the lifecycle of a command. Allows invocations to be postponed temporarily, or for the command to be instantiated and still passed around. Client code should almost never need to see this class, so the methods aren’t individually documented.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd = [], args = {}) ⇒ CommandSetup

Returns a new instance of CommandSetup.



41
42
43
44
45
46
# File 'lib/command-set/command.rb', line 41

def initialize(cmd = [], args = {})
  @task_id = nil
  @args_hash = args
  @terms = []
  @command = cmd
end

Instance Attribute Details

#args_hashObject

Returns the value of attribute args_hash.



48
49
50
# File 'lib/command-set/command.rb', line 48

def args_hash
  @args_hash
end

#commandObject

Returns the value of attribute command.



48
49
50
# File 'lib/command-set/command.rb', line 48

def command
  @command
end

#task_idObject

Returns the value of attribute task_id.



48
49
50
# File 'lib/command-set/command.rb', line 48

def task_id
  @task_id
end

#termsObject

Returns the value of attribute terms.



48
49
50
# File 'lib/command-set/command.rb', line 48

def terms
  @terms
end

Instance Method Details

#command_instance(command_set, subject) ⇒ Object



62
63
64
65
66
67
# File 'lib/command-set/command.rb', line 62

def command_instance(command_set, subject)
  command_class = resolve_command_class(command_set, subject)
  command = command_class.new(subject, task_id)
  command.consume_hash(@args_hash)
  return command
end

#resolve_command_class(command_set, subject) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/command-set/command.rb', line 50

def resolve_command_class(command_set, subject)
  unless Class === @command && Command > @command
    command_path = @command
    result = command_set.process_terms(command_path, subject)
    @command = result.command_class
    @args_hash = result.arg_hash.merge(@args_hash)
    @terms = command_path
  end

  return @command
end