Class: Caliph::CommandChain

Inherits:
CommandLine show all
Includes:
DefineOp
Defined in:
lib/caliph/command-chain.rb

Direct Known Subclasses

PipelineChain, PrereqChain, WrappingChain

Instance Attribute Summary collapse

Attributes inherited from CommandLine

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

Instance Method Summary collapse

Methods included from DefineOp

included

Methods inherited from CommandLine

#command, #copy_stream_to, emit_recording, #execute, execute, #must_succeed!, #options_composition, #original_execute, #redirect_both, #redirect_from, #redirect_stderr, #redirect_stdin, #redirect_stdout, #redirect_to, #run, #run_as_replacement, #run_detached, #run_in_background, #set_env, #string_format, #succeeds?

Constructor Details

#initializeCommandChain

Returns a new instance of CommandChain.



7
8
9
10
11
# File 'lib/caliph/command-chain.rb', line 7

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

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



13
14
15
# File 'lib/caliph/command-chain.rb', line 13

def commands
  @commands
end

Instance Method Details

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

Yields:

  • (cmd)


19
20
21
22
23
# File 'lib/caliph/command-chain.rb', line 19

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.



27
28
29
30
31
# File 'lib/caliph/command-chain.rb', line 27

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

#nameObject



33
34
35
# File 'lib/caliph/command-chain.rb', line 33

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

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/caliph/command-chain.rb', line 15

def valid?
  commands.all?{|cmd| cmd.valid?}
end