Class: Plines::Job
- Inherits:
-
Struct
- Object
- Struct
- Plines::Job
- Extended by:
- Forwardable
- Defined in:
- lib/plines/job.rb
Overview
An instance of a Step: a step class paired with some data for the job.
Constant Summary collapse
- RemoveNonexistentDependencyError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#dependents ⇒ Object
readonly
Returns the value of attribute dependents.
-
#klass ⇒ Object
Returns the value of attribute klass.
Class Method Summary collapse
-
.accumulate_instances ⇒ Object
Ensures all “identical” instances (same klass and data) created within the block are in fact the same object.
- .build(*args, &block) ⇒ Object
Instance Method Summary collapse
- #add_dependencies_for(batch_data) ⇒ Object
- #add_dependency(step) ⇒ Object
- #external_dependencies ⇒ Object
-
#initialize(klass, data) {|_self| ... } ⇒ Job
constructor
A new instance of Job.
- #remove_dependency(step) ⇒ Object
Constructor Details
#initialize(klass, data) {|_self| ... } ⇒ Job
Returns a new instance of Job.
11 12 13 14 15 16 |
# File 'lib/plines/job.rb', line 11 def initialize(klass, data) super(klass, IndifferentHash.from(data)) @dependencies = Set.new @dependents = Set.new yield self if block_given? end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data
6 7 8 |
# File 'lib/plines/job.rb', line 6 def data @data end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
8 9 10 |
# File 'lib/plines/job.rb', line 8 def dependencies @dependencies end |
#dependents ⇒ Object (readonly)
Returns the value of attribute dependents.
8 9 10 |
# File 'lib/plines/job.rb', line 8 def dependents @dependents end |
#klass ⇒ Object
Returns the value of attribute klass
6 7 8 |
# File 'lib/plines/job.rb', line 6 def klass @klass end |
Class Method Details
.accumulate_instances ⇒ Object
Ensures all “identical” instances (same klass and data) created within the block are in fact the same object. This is important when constructing the dependency graph, so that all the dependency/dependee relationships point to the right objects (rather than duplicate objects).
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plines/job.rb', line 55 def accumulate_instances self.repository = Hash.new { |h,k| h[k] = new(*k) } begin yield return repository.values ensure self.repository = nil end end |
.build(*args, &block) ⇒ Object
66 67 68 |
# File 'lib/plines/job.rb', line 66 def build(*args, &block) repository[args, &block] end |
Instance Method Details
#add_dependencies_for(batch_data) ⇒ Object
31 32 33 34 35 |
# File 'lib/plines/job.rb', line 31 def add_dependencies_for(batch_data) klass.dependencies_for(self, batch_data).each do |job| add_dependency(job) end end |
#add_dependency(step) ⇒ Object
18 19 20 21 |
# File 'lib/plines/job.rb', line 18 def add_dependency(step) dependencies << step step.dependents << self end |
#external_dependencies ⇒ Object
37 38 39 |
# File 'lib/plines/job.rb', line 37 def external_dependencies klass.external_dependencies_for(data) end |
#remove_dependency(step) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/plines/job.rb', line 24 def remove_dependency(step) unless dependencies.delete?(step) && step.dependents.delete?(self) raise RemoveNonexistentDependencyError, "Attempted to remove nonexistent dependency #{step} from #{self}" end end |