Class: Command::AnchoredCommandSetup

Inherits:
CommandSetup 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.
class CommandSetup
  def initialize(cmd = [], args = {})
    @task_id = nil
    @args_hash = args
    @terms = []
    @command = cmd
    @execution_context = nil
  end

  attr_accessor :task_id, :command, :args_hash, :terms

  def class_resolution(command_set, path, subject)
    return command_set.process_terms(path, subject)
  end

  def resolve_command_class(command_set, subject)
    if @execution_context.nil? && Class === @command && Command > @command
      @execution_context = TermProcessor.new(subject)
    else
      command_path = @command
      @execution_context = class_resolution(command_set, 
                                            command_path, 
                                            subject)
      @command = @execution_context.command_class
      @args_hash = @execution_context.arg_hash.merge(@args_hash)
      @terms = command_path
    end

    return @command
  end

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

Instance Attribute Summary collapse

Attributes inherited from CommandSetup

#arg_hash, #command_class, #set_nesting, #subject, #task_id, #terms

Attributes inherited from SetVisitor

#command_path, #subject_context

Instance Method Summary collapse

Methods inherited from CommandSetup

#arrive_at, #command_instance, #leave_from, #resolve_command_class, #term_without_hop

Methods inherited from SetVisitor

#arrive_at, #command_out_of_terms, #extra_terms, #leave_from, #set_out_of_terms, #term_without_hop

Constructor Details

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

Returns a new instance of AnchoredCommandSetup.



82
83
84
85
# File 'lib/command-set/command.rb', line 82

def initialize(command_set, cmd = [], args = {})
  super(cmd, args)
  @anchored_at = command_set
end

Instance Attribute Details

#anchored_atObject

Returns the value of attribute anchored_at.



87
88
89
# File 'lib/command-set/command.rb', line 87

def anchored_at
  @anchored_at
end

Instance Method Details

#class_resolution(current_set) ⇒ Object



89
90
91
# File 'lib/command-set/command.rb', line 89

def class_resolution(current_set)
  @command_class = @anchored_at.find_command(@terms.dup)
end