Class: Wolflow::TaskSpec
- Inherits:
-
Object
- Object
- Wolflow::TaskSpec
- Defined in:
- lib/wolflow/task_spec.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.spec_type ⇒ Object
readonly
Returns the value of attribute spec_type.
-
.spec_types ⇒ Object
readonly
Returns the value of attribute spec_types.
Instance Attribute Summary collapse
-
#connects_to ⇒ Object
writeonly
Sets the attribute connects_to.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#prev_tasks ⇒ Object
readonly
Returns the value of attribute prev_tasks.
-
#workflow_spec ⇒ Object
Returns the value of attribute workflow_spec.
Class Method Summary collapse
Instance Method Summary collapse
- #child_of?(spec) ⇒ Boolean
- #each_ancestor(visited = [self], &blk) ⇒ Object
- #each_child(task) ⇒ Object
- #each_parent(task) ⇒ Object
- #each_successor(visited = [self], &blk) ⇒ Object
-
#initialize(id: object_id.to_s, name: self.class.spec_type, workflow_spec: nil, prev_tasks: []) ⇒ TaskSpec
constructor
A new instance of TaskSpec.
Constructor Details
#initialize(id: object_id.to_s, name: self.class.spec_type, workflow_spec: nil, prev_tasks: []) ⇒ TaskSpec
Returns a new instance of TaskSpec.
11 12 13 14 15 16 |
# File 'lib/wolflow/task_spec.rb', line 11 def initialize(id: object_id.to_s, name: self.class.spec_type, workflow_spec: nil, prev_tasks: []) @id = id @name = name @workflow_spec = workflow_spec @prev_tasks = prev_tasks end |
Class Attribute Details
.spec_type ⇒ Object (readonly)
Returns the value of attribute spec_type.
81 82 83 |
# File 'lib/wolflow/task_spec.rb', line 81 def spec_type @spec_type end |
.spec_types ⇒ Object (readonly)
Returns the value of attribute spec_types.
81 82 83 |
# File 'lib/wolflow/task_spec.rb', line 81 def spec_types @spec_types end |
Instance Attribute Details
#connects_to=(value) ⇒ Object (writeonly)
Sets the attribute connects_to
9 10 11 |
# File 'lib/wolflow/task_spec.rb', line 9 def connects_to=(value) @connects_to = value end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/wolflow/task_spec.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/wolflow/task_spec.rb', line 7 def name @name end |
#prev_tasks ⇒ Object (readonly)
Returns the value of attribute prev_tasks.
7 8 9 |
# File 'lib/wolflow/task_spec.rb', line 7 def prev_tasks @prev_tasks end |
#workflow_spec ⇒ Object
Returns the value of attribute workflow_spec.
7 8 9 |
# File 'lib/wolflow/task_spec.rb', line 7 def workflow_spec @workflow_spec end |
Class Method Details
.from_hash(hash) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/wolflow/task_spec.rb', line 102 def from_hash(hash) case hash in { id: String => id, name: String => name, ** } TaskSpec.spec_types[name].new(**hash) in { id: String => id } new(id: id) else raise TaskSpecError, "can't deserialize #{hash} to a TaskSpec" end end |
.inherited(subclass) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wolflow/task_spec.rb', line 83 def inherited(subclass) super return superclass.inherited(subclass) unless self == TaskSpec name = subclass.name return unless name # anon class tag = name.demodulize.underscore raise Error, "spec type for #{tag} already exists" if @spec_types.key?(tag) subclass.instance_variable_set(:@spec_type, tag) subclass.instance_variable_get(:@spec_type).freeze @spec_types[tag] = subclass end |
Instance Method Details
#child_of?(spec) ⇒ Boolean
64 65 66 |
# File 'lib/wolflow/task_spec.rb', line 64 def child_of?(spec) spec.next_tasks.include?(self) || spec.next_tasks.one? { |child_spec| child_of?(child_spec) } end |
#each_ancestor(visited = [self], &blk) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wolflow/task_spec.rb', line 40 def each_ancestor(visited = [self], &blk) return enum_for(__method__, visited) unless blk @prev_tasks.each do |spec| next if visited.include?(spec) blk.call(spec) visited << spec spec.each_ancestor(visited, &blk) end end |
#each_child(task) ⇒ Object
18 19 20 |
# File 'lib/wolflow/task_spec.rb', line 18 def each_child(task, &) task.children.each(&) end |
#each_parent(task) ⇒ Object
22 23 24 |
# File 'lib/wolflow/task_spec.rb', line 22 def each_parent(task, &) task.parents.each(&) end |
#each_successor(visited = [self], &blk) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wolflow/task_spec.rb', line 26 def each_successor(visited = [self], &blk) return enum_for(__method__, visited) unless blk next_tasks.each do |spec| next if visited.include?(spec) blk.call(spec) visited << spec spec.each_successor(visited, &blk) end end |