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, #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, #run, #set_env, #spawn_process, #spin_off, #string_format, #succeeds?, #verbose

Constructor Details

#initializeCommandChain

Returns a new instance of CommandChain.



199
200
201
202
203
# File 'lib/mattock/command-line.rb', line 199

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

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



205
206
207
# File 'lib/mattock/command-line.rb', line 205

def commands
  @commands
end

Instance Method Details

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

Yields:

  • (cmd)


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

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.



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

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

#nameObject



221
222
223
# File 'lib/mattock/command-line.rb', line 221

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