Class: StackCommander::Stack
- Inherits:
-
Object
- Object
- StackCommander::Stack
- Extended by:
- Forwardable
- 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.
10 11 12 13 |
# File 'lib/stack_commander/stack.rb', line 10 def initialize(scope) @queue = [] @scope = scope end |
Instance Method Details
#<<(command) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/stack_commander/stack.rb', line 19 def <<(command) StackCommander::DependencyInjection.new(command).match!(@scope) @queue.push(command) self # for chaining awesomeness << cmd << cmd2 << cmd3 end |
#call ⇒ Object
27 28 29 30 31 |
# File 'lib/stack_commander/stack.rb', line 27 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
34 35 36 37 38 39 40 41 42 |
# File 'lib/stack_commander/stack.rb', line 34 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
15 16 17 |
# File 'lib/stack_commander/stack.rb', line 15 def size @queue.length end |