Class: Mattock::CommandChain

Inherits:
CommandLine show all
Defined in:
lib/mattock/command-line.rb

Direct Known Subclasses

PipelineChain, PrereqChain, WrappingChain

Instance Attribute Summary collapse

Attributes inherited from CommandLine

#env, #executable, #options, #output_stream, #redirections

Instance Method Summary collapse

Methods inherited from CommandLine

#background, #collect_result, #command, #complete, #copy_stream_to, define_chain_op, define_op, emit_recording, execute, #execute, #kill_process, #must_succeed!, #options_composition, #original_execute, #redirect_from, #redirect_stderr, #redirect_stdin, #redirect_stdout, #redirect_to, #replace_us, #report, #run, #set_env, #spawn_process, #spin_off, #string_format, #succeeds?, #verbose

Constructor Details

#initializeCommandChain

Returns a new instance of CommandChain.



208
209
210
211
212
# File 'lib/mattock/command-line.rb', line 208

def initialize
  @commands = []
  @command_environment = {}
  super(nil)
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



214
215
216
# File 'lib/mattock/command-line.rb', line 214

def commands
  @commands
end

Instance Method Details

#add(cmd) {|cmd| ... } ⇒ Object

Yields:

  • (cmd)


216
217
218
219
220
# File 'lib/mattock/command-line.rb', line 216

def add(cmd)
  yield cmd if block_given?
  @commands << cmd
  self
end

#command_environmentObject

Honestly this is sub-optimal - biggest driver for considering the mini-shell approach here.



224
225
226
227
228
# File 'lib/mattock/command-line.rb', line 224

def command_environment
  @command_environment = @commands.reverse.inject(@command_environment) do |env, command|
    env.merge(command.command_environment)
  end
end

#nameObject



230
231
232
# File 'lib/mattock/command-line.rb', line 230

def name
  @name || @commands.last.name
end