Class: BoPeep::Command::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/bopeep.rb

Defined Under Namespace

Classes: BlockProxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, run_object, hosts, order: nil, log: nil, &setup) ⇒ Step

Returns a new instance of Step.



2119
2120
2121
2122
2123
2124
2125
2126
# File 'lib/bopeep.rb', line 2119

def initialize(command, run_object, hosts, order: nil, log: nil, &setup)
  @command = command
  @run_object = run_object
  @hosts = hosts
  @order = order || :parallel
  @log = log.nil? ? true : log
  @callbacks_definition = Host::Callbacks::Definition.new(command, &setup)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



2113
2114
2115
# File 'lib/bopeep.rb', line 2113

def command
  @command
end

#hostsObject (readonly)

Returns the value of attribute hosts.



2114
2115
2116
# File 'lib/bopeep.rb', line 2114

def hosts
  @hosts
end

#nextObject

Returns the value of attribute next.



2115
2116
2117
# File 'lib/bopeep.rb', line 2115

def next
  @next
end

#previousObject

Returns the value of attribute previous.



2116
2117
2118
# File 'lib/bopeep.rb', line 2116

def previous
  @previous
end

#resultObject (readonly)

Returns the value of attribute result.



2117
2118
2119
# File 'lib/bopeep.rb', line 2117

def result
  @result
end

Class Method Details

.local(command, banner, block, **options) ⇒ Object



2109
2110
2111
# File 'lib/bopeep.rb', line 2109

def self.local(command, banner, block, **options)
  new(command, BlockProxy.new(banner, block), LOCALHOST, **options)
end

Instance Method Details

#log?Boolean

Returns:

  • (Boolean)


2128
2129
2130
# File 'lib/bopeep.rb', line 2128

def log?
  @log
end

#log_commandObject



2146
2147
2148
2149
2150
# File 'lib/bopeep.rb', line 2146

def log_command
  if log?
    BoPeep.console.puts Console::SGR(command.command_name.console).with(text_color: :blue, effect: :bold)
  end
end

#log_stepObject



2152
2153
2154
2155
2156
# File 'lib/bopeep.rb', line 2152

def log_step
  if log?
    BoPeep.console.puts Console::SGR(" -> #{@run_object}").with(text_color: :magenta)
  end
end

#on_failure(&block) ⇒ Object



2170
2171
2172
# File 'lib/bopeep.rb', line 2170

def on_failure(&block)
  @callbacks_definition.on_failure(&block)
end

#on_stderr(&block) ⇒ Object



2162
2163
2164
# File 'lib/bopeep.rb', line 2162

def on_stderr(&block)
  @callbacks_definition.on_stderr(&block)
end

#on_stdout(&block) ⇒ Object



2158
2159
2160
# File 'lib/bopeep.rb', line 2158

def on_stdout(&block)
  @callbacks_definition.on_stdout(&block)
end

#on_success(&block) ⇒ Object



2166
2167
2168
# File 'lib/bopeep.rb', line 2166

def on_success(&block)
  @callbacks_definition.on_success(&block)
end

#runObject



2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
# File 'lib/bopeep.rb', line 2132

def run
  @result = case @run_object
            when String
              @hosts.run_command(@run_object, order: @order, callbacks: @callbacks_definition.callbacks, log: @log)
            when Script
              @hosts.run_script(@run_object, order: @order, callbacks: @callbacks_definition.callbacks, log: @log)
            when BlockProxy
              # NOTE: A `Proc` means `@hosts` is `LOCALHOST`
              Executor::Result.new.tap do |result|
                result.update LOCALHOST.run(callbacks: @callbacks_definition.callbacks, log: @log, &@run_object)
              end
            end
end