Class: WadrcBcpScripts::ShellQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/wadrc-bcp-scripts/freesurfer_roi_task.rb

Overview

Heroes in a half shell - Turtle Power!

Manage a list of shell commands. q = ShellQueue.new(:dry_run => true) q << “ls” q << “time” q.run!

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {:dry_run => false}) ⇒ ShellQueue

Initialize a queue with an options hash.



109
110
111
112
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 109

def initialize(options = {:dry_run => false})
  @commands = Array.new
  @dry_run = options[:dry_run]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

Expose >>, << array methods to commands array.



129
130
131
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 129

def method_missing(m, *args, &block)
  @commands.send(m, *args, &block)
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



106
107
108
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 106

def commands
  @commands
end

#completed_commandsObject (readonly)

Returns the value of attribute completed_commands.



106
107
108
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 106

def completed_commands
  @completed_commands
end

#dry_runObject (readonly)

Returns the value of attribute dry_run.



106
107
108
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 106

def dry_run
  @dry_run
end

#failed_commandsObject (readonly)

Returns the value of attribute failed_commands.



106
107
108
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 106

def failed_commands
  @failed_commands
end

Instance Method Details

#<<(cmd) ⇒ Object



123
124
125
126
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 123

def <<(cmd)
  @commands << cmd
  run!
end

#run!Object

Run a queue (or print if dry_run)



115
116
117
118
119
120
121
# File 'lib/wadrc-bcp-scripts/freesurfer_roi_task.rb', line 115

def run!
  while @commands.length > 0
    command = @commands.shift
    puts command
    @run_success = run command unless @dry_run
  end      
end