Class: StackCommander::Stack
- Inherits:
-
Object
- Object
- StackCommander::Stack
- Defined in:
- lib/stack_commander/stack.rb
Instance Method Summary collapse
- #<<(command) ⇒ Object
- #call ⇒ Object
-
#initialize(scope) ⇒ Stack
constructor
A new instance of Stack.
-
#initialize_command(klass) ⇒ Object
TODO: maybe this should be responsibility of the command? it would make testing easier.
- #size ⇒ Object
Constructor Details
#initialize(scope) ⇒ Stack
Returns a new instance of Stack.
5 6 7 8 |
# File 'lib/stack_commander/stack.rb', line 5 def initialize(scope) @queue = [] @scope = scope end |
Instance Method Details
#<<(command) ⇒ Object
14 15 16 17 18 |
# File 'lib/stack_commander/stack.rb', line 14 def <<(command) @queue.push(command) self # for chaining awesomeness << cmd << cmd2 << cmd3 end |
#call ⇒ Object
20 21 22 23 24 |
# File 'lib/stack_commander/stack.rb', line 20 def call if command_class = @queue.shift run_command(command_class) end end |
#initialize_command(klass) ⇒ Object
TODO: maybe this should be responsibility of the command? it would make testing easier
27 28 29 30 31 32 33 34 35 |
# File 'lib/stack_commander/stack.rb', line 27 def initialize_command(klass) parameters = StackCommander::DependencyInjection.new(klass).extract(@scope) command = klass.allocate command.instance_variable_set :@scope, @scope command.__send__(:initialize, *parameters) command end |
#size ⇒ Object
10 11 12 |
# File 'lib/stack_commander/stack.rb', line 10 def size @queue.length end |