Class: Command::CommandSetup
- Inherits:
-
SetVisitor
- Object
- SetVisitor
- Command::CommandSetup
- Defined in:
- lib/command-set/structural.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#arg_hash ⇒ Object
Returns the value of attribute arg_hash.
-
#command_class ⇒ Object
Returns the value of attribute command_class.
-
#set_nesting ⇒ Object
Returns the value of attribute set_nesting.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#task_id ⇒ Object
Returns the value of attribute task_id.
-
#terms ⇒ Object
Returns the value of attribute terms.
Attributes inherited from SetVisitor
#command_path, #subject_context
Instance Method Summary collapse
- #arrive_at(terms, node) ⇒ Object
- #class_resolution(command_set) ⇒ Object
- #command_instance(command_set, subject) ⇒ Object
-
#initialize(terms = [], hash = {}) ⇒ CommandSetup
constructor
A new instance of CommandSetup.
- #leave_from(via, terms, node) ⇒ Object
- #resolve_command_class(command_set) ⇒ Object
- #term_without_hop(terms, node) ⇒ Object
Methods inherited from SetVisitor
#command_out_of_terms, #extra_terms, #set_out_of_terms
Constructor Details
#initialize(terms = [], hash = {}) ⇒ CommandSetup
Returns a new instance of CommandSetup.
74 75 76 77 78 79 80 81 82 |
# File 'lib/command-set/structural.rb', line 74 def initialize(terms = [], hash = {}) super() @command_class = nil @subject = subject @arg_hash = hash @terms = terms.dup @task_id = nil @set_nesting = [] end |
Instance Attribute Details
#arg_hash ⇒ Object
Returns the value of attribute arg_hash.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def arg_hash @arg_hash end |
#command_class ⇒ Object
Returns the value of attribute command_class.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def command_class @command_class end |
#set_nesting ⇒ Object
Returns the value of attribute set_nesting.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def set_nesting @set_nesting end |
#subject ⇒ Object
Returns the value of attribute subject.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def subject @subject end |
#task_id ⇒ Object
Returns the value of attribute task_id.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def task_id @task_id end |
#terms ⇒ Object
Returns the value of attribute terms.
84 85 86 |
# File 'lib/command-set/structural.rb', line 84 def terms @terms end |
Instance Method Details
#arrive_at(terms, node) ⇒ Object
87 88 89 90 91 |
# File 'lib/command-set/structural.rb', line 87 def arrive_at(terms, node) @command_class = node subject = @subject.get_image(node.subject_requirements, @subject_context) return node.consume_terms(terms, subject, @arg_hash) end |
#class_resolution(command_set) ⇒ Object
106 107 108 |
# File 'lib/command-set/structural.rb', line 106 def class_resolution(command_set) @command_class = command_set.find_command(@terms.dup) end |
#command_instance(command_set, subject) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/command-set/structural.rb', line 116 def command_instance(command_set, subject) @subject ||= subject resolve_command_class(command_set) command = self.command_class.new(self, task_id) command.consume_hash(self.arg_hash) return command end |
#leave_from(via, terms, node) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/command-set/structural.rb', line 93 def leave_from(via, terms, node) if CommandSet === node @set_nesting << node end super end |
#resolve_command_class(command_set) ⇒ Object
110 111 112 113 114 |
# File 'lib/command-set/structural.rb', line 110 def resolve_command_class(command_set) return if Class === @command_class && Command > @command_class class_resolution(command_set) #@args_hash = @arg_hash.merge(@args_hash) end |
#term_without_hop(terms, node) ⇒ Object
100 101 102 103 104 |
# File 'lib/command-set/structural.rb', line 100 def term_without_hop(terms, node) if CommandSet === node raise CommandException, "#{@command_path.join(" ")}: No such command: #{terms.first}" end end |