Class: MiasmaTerraform::Stack::Action
- Inherits:
-
Object
- Object
- MiasmaTerraform::Stack::Action
- Defined in:
- lib/miasma-terraform/stack.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#waiter ⇒ Object
readonly
Returns the value of attribute waiter.
Instance Method Summary collapse
-
#complete! ⇒ Process::Status
Wait for the process to complete.
-
#initialize(command, opts = {}) ⇒ self
constructor
Create a new action to run.
-
#on_complete {|result, self| ... } ⇒ Object
Register a block to be run when a process completes.
-
#on_io {|line, type| ... } ⇒ Object
Register a block to be run when process output is received.
-
#on_start {|self| ... } ⇒ Object
Register a block to be run when a process starts.
-
#start! ⇒ Object
Start the process.
-
#stderr ⇒ IO
Stderr stream.
-
#stdout ⇒ IO
Stdout stream.
Constructor Details
#initialize(command, opts = {}) ⇒ self
Create a new action to run
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/miasma-terraform/stack.rb', line 69 def initialize(command, opts={}) @command = command.dup.freeze @options = opts.to_smash @io_callbacks = [] @complete_callbacks = [] @start_callbacks = [] @cached_output = Smash.new( :stdout => StringIO.new(''), :stderr => StringIO.new('') ) if(@options.delete(:auto_start)) start! end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
62 63 64 |
# File 'lib/miasma-terraform/stack.rb', line 62 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
62 63 64 |
# File 'lib/miasma-terraform/stack.rb', line 62 def @options end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
62 63 64 |
# File 'lib/miasma-terraform/stack.rb', line 62 def stdin @stdin end |
#waiter ⇒ Object (readonly)
Returns the value of attribute waiter.
62 63 64 |
# File 'lib/miasma-terraform/stack.rb', line 62 def waiter @waiter end |
Instance Method Details
#complete! ⇒ Process::Status
Wait for the process to complete
101 102 103 104 105 106 107 108 109 |
# File 'lib/miasma-terraform/stack.rb', line 101 def complete! start! unless waiter if(@process_manager) @process_manager.join end result = waiter.value MiasmaTerraform::Stack.deregister_action(self) result end |
#on_complete {|result, self| ... } ⇒ Object
Register a block to be run when a process completes
143 144 145 146 |
# File 'lib/miasma-terraform/stack.rb', line 143 def on_complete(&block) @complete_callbacks << block self end |
#on_io {|line, type| ... } ⇒ Object
Register a block to be run when process output is received
134 135 136 137 |
# File 'lib/miasma-terraform/stack.rb', line 134 def on_io(&block) @io_callbacks << block self end |
#on_start {|self| ... } ⇒ Object
Register a block to be run when a process starts
151 152 153 154 |
# File 'lib/miasma-terraform/stack.rb', line 151 def on_start(&block) @start_callbacks << block self end |
#start! ⇒ Object
Start the process
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/miasma-terraform/stack.rb', line 85 def start! opts = Hash[@options.map{|k,v| [k.to_sym,v]}] MiasmaTerraform::Stack.register_action(self) @stdin, @stdout, @stderr, @waiter = Open3.popen3(@command, **opts) @start_callbacks.each do |callback| callback.call(self) end unless(@io_callbacks.empty? && @complete_callbacks.empty?) manage_process! end true end |
#stderr ⇒ IO
Returns stderr stream.
112 113 114 115 116 117 118 |
# File 'lib/miasma-terraform/stack.rb', line 112 def stderr if(@stderr == :managed_io) @cached_output[:stderr] else @stderr end end |
#stdout ⇒ IO
Returns stdout stream.
121 122 123 124 125 126 127 |
# File 'lib/miasma-terraform/stack.rb', line 121 def stdout if(@stdout == :managed_io) @cached_output[:stdout] else @stdout end end |