Class: Squared::Workspace::Application
- Inherits:
-
Object
- Object
- Squared::Workspace::Application
- Includes:
- Rake::DSL, Common::Format, Repo, Utils
- Defined in:
- lib/squared/workspace/application.rb
Constant Summary
Constants included from Common
Class Attribute Summary collapse
-
.attr_banner ⇒ Object
Returns the value of attribute attr_banner.
-
.impl_project ⇒ Object
Returns the value of attribute impl_project.
-
.impl_series ⇒ Object
Returns the value of attribute impl_series.
-
.kind_project ⇒ Object
readonly
Returns the value of attribute kind_project.
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#home ⇒ Object
readonly
Returns the value of attribute home.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#pipe ⇒ Object
readonly
Returns the value of attribute pipe.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#series ⇒ Object
readonly
Returns the value of attribute series.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
-
#warning ⇒ Object
readonly
Returns the value of attribute warning.
Attributes included from Repo
Class Method Summary collapse
- .baseref ⇒ Object
- .find(ref = nil, path: nil) ⇒ Object
- .implement(*objs, base: false) ⇒ Object
- .to_s ⇒ Object
Instance Method Summary collapse
- #add(path, project = nil, **kwargs, &blk) ⇒ Object
- #apply(&blk) ⇒ Object
- #banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) ⇒ Object
- #banner_get(*ref, group: nil) ⇒ Object
- #baseref ⇒ Object
- #build(parallel: [], **kwargs) {|_self| ... } ⇒ Object
- #clean(script, group: @group, ref: @ref) ⇒ Object
- #compose(name, &blk) ⇒ Object
- #depend(script, group: @group, ref: @ref) ⇒ Object
- #dev?(**kwargs) ⇒ Boolean
- #doc(script, group: @group, ref: @ref) ⇒ Object
- #enabled? ⇒ Boolean
- #exclude(base, group: @group, ref: @ref) ⇒ Object
- #find(path = nil, name: nil) {|ret| ... } ⇒ Object
- #find_base(obj) ⇒ Object
- #graph(script, group: @group, ref: @ref) ⇒ Object
- #group(path, val, override: {}, **kwargs, &blk) ⇒ Object
- #home? ⇒ Boolean
- #homepath(*args) ⇒ Object
-
#initialize(home = Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
constructor
A new instance of Application.
- #initialize_session ⇒ Object
- #inspect ⇒ Object
- #invokeargs ⇒ Object
- #jruby? ⇒ Boolean
- #jruby_win? ⇒ Boolean
- #log(script, group: @group, ref: @ref) ⇒ Object
- #prod?(**kwargs) ⇒ Boolean
- #pwd ⇒ Object
- #rootpath(*args) ⇒ Object
- #run(script, group: @group, ref: @ref) ⇒ Object
- #script_find(*args) ⇒ Object
- #script_get(*args, group: nil, ref: nil) ⇒ Object
- #style(obj, *args, target: nil, empty: false) ⇒ Object
- #task_base?(key) ⇒ Boolean
- #task_defined?(*key) ⇒ Boolean
- #task_extend?(obj, key) ⇒ Boolean
- #task_include?(obj, key, ref = nil) ⇒ Boolean
- #task_name(val, desc: false) ⇒ Object
- #task_namespace(val, first: false) ⇒ Object
- #task_resolve(obj, key) ⇒ Object
- #task_sync(key) ⇒ Object
- #test(script, group: @group, ref: @ref) ⇒ Object
- #to_s ⇒ Object
- #windows? ⇒ Boolean
- #with(*val, group: nil, **kwargs, &blk) ⇒ Object
Methods included from Repo
Methods included from Common::Format
Constructor Details
#initialize(home = Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
Returns a new instance of Application.
70 71 72 73 74 75 76 77 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 107 |
# File 'lib/squared/workspace/application.rb', line 70 def initialize(home = Dir.pwd, *, main: nil, prefix: nil, verbose: ARG[:VERBOSE], common: ARG[:COMMON], pipe: ARG[:PIPE], exception: ARG[:FAIL], **) @home = Pathname.new(home).realdirpath basename = @home.basename.to_s if main @main = main.to_s.freeze @home = @home.join(@main) unless @main == basename || (windows? && @main.downcase == basename.downcase) else @main = basename.freeze end @root = @home.parent @prefix = prefix @series = Application.impl_series.new(self) @project = {} @extensions = [] @pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home) @exception = env_bool(exception) @verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose) @warning = @verbose != false @closed = false if common @theme = __get__(:theme)[:workspace] ARG[:COLOR] = false if @pipe == 0 || @pipe.is_a?(Pathname) else @theme = {} end @script = { group: {}, ref: {}, group!: {}, ref!: {} }.freeze @banner = { group: {}, ref: {} }.freeze initialize_session end |
Class Attribute Details
.attr_banner ⇒ Object
Returns the value of attribute attr_banner.
63 64 65 |
# File 'lib/squared/workspace/application.rb', line 63 def @attr_banner end |
.impl_project ⇒ Object
Returns the value of attribute impl_project.
63 64 65 |
# File 'lib/squared/workspace/application.rb', line 63 def impl_project @impl_project end |
.impl_series ⇒ Object
Returns the value of attribute impl_series.
63 64 65 |
# File 'lib/squared/workspace/application.rb', line 63 def impl_series @impl_series end |
.kind_project ⇒ Object (readonly)
Returns the value of attribute kind_project.
62 63 64 |
# File 'lib/squared/workspace/application.rb', line 62 def kind_project @kind_project end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def closed @closed end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def exception @exception end |
#home ⇒ Object (readonly)
Returns the value of attribute home.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def home @home end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def main @main end |
#pipe ⇒ Object (readonly)
Returns the value of attribute pipe.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def pipe @pipe end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def prefix @prefix end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def root @root end |
#series ⇒ Object (readonly)
Returns the value of attribute series.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def series @series end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def theme @theme end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def verbose @verbose end |
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
68 69 70 |
# File 'lib/squared/workspace/application.rb', line 68 def warning @warning end |
Class Method Details
.baseref ⇒ Object
54 55 56 |
# File 'lib/squared/workspace/application.rb', line 54 def baseref impl_project.ref end |
.find(ref = nil, path: nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/squared/workspace/application.rb', line 46 def find(ref = nil, path: nil) if ref && (ret = kind_project.find { |proj| proj.ref == ref }) ret elsif path kind_project.find { |proj| proj.config?(path) } end end |
.implement(*objs, base: false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/squared/workspace/application.rb', line 21 def implement(*objs, base: false) return if base && objs.size > 1 objs.each do |obj| next unless base || obj < impl_project if base @impl_project = obj impl_series.base_set(obj) else kind_project.unshift(obj) obj.tasks&.each { |task| impl_series.add(task, obj) } end if (args = obj.batchargs) impl_series.batch(*args) end if (args = obj.aliasargs) impl_series.alias(*args) end if (args = obj.) @attr_banner += args end end end |
.to_s ⇒ Object
58 59 60 |
# File 'lib/squared/workspace/application.rb', line 58 def to_s super.match(/[^:]+\z/)[0] end |
Instance Method Details
#add(path, project = nil, **kwargs, &blk) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/squared/workspace/application.rb', line 240 def add(path, project = nil, **kwargs, &blk) if @withargs data = @withargs.dup data.merge!(kwargs) kwargs = data end ref = if kwargs.key?(:ref) kwargs = kwargs.dup unless @withargs kwargs.delete(:ref) elsif @ref.is_a?(Symbol) @ref end if @group.is_a?(String) && !kwargs.key?(:group) kwargs = kwargs.dup unless @withargs kwargs[:group] = @group end path = rootpath(path) project = (project || path.basename).to_s name = task_name(project) index = 0 while @project[name] index += 1 name = task_name "#{project}-#{index}" end proj = ((if !ref.is_a?(Class) Application.find(ref, path: path) elsif ref < Project::Base ref end) || Project::Base).new(self, path, name, **kwargs) @project[name] = proj __get__(:project)[name] = proj unless kwargs[:private] proj.instance_eval(&blk) if block_given? self end |
#apply(&blk) ⇒ Object
295 296 297 298 |
# File 'lib/squared/workspace/application.rb', line 295 def apply(&blk) instance_eval(&blk) self end |
#banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/squared/workspace/application.rb', line 201 def (*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) data = { command: command, order: [], styles: check_style(styles, empty: false), border: check_style(border) } args.each do |meth| if meth.is_a?(Array) found = false meth = meth.select do |val| case val when Symbol found = true Application..include?(val) when String true else false end end if !found next elsif meth.size == 1 meth = meth.first end elsif !Application..include?(meth = meth.to_sym) next end data[:order] << meth end unless !command && data[:order].empty? if group label = :group items = as_a(group) else label = :ref items = ref ? as_a(ref) : %i[_] end items.each { |val| @banner[label][val.to_sym] = data } end self end |
#banner_get(*ref, group: nil) ⇒ Object
413 414 415 416 417 418 419 |
# File 'lib/squared/workspace/application.rb', line 413 def (*ref, group: nil) ret = nil return ret if group && (ret = @banner[:group][group.to_sym]) ref.reverse_each { |val| return ret if (ret = @banner[:ref][val]) } @banner[:ref][:''] end |
#baseref ⇒ Object
477 478 479 |
# File 'lib/squared/workspace/application.rb', line 477 def baseref Application.baseref end |
#build(parallel: [], **kwargs) {|_self| ... } ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/squared/workspace/application.rb', line 117 def build(parallel: [], **kwargs) return self unless enabled? && !@closed if kwargs[:pattern].is_a?(Array) kwargs[:parallel] = parallel.map(&:to_s) else kwargs[:pattern] = [] kwargs[:parallel] = parallel.reject { |val| val.is_a?(Regexp) && (kwargs[:pattern] << val) } .map(&:to_s) end @project.each_value do |proj| next unless proj.enabled? proj.populate(**kwargs) series.populate(proj) end Application.kind_project.each { |obj| obj.populate(self, **kwargs) } @extensions.each { |ext| __send__(ext, **kwargs) } series.build(**kwargs) __build__(**kwargs) yield self if block_given? @closed = true self end |
#clean(script, group: @group, ref: @ref) ⇒ Object
181 182 183 |
# File 'lib/squared/workspace/application.rb', line 181 def clean(script, group: @group, ref: @ref) script_command :clean, script, group, ref end |
#compose(name, &blk) ⇒ Object
290 291 292 293 |
# File 'lib/squared/workspace/application.rb', line 290 def compose(name, &blk) namespace(task_name(name), &blk) if block_given? self end |
#depend(script, group: @group, ref: @ref) ⇒ Object
173 174 175 |
# File 'lib/squared/workspace/application.rb', line 173 def depend(script, group: @group, ref: @ref) script_command :depend, script, group, ref end |
#dev?(**kwargs) ⇒ Boolean
441 442 443 |
# File 'lib/squared/workspace/application.rb', line 441 def dev?(**kwargs) script?(:dev, **kwargs) end |
#doc(script, group: @group, ref: @ref) ⇒ Object
185 186 187 |
# File 'lib/squared/workspace/application.rb', line 185 def doc(script, group: @group, ref: @ref) script_command :doc, script, group, ref end |
#enabled? ⇒ Boolean
421 422 423 |
# File 'lib/squared/workspace/application.rb', line 421 def enabled? !@extensions.empty? || @project.values.any?(&:enabled?) end |
#exclude(base, group: @group, ref: @ref) ⇒ Object
197 198 199 |
# File 'lib/squared/workspace/application.rb', line 197 def exclude(base, group: @group, ref: @ref) script_command :exclude, as_a(base, :to_sym).freeze, group, ref end |
#find(path = nil, name: nil) {|ret| ... } ⇒ Object
315 316 317 318 319 320 321 322 323 |
# File 'lib/squared/workspace/application.rb', line 315 def find(path = nil, name: nil) path &&= rootpath(path) name &&= name.to_s ret = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last return ret unless block_given? yield ret if ret self end |
#find_base(obj) ⇒ Object
325 326 327 |
# File 'lib/squared/workspace/application.rb', line 325 def find_base(obj) Application.kind_project.find { |proj| obj.instance_of?(proj) } end |
#graph(script, group: @group, ref: @ref) ⇒ Object
177 178 179 |
# File 'lib/squared/workspace/application.rb', line 177 def graph(script, group: @group, ref: @ref) script_command :graph, as_a(script, :to_s).freeze, group, ref end |
#group(path, val, override: {}, **kwargs, &blk) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/squared/workspace/application.rb', line 275 def group(path, val, override: {}, **kwargs, &blk) rootpath(path).children.map do |dir| next unless dir.directory? basename = dir.basename.to_s [dir, basename, override[basename.to_sym]] end .each do |dir, basename, opts| args = kwargs.dup args.merge!(opts) if opts add(dir, basename, group: val, **args, &blk) end self end |
#home? ⇒ Boolean
449 450 451 |
# File 'lib/squared/workspace/application.rb', line 449 def home? !(proj = find(home)).nil? && proj.enabled? end |
#homepath(*args) ⇒ Object
469 470 471 |
# File 'lib/squared/workspace/application.rb', line 469 def homepath(*args) home.join(*args) end |
#initialize_session ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/squared/workspace/application.rb', line 109 def initialize_session @envname = @main.gsub(/[^\w]+/, '_').upcase.freeze return unless @pipe.is_a?(Pathname) bord = '#' * Project.line_width puts bord, format('Session started on %s by %s', Time.now.to_s, @main), bord end |
#inspect ⇒ Object
489 490 491 |
# File 'lib/squared/workspace/application.rb', line 489 def inspect "#<#{self.class}: #{main} => #{self}>" end |
#invokeargs ⇒ Object
481 482 483 |
# File 'lib/squared/workspace/application.rb', line 481 def invokeargs { exception: exception, warning: warning } end |
#jruby? ⇒ Boolean
457 458 459 |
# File 'lib/squared/workspace/application.rb', line 457 def jruby? RUBY_ENGINE == 'jruby' end |
#jruby_win? ⇒ Boolean
461 462 463 |
# File 'lib/squared/workspace/application.rb', line 461 def jruby_win? jruby? && windows? end |
#log(script, group: @group, ref: @ref) ⇒ Object
193 194 195 |
# File 'lib/squared/workspace/application.rb', line 193 def log(script, group: @group, ref: @ref) script_command :log, script, group, ref end |
#prod?(**kwargs) ⇒ Boolean
445 446 447 |
# File 'lib/squared/workspace/application.rb', line 445 def prod?(**kwargs) script?(:prod, **kwargs) end |
#pwd ⇒ Object
473 474 475 |
# File 'lib/squared/workspace/application.rb', line 473 def pwd Pathname.new(Rake.application.original_dir) end |
#rootpath(*args) ⇒ Object
465 466 467 |
# File 'lib/squared/workspace/application.rb', line 465 def rootpath(*args) root.join(*args) end |
#run(script, group: @group, ref: @ref) ⇒ Object
169 170 171 |
# File 'lib/squared/workspace/application.rb', line 169 def run(script, group: @group, ref: @ref) script_command :run, script, group, ref end |
#script_find(*args) ⇒ Object
386 387 388 389 390 391 392 393 |
# File 'lib/squared/workspace/application.rb', line 386 def script_find(*args) args.reverse_each do |val| next unless val && (ret = val.is_a?(Symbol) ? @script[:ref!][val] : @script[:group!][val.to_sym]) return ret end @script[:ref!][:''] || SCRIPT_OBJ end |
#script_get(*args, group: nil, ref: nil) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/squared/workspace/application.rb', line 395 def script_get(*args, group: nil, ref: nil) if group @script[:group][group.to_sym] elsif ref.is_a?(Array) ref = ref.each end if ref.instance_of?(Enumerator) ref.each do |key| next unless (ret = @script[:ref][key]) return ret if args.empty? || args.any? { |val| ret.key?(val) } end nil elsif ref @script[:ref][ref] end end |
#style(obj, *args, target: nil, empty: false) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/squared/workspace/application.rb', line 300 def style(obj, *args, target: nil, empty: false) data = nil if target as_a(target).each_with_index do |key, i| if i == 0 break unless (data = __get__(:theme)[key.to_sym]) else data = data[key.to_sym] ||= {} end end end apply_style(data || theme, obj, args, empty: empty) unless target && !data self end |
#task_base?(key) ⇒ Boolean
425 426 427 |
# File 'lib/squared/workspace/application.rb', line 425 def task_base?(key) series.base?(key) end |
#task_defined?(*key) ⇒ Boolean
437 438 439 |
# File 'lib/squared/workspace/application.rb', line 437 def task_defined?(*key) Rake::Task.task_defined?(key.size == 1 ? key.first : task_join(*key)) end |
#task_extend?(obj, key) ⇒ Boolean
429 430 431 |
# File 'lib/squared/workspace/application.rb', line 429 def task_extend?(obj, key) series.extend?(obj, key) end |
#task_include?(obj, key, ref = nil) ⇒ Boolean
433 434 435 |
# File 'lib/squared/workspace/application.rb', line 433 def task_include?(obj, key, ref = nil) task_base?(key) ? obj.has?(key, ref || baseref) : task_extend?(obj, key) end |
#task_name(val, desc: false) ⇒ Object
329 330 331 332 |
# File 'lib/squared/workspace/application.rb', line 329 def task_name(val, desc: false) ret = @prefix ? task_join(@prefix, val) : val.to_s desc ? (*ret.split(':')) : ret end |
#task_namespace(val, first: false) ⇒ Object
334 335 336 337 338 |
# File 'lib/squared/workspace/application.rb', line 334 def task_namespace(val, first: false) return nil unless (ret = val.to_s.split(':')).size > 1 first ? ret.first : task_join(*ret[0..-2]) end |
#task_resolve(obj, key) ⇒ Object
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/squared/workspace/application.rb', line 340 def task_resolve(obj, key) tasks = [] if (base = task_base?(key)) tasks << key if obj.has?(key, baseref) elsif (batch = series.batch_get(key)) obj.allref.each do |ref| next unless obj.has?(key, ref) && (data = batch[ref]) data.each do |val| if (items = task_resolve(obj, val)).empty? tasks.clear break end tasks += items end return tasks unless tasks.empty? end elsif task_extend?(obj, key) tasks << key end ret = [] if tasks.empty? return [] if (base && !obj.ref?(baseref)) || !(data = series.alias_get(key)) obj.allref.each do |ref| next unless obj.has?(key, ref) && (alt = data[ref]) ret = task_resolve(obj, alt) break unless ret.empty? end else tasks.each do |val| target = task_join(obj.name, series.name_get(val)) return [] unless task_defined?(target) ret << target end end ret end |
#task_sync(key) ⇒ Object
381 382 383 384 |
# File 'lib/squared/workspace/application.rb', line 381 def task_sync(key) key = task_name(key) task_defined?(ret = task_join(key, 'sync')) ? ret : key end |
#test(script, group: @group, ref: @ref) ⇒ Object
189 190 191 |
# File 'lib/squared/workspace/application.rb', line 189 def test(script, group: @group, ref: @ref) script_command :test, script, group, ref end |
#to_s ⇒ Object
485 486 487 |
# File 'lib/squared/workspace/application.rb', line 485 def to_s (home? ? home : root).to_s end |
#windows? ⇒ Boolean
453 454 455 |
# File 'lib/squared/workspace/application.rb', line 453 def windows? Rake::Win32.windows? end |
#with(*val, group: nil, **kwargs, &blk) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/squared/workspace/application.rb', line 145 def with(*val, group: nil, **kwargs, &blk) @group = nil @ref = nil @withargs = kwargs.empty? ? nil : kwargs val = as_a(group || kwargs[:ref], flat: true, compact: true) if val.empty? kind = val.first val = kind if val.size == 1 case kind when String @group = val when Symbol @ref = val else raise_error('group{Symbol} | ref{String}', hint: 'missing') if block_given? end if block_given? instance_eval(&blk) @group = nil @ref = nil @withargs = nil end self end |