Class: OctocatalogDiff::Util::Parallel::Task
- Inherits:
-
Object
- Object
- OctocatalogDiff::Util::Parallel::Task
- Defined in:
- lib/octocatalog-diff/util/parallel.rb
Overview
This class represents a parallel task. It requires a method reference, which will be executed with any supplied arguments. It can optionally take a text description and a validator function.
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Instance Method Summary collapse
- #execute(logger = Logger.new(StringIO.new)) ⇒ Object
-
#initialize(opts = {}) ⇒ Task
constructor
A new instance of Task.
- #validate(result, logger = Logger.new(StringIO.new)) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Task
Returns a new instance of Task.
25 26 27 28 29 30 31 |
# File 'lib/octocatalog-diff/util/parallel.rb', line 25 def initialize(opts = {}) @method = opts.fetch(:method) @args = opts.fetch(:args, {}) @description = opts[:description] || @method.name @validator = opts[:validator] @validator_args = opts[:validator_args] || {} end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
23 24 25 |
# File 'lib/octocatalog-diff/util/parallel.rb', line 23 def args @args end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
22 23 24 |
# File 'lib/octocatalog-diff/util/parallel.rb', line 22 def description @description end |
Instance Method Details
#execute(logger = Logger.new(StringIO.new)) ⇒ Object
33 34 35 |
# File 'lib/octocatalog-diff/util/parallel.rb', line 33 def execute(logger = Logger.new(StringIO.new)) @method.call(@args, logger) end |
#validate(result, logger = Logger.new(StringIO.new)) ⇒ Object
37 38 39 40 |
# File 'lib/octocatalog-diff/util/parallel.rb', line 37 def validate(result, logger = Logger.new(StringIO.new)) return true if @validator.nil? @validator.call(result, logger, @validator_args) end |