Class: OctocatalogDiff::Util::Parallel::Task

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#argsObject

Returns the value of attribute args.



23
24
25
# File 'lib/octocatalog-diff/util/parallel.rb', line 23

def args
  @args
end

#descriptionObject (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