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.



24
25
26
27
28
29
30
# File 'lib/octocatalog-diff/util/parallel.rb', line 24

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.



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

def args
  @args
end

#descriptionObject (readonly)

Returns the value of attribute description.



21
22
23
# File 'lib/octocatalog-diff/util/parallel.rb', line 21

def description
  @description
end

Instance Method Details

#execute(logger = Logger.new(StringIO.new)) ⇒ Object



32
33
34
# File 'lib/octocatalog-diff/util/parallel.rb', line 32

def execute(logger = Logger.new(StringIO.new))
  @method.call(@args, logger)
end

#validate(result, logger = Logger.new(StringIO.new)) ⇒ Object



36
37
38
39
# File 'lib/octocatalog-diff/util/parallel.rb', line 36

def validate(result, logger = Logger.new(StringIO.new))
  return true if @validator.nil?
  @validator.call(result, logger, @validator_args)
end