Class: Squared::Workspace::Series
- Inherits:
-
Object
- Object
- Squared::Workspace::Series
- Extended by:
- Forwardable
- Includes:
- Rake::DSL
- Defined in:
- lib/squared/workspace/series.rb
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.
Instance Method Summary collapse
- #alias_get(key) ⇒ Object
- #base?(key) ⇒ Boolean
- #batch?(obj, key) ⇒ Boolean
- #batch_get(key) ⇒ Object
- #build(parallel: [], pattern: []) ⇒ Object
- #chain(key, level, sync: []) ⇒ Object
- #chain?(val) ⇒ Boolean
- #exclude?(key, empty = false) ⇒ Boolean
- #extend?(obj, key) ⇒ Boolean
-
#initialize(workspace, project, exclude: []) ⇒ Series
constructor
A new instance of Series.
- #missing?(obj, key) ⇒ Boolean
- #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, project, exclude: []) ⇒ Series
Returns a new instance of Series.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/squared/workspace/series.rb', line 17 def initialize(workspace, project, exclude: []) @workspace = workspace @sync = [] @multiple = [] @parallel = [] @chain = {} @exclude = exclude.freeze @task = Struct::SeriesData.new(workspace.config_get(:rename)) @data = {} project.each_with_index do |obj, index| if index == 0 target = @task.base obj.tasks.each do |key| target << key @data[key] = [] end else target = @task.project obj.tasks&.each do |key| task_set key target[key] << obj end end if (args = obj.batchargs) batch_set(*args) end if (args = obj.aliasargs) alias_set(*args) end end workspace.config_get(:batch)&.each { |args| batch_set(*args) } @session = { group: Support.hashlist, parent: Support.hashlist, id: [] }.freeze end |
Instance Attribute Details
#multiple ⇒ Object (readonly)
Returns the value of attribute multiple.
11 12 13 |
# File 'lib/squared/workspace/series.rb', line 11 def multiple @multiple end |
#parallel ⇒ Object (readonly)
Returns the value of attribute parallel.
11 12 13 |
# File 'lib/squared/workspace/series.rb', line 11 def parallel @parallel end |
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
11 12 13 |
# File 'lib/squared/workspace/series.rb', line 11 def sync @sync end |
Instance Method Details
#alias_get(key) ⇒ Object
140 141 142 143 144 |
# File 'lib/squared/workspace/series.rb', line 140 def alias_get(key) return unless @task.alias.key?(key) @task.alias[key] end |
#base?(key) ⇒ Boolean
155 156 157 |
# File 'lib/squared/workspace/series.rb', line 155 def base?(key) @task.base.include?(key) end |
#batch?(obj, key) ⇒ Boolean
178 179 180 181 182 |
# File 'lib/squared/workspace/series.rb', line 178 def batch?(obj, key) return false unless (data = batch_get(key)) data.keys.any? { |ref| obj.ref?(ref) } end |
#batch_get(key) ⇒ Object
134 135 136 137 138 |
# File 'lib/squared/workspace/series.rb', line 134 def batch_get(key) return unless @task.batch.key?(key) @task.batch[key] end |
#build(parallel: [], pattern: []) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/squared/workspace/series.rb', line 78 def build(parallel: [], pattern: [], **) subcheck = ->(val) { (ns = task_namespace(val)) && parallel.include?(ns) } update @session[:parent] if @session[:id].uniq.size > 1 update @session[:group] each do |key, items| next if exclude?(key, true) || @workspace.task_exclude?(t = name_get(key)) key = task_name t title = format_desc(key, out: true) if items.size > 1 @multiple << key if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.call(t) task_desc("#{title} (thread)", name: key) if title multitask key => items @parallel << key s = task_join key, 'sync' task_desc("#{title} (sync)", name: s) if title task s => items @sync << s next end end task_desc(title, name: key) if title task key => items end @multiple.concat(sync) end |
#chain(key, level, sync: []) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/squared/workspace/series.rb', line 108 def chain(key, level, sync: []) return if level.empty? index = 0 prereqs = level.map do |tasks| name = task_join(key, index += 1) if sync.include?(tasks) || (tasks.size == 1 && (sync << tasks)) task name => tasks else multitask name => tasks end name end @chain[key] = level.freeze parallel << key format_desc key, level.map(&:size).join('-') task key => prereqs end |
#chain?(val) ⇒ Boolean
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/squared/workspace/series.rb', line 189 def chain?(val) @chain.each_value do |tasks| tasks.flatten(1).each do |name| next unless (task = invoked_get(name)) return true if name == val || task.prerequisites.any? { |pr| pr == val && Rake::Task[pr].already_invoked } end end false end |
#exclude?(key, empty = false) ⇒ Boolean
212 213 214 |
# File 'lib/squared/workspace/series.rb', line 212 def exclude?(key, empty = false) @exclude.include?(key) || (empty && (!key?(key) || self[key].empty?)) end |
#extend?(obj, key) ⇒ Boolean
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/squared/workspace/series.rb', line 159 def extend?(obj, key) return false unless @task.project.key?(key) ret = false @task.project[key].each do |kind| next unless obj.is_a?(kind) meth = :"#{key}?" if kind.method_defined?(meth) out = obj.__send__(meth) return true if out == 1 return out if obj.ref?(kind.ref) elsif obj.ref?(kind.ref) ret = true end end ret end |
#missing?(obj, key) ⇒ Boolean
184 185 186 187 |
# File 'lib/squared/workspace/series.rb', line 184 def missing?(obj, key) obj = obj.ref unless obj.is_a?(Symbol) @task.missing.key?(obj) && @task.missing.include?(key) end |
#multiple?(val = nil) ⇒ Boolean
200 201 202 |
# File 'lib/squared/workspace/series.rb', line 200 def multiple?(val = nil) already_invoked? multiple, val end |
#name_get(key) ⇒ Object
128 129 130 131 132 |
# File 'lib/squared/workspace/series.rb', line 128 def name_get(key) return key.to_s unless @task.rename&.key?(key) @task.rename[key] end |
#parallel?(val = nil) ⇒ Boolean
208 209 210 |
# File 'lib/squared/workspace/series.rb', line 208 def parallel?(val = nil) already_invoked? parallel, val end |
#populate(proj) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/squared/workspace/series.rb', line 55 def populate(proj, **) group, parent, id = @session.values ws = proj.workspace each do |key, items| next if exclude?(key) || (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 && batch?(proj, key) && !ws.task_exclude?(key, proj) ws.task_desc(t = ws.task_join(proj.name, key)) task 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
146 147 148 149 150 151 152 153 |
# File 'lib/squared/workspace/series.rb', line 146 def some?(key) return key?(key) && !self[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
204 205 206 |
# File 'lib/squared/workspace/series.rb', line 204 def sync?(val = nil) already_invoked? sync, val end |