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

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

Instance Method Summary collapse

Methods included from DefineOp

included

Methods inherited from CommandLine

#command, emit_recording, #execute, #from, #must_succeed!, #options_composition, #original_execute, #redirect_both, #redirect_stderr, #redirect_stdin, #redirect_stdout, #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

#copy_stream_to(from, to) ⇒ Object



41
42
43
# File 'lib/caliph/command-chain.rb', line 41

def copy_stream_to(from, to)
  @commands.last.copy_stream_to(from, to)
end

#nameObject



45
46
47
# File 'lib/caliph/command-chain.rb', line 45

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

#redirect_from(path, stream) ⇒ Object



37
38
39
# File 'lib/caliph/command-chain.rb', line 37

def redirect_from(path, stream)
  @commands.last.redirect_from(path, stream)
end

#redirect_to(stream, path) ⇒ Object



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

def redirect_to(stream, path)
  @commands.last.redirect_to(stream, path)
end

#valid?Boolean

Returns:

  • (Boolean)


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

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