Class: BioDSL::Pipeline
- Inherits:
-
Object
- Object
- BioDSL::Pipeline
- Includes:
- EmailHelper, HistoryHelper, LogHelper, OptionsHelper, StatusHelper
- Defined in:
- lib/BioDSL/pipeline.rb
Overview
Pipeline class
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#complete ⇒ Object
Returns the value of attribute complete.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Method that adds two Pipelines and return a new Pipeline.
-
#<<(other) ⇒ self
Method for merging one pipeline onto another.
-
#initialize ⇒ Pipeline
constructor
Pipeline class constructor.
-
#pop ⇒ Object
Removes last command from a Pipeline and returns a new Pipeline with this command.
-
#run(options = {}) ⇒ self
Run all the commands in the Pipeline.
-
#size ⇒ Integer
The size or number of commands in a pipeline.
-
#status ⇒ Array
Return a list of all status hashes from the commands.
-
#to_s ⇒ Object
Format a Pipeline to a pretty string which is returned.
Methods included from StatusHelper
#status_init, #status_progress
Methods included from HistoryHelper
Methods included from LogHelper
Methods included from EmailHelper
Constructor Details
#initialize ⇒ Pipeline
Pipeline class constructor.
54 55 56 57 58 59 |
# File 'lib/BioDSL/pipeline.rb', line 54 def initialize @commands = [] # Array of Commands in the Pipeline. @options = {} # Options hash. @enums = [[]] # Array of Enumerators. @complete = false # Flag denoting if run was completed. end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ self (private)
Add a command to the pipeline. This is done by first requiring the relevant Class/Module and then calling the relevant command.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/BioDSL/pipeline.rb', line 171 def method_missing(method, *args, &block) require_file(method) const = method.to_s.split('_').map(&:capitalize).join('') if BioDSL.const_defined? const = args.first || {} (, method) klass = BioDSL.const_get(const) klass.send(:include, OptionsHelper) klass.send(:include, StatusHelper) lmb = klass.send(:new, ).lmb @commands << Command.new(method, lmb, ) else super end self end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
51 52 53 |
# File 'lib/BioDSL/pipeline.rb', line 51 def commands @commands end |
#complete ⇒ Object
Returns the value of attribute complete.
51 52 53 |
# File 'lib/BioDSL/pipeline.rb', line 51 def complete @complete end |
Instance Method Details
#+(other) ⇒ Object
Method that adds two Pipelines and return a new Pipeline.
79 80 81 82 83 84 85 86 87 |
# File 'lib/BioDSL/pipeline.rb', line 79 def +(other) unless other.is_a?(BioDSL::Pipeline) fail PipelineError, "Not a pipeline: #{other.inspect}" end p = self.class.new p << self p << other end |
#<<(other) ⇒ self
Method for merging one pipeline onto another.
71 72 73 74 75 76 |
# File 'lib/BioDSL/pipeline.rb', line 71 def <<(other) other.commands.map { |command| commands << command } other.status.map { |status| self.status << status } self end |
#pop ⇒ Object
Removes last command from a Pipeline and returns a new Pipeline with this command.
91 92 93 94 95 |
# File 'lib/BioDSL/pipeline.rb', line 91 def pop p = BioDSL::Pipeline.new p.commands = [@commands.pop] p end |
#run(options = {}) ⇒ self
Run all the commands in the Pipeline.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/BioDSL/pipeline.rb', line 105 def run( = {}) prime_variables() fail BioDSL::PipelineError, 'Empty pipeline' if @commands.empty? @options = command_runner print_status send_email(self) save_report log_ok self rescue => exception exit_gracefully(exception) ensure save_history end |
#size ⇒ Integer
Returns The size or number of commands in a pipeline.
62 63 64 |
# File 'lib/BioDSL/pipeline.rb', line 62 def size @commands.size end |
#status ⇒ Array
Return a list of all status hashes from the commands.
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/BioDSL/pipeline.rb', line 129 def status @commands.each_with_object([]) do |e, a| if @complete e.calc_time_elapsed e.calc_delta end a << e.status end end |
#to_s ⇒ Object
Format a Pipeline to a pretty string which is returned.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/BioDSL/pipeline.rb', line 141 def to_s command_strings = %w(BD new) @commands.each { |command| command_strings << command.to_s } if @complete if @options.empty? command_strings << 'run' else command_strings << "run(#{})" end end command_strings.join('.') end |