Class: Squared::Workspace::Series
- Inherits:
-
Object
- Object
- Squared::Workspace::Series
- Extended by:
- Forwardable
- Includes:
- Rake::DSL
- Defined in:
- lib/squared/workspace/series.rb
Constant Summary collapse
- TASK_ALIAS =
{}
Instance Attribute Summary collapse
-
#multiple ⇒ Object
readonly
Returns the value of attribute multiple.
-
#parallel ⇒ Object
readonly
Returns the value of attribute parallel.
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Class Method Summary collapse
- .add(task, obj) ⇒ Object
- .alias(ref, obj) ⇒ Object
- .batch(*args, obj) ⇒ Object
- .rename(key, task) ⇒ Object
Instance Method Summary collapse
- #alias_get(key) ⇒ Object
- #base?(key) ⇒ Boolean
- #batch_get(key) ⇒ Object
- #build(parallel: [], pattern: []) ⇒ Object
- #extend?(obj, key) ⇒ Boolean
-
#initialize(workspace) ⇒ Series
constructor
A new instance of Series.
- #multiple?(val = nil) ⇒ Boolean
- #name_get(key) ⇒ Object
- #parallel?(val = nil) ⇒ Boolean
- #populate(proj) ⇒ Object
- #some?(key) ⇒ Boolean
- #sync?(val = nil) ⇒ Boolean
Constructor Details
#initialize(workspace) ⇒ Series
Returns a new instance of Series.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/squared/workspace/series.rb', line 64 def initialize(workspace) @workspace = workspace @sync = [] @multiple = [] @parallel = [] @session = { group: {}, parent: {}, id: [] } @data = {} TASK_KEYS.each { |key| @data[key] = [] } end |
Instance Attribute Details
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
60 61 62 |
# File 'lib/squared/workspace/series.rb', line 60 def multiple @multiple end |
#parallel ⇒ Object (readonly)
Returns the value of attribute parallel.
60 61 62 |
# File 'lib/squared/workspace/series.rb', line 60 def parallel @parallel end |
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
60 61 62 |
# File 'lib/squared/workspace/series.rb', line 60 def sync @sync end |
Class Method Details
.add(task, obj) ⇒ Object
20 21 22 23 |
# File 'lib/squared/workspace/series.rb', line 20 def add(task, obj) key_set task (TASK_EXTEND[task] ||= []) << obj end |
.alias(ref, obj) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/squared/workspace/series.rb', line 38 def alias(ref, obj) if obj.is_a?(Hash) obj.each { |key, val| (TASK_ALIAS[key] ||= {})[ref] = val } else TASK_ALIAS[obj]&.delete(ref) end end |
.batch(*args, obj) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/squared/workspace/series.rb', line 25 def batch(*args, obj) if obj.is_a?(Hash) obj.each do |key, val| key_set key data = TASK_BATCH[key] ||= {} args.each { |ref| (data[ref] ||= []).concat(val) } end elsif (data = TASK_BATCH[obj]) args.each { |ref| data.delete(ref) } TASK_KEYS.delete(obj) if data.empty? end end |
.rename(key, task) ⇒ Object
46 47 48 |
# File 'lib/squared/workspace/series.rb', line 46 def rename(key, task) TASK_NAME[key.to_sym] = task.to_sym end |
Instance Method Details
#alias_get(key) ⇒ Object
139 140 141 |
# File 'lib/squared/workspace/series.rb', line 139 def alias_get(key) TASK_ALIAS[key] end |
#base?(key) ⇒ Boolean
152 153 154 |
# File 'lib/squared/workspace/series.rb', line 152 def base?(key) TASK_BASE.include?(key) end |
#batch_get(key) ⇒ Object
135 136 137 |
# File 'lib/squared/workspace/series.rb', line 135 def batch_get(key) TASK_BATCH[key] end |
#build(parallel: [], pattern: []) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/squared/workspace/series.rb', line 101 def build(parallel: [], pattern: [], **) subcheck = ->(val) { (ns = @workspace.task_namespace(val)) && parallel.include?(ns) } @data.merge!(@session[:parent]) if @session[:id].uniq.size > 1 @data.merge!(@session[:group]) @data.each do |key, items| next if items.empty? key = @workspace.task_name(t = name_get(key)) val = @workspace.task_name(t, desc: true) if items.size > 1 @multiple << key if parallel.include?(t) || pattern.any? { |pat| pat.match?(t) } || subcheck.(t) desc "#{val} (thread)" multitask key => items @parallel << key s = @workspace.task_join(key, 'sync') desc "#{val} (sync)" task s => items @sync << s next end end desc val task key => items end @multiple += sync end |
#extend?(obj, key) ⇒ Boolean
156 157 158 |
# File 'lib/squared/workspace/series.rb', line 156 def extend?(obj, key) TASK_EXTEND.fetch(key, []).any? { |kind| obj.is_a?(kind) && obj.ref?(kind.ref) } end |
#multiple?(val = nil) ⇒ Boolean
160 161 162 |
# File 'lib/squared/workspace/series.rb', line 160 def multiple?(val = nil) already_invoked?(multiple, val) end |
#name_get(key) ⇒ Object
131 132 133 |
# File 'lib/squared/workspace/series.rb', line 131 def name_get(key) (TASK_NAME[key] || key).to_s end |
#parallel?(val = nil) ⇒ Boolean
168 169 170 |
# File 'lib/squared/workspace/series.rb', line 168 def parallel?(val = nil) already_invoked?(parallel, val) end |
#populate(proj) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/squared/workspace/series.rb', line 78 def populate(proj) group, parent, id = @session.values ws = proj.workspace @data.each do |key, items| next if (tasks = ws.task_resolve(proj, key)).empty? if (g = proj.group) id << g (group[:"#{key}:#{g}"] ||= []).concat(tasks) else items.concat(tasks) end if tasks.size > 1 && (data = batch_get(key)) && data.keys.any? { |ref| proj.ref?(ref) } desc ws.task_name(t = ws.task_join(proj.name, key), desc: true) task ws.task_name(t) => tasks end next unless (b = ws.find_base(proj)) && (n = b.ref.to_s) != g id << n (parent[:"#{key}:#{n}"] ||= []).concat(tasks) end end |
#some?(key) ⇒ Boolean
143 144 145 146 147 148 149 150 |
# File 'lib/squared/workspace/series.rb', line 143 def some?(key) return @data.key?(key) && !@data[key].empty? unless (batch = batch_get(key)) batch.each_value do |items| return true if items.all? { |val| some?(val) || alias_get(val)&.any? { |_, alt| some?(alt) } } end false end |
#sync?(val = nil) ⇒ Boolean
164 165 166 |
# File 'lib/squared/workspace/series.rb', line 164 def sync?(val = nil) already_invoked?(sync, val) end |