Class: WadrcBcpScripts::ShellQueue
- Inherits:
-
Object
- Object
- WadrcBcpScripts::ShellQueue
- 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
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#completed_commands ⇒ Object
readonly
Returns the value of attribute completed_commands.
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#failed_commands ⇒ Object
readonly
Returns the value of attribute failed_commands.
Instance Method Summary collapse
- #<<(cmd) ⇒ Object
-
#initialize(options = {:dry_run => false}) ⇒ ShellQueue
constructor
Initialize a queue with an options hash.
-
#method_missing(m, *args, &block) ⇒ Object
Expose >>, << array methods to commands array.
-
#run! ⇒ Object
Run a queue (or print if dry_run).
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( = {:dry_run => false}) @commands = Array.new @dry_run = [: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
#commands ⇒ Object (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_commands ⇒ Object (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_run ⇒ Object (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_commands ⇒ Object (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 |