Class: Squared::Workspace::Application
- Inherits:
-
Object
- Object
- Squared::Workspace::Application
show all
- Includes:
- Enumerable, Rake::DSL, Common::Format, Git, Repo, Utils
- Defined in:
- lib/squared/workspace/application.rb
Constant Summary
Constants included
from Common
Common::ARG, Common::PATH
Class Attribute Summary collapse
Instance Attribute Summary collapse
Attributes included from Git
#revfile
Class Method Summary
collapse
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
-
#batch(*args) ⇒ Object
-
#build(parallel: [], **kwargs) ⇒ Object
-
#chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false, group: @group, ref: @ref) ⇒ Object
-
#clean(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#compose(name, &blk) ⇒ Object
-
#config_get(key, default = nil, &blk) ⇒ Object
-
#depend(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#describe(data) ⇒ Object
-
#dev?(**kwargs) ⇒ Boolean
-
#doc(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#docker? ⇒ Boolean
-
#each(&blk) ⇒ Object
-
#enabled? ⇒ Boolean
-
#events_get(*args, group: nil, ref: nil) ⇒ Object
-
#exclude(base, group: @group, ref: @ref) ⇒ Object
-
#find(path = nil, name: nil, group: nil, ref: nil, &blk) ⇒ Object
-
#find_base(obj) ⇒ Object
-
#format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false) ⇒ Object
-
#get(name, &blk) ⇒ Object
-
#graph(script, group: @group, ref: @ref, on: nil) ⇒ Object
-
#group(path, val, override: {}, **kwargs, &blk) ⇒ Object
-
#home? ⇒ Boolean
-
#homepath(*args) ⇒ Object
-
#initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
constructor
A new instance of Application.
-
#inspect ⇒ Object
-
#invokeargs ⇒ Object
-
#join(task, *cmd, invoke: nil, args: [], group: @group, ref: @ref, **kwargs, &blk) ⇒ Object
-
#lint(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#log(script, group: @group, ref: @ref) ⇒ Object
-
#mri? ⇒ Boolean
-
#pass(name, group: @group, ref: @ref, &blk) ⇒ Object
-
#powershell? ⇒ Boolean
-
#prod?(**kwargs) ⇒ Boolean
-
#pwd ⇒ Object
-
#rename(task, val) ⇒ Object
-
#rootpath(*args) ⇒ Object
-
#run(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#script(script, group: @group, ref: @ref, on: nil) ⇒ Object
-
#script_find(*args, name: nil) ⇒ Object
-
#script_get(*args, group: nil, ref: nil) ⇒ Object
-
#size ⇒ Object
-
#stage(val, first: false, &blk) ⇒ Object
-
#style(obj, *args, target: nil, empty: false) ⇒ Object
-
#task_base?(key) ⇒ Boolean
-
#task_defined?(*key) ⇒ Boolean
-
#task_desc(*args, **kwargs) ⇒ Object
-
#task_exclude?(key, obj = nil) ⇒ Boolean
-
#task_extend?(obj, key) ⇒ Boolean
-
#task_include?(obj, key, ref: nil) ⇒ Boolean
-
#task_localname(val) ⇒ Object
-
#task_name(val) ⇒ Object
-
#task_namespace(val, first: false) ⇒ Object
-
#task_resolve(obj, key) ⇒ Object
-
#task_sync(key) ⇒ Object
-
#test(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
-
#timeout(data, group: @group, ref: @ref) ⇒ Object
-
#timeout_get(*ref, group: nil) ⇒ Object
-
#to_s ⇒ Object
-
#windows? ⇒ Boolean
-
#with(*val, hide: false, group: nil, **kwargs, &blk) ⇒ Object
Methods included from Repo
#repo, #repo?
Methods included from Git
#git, #git_clone?, #git_repo, #rev_clear, #rev_entry, #rev_timesince, #rev_timeutc, #rev_write, #revbuild
emphasize, #enable_aixterm, #enable_drawing, message
Constructor Details
#initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, main: nil, prefix: nil, verbose: , common: , pipe: , exception: ) ⇒ Application
Returns a new instance of Application.
96
97
98
99
100
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/squared/workspace/application.rb', line 96
def initialize(home = (ARG[:HOME] && ENV[ARG[:HOME]]) || Dir.pwd, *, main: nil, prefix: nil,
verbose: ARG[:VERBOSE], common: ARG[:COMMON], pipe: ARG[:PIPE], exception: ARG[:FAIL], **)
home = Pathname.new(home)
basename = home.basename.to_s
if main
@main = main.to_s.freeze
home += @main unless @main == basename || (windows? && @main.casecmp?(basename))
else
@main = basename.freeze
end
@prefix = prefix
@project = {}
@base = Set.new
@kind = Support.hashlist
@config = {}
@extensions = Set.new
@finalize = Set.new(%i[__chain__ __join__])
@envname = env_key(@main).freeze
@closed = false
@stage = Support.hashlist
self.home = home
self.exception = env_bool exception
self.pipe = if $DEBUG
2
elsif (out = ARG[:OUT]) && out.include?(File::SEPARATOR)
env_pipe(out, pipe, root: home)
else
env_pipe(pipe, (out && env(out)) || 1, root: home)
end
self.verbose = if $VERBOSE.nil?
false
elsif verbose.nil?
@pipe != 0
else
env_bool(verbose, verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
end
self.warning = @verbose != false
@theme = common ? __get__(:theme)[:workspace] : {}
@chain = Support.hashlist
@script = Struct::SessionData.new
@join = Struct::SessionData.new
@events = Struct::SessionData.new
@pass = Struct::SessionData.new
@banner = Struct::SessionData.new
@timeout = Struct::SessionData.new
@global = Hash.new do |data, key|
data[key] = { group: {}, ref: {}, exclude: [], extras: {}, module: nil, script: nil }
end
initialize_session
end
|
Class Attribute Details
.attr_banner ⇒ Object
Returns the value of attribute attr_banner.
83
84
85
|
# File 'lib/squared/workspace/application.rb', line 83
def attr_banner
@attr_banner
end
|
.impl_series ⇒ Object
Returns the value of attribute impl_series.
84
85
86
|
# File 'lib/squared/workspace/application.rb', line 84
def impl_series
@impl_series
end
|
.kind_project ⇒ Object
Returns the value of attribute kind_project.
83
84
85
|
# File 'lib/squared/workspace/application.rb', line 83
def kind_project
@kind_project
end
|
.load_project ⇒ Object
Returns the value of attribute load_project.
83
84
85
|
# File 'lib/squared/workspace/application.rb', line 83
def load_project
@load_project
end
|
.session ⇒ Object
Returns the value of attribute session.
83
84
85
|
# File 'lib/squared/workspace/application.rb', line 83
def session
@session
end
|
Instance Attribute Details
#closed ⇒ Object
Returns the value of attribute closed.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def closed
@closed
end
|
#exception ⇒ Object
Returns the value of attribute exception.
94
95
96
|
# File 'lib/squared/workspace/application.rb', line 94
def exception
@exception
end
|
#home ⇒ Object
Returns the value of attribute home.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def home
@home
end
|
#main ⇒ Object
Returns the value of attribute main.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def main
@main
end
|
#pipe ⇒ Object
Returns the value of attribute pipe.
94
95
96
|
# File 'lib/squared/workspace/application.rb', line 94
def pipe
@pipe
end
|
#prefix ⇒ Object
Returns the value of attribute prefix.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def prefix
@prefix
end
|
#root ⇒ Object
Returns the value of attribute root.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def root
@root
end
|
#series ⇒ Object
Returns the value of attribute series.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def series
@series
end
|
#theme ⇒ Object
Returns the value of attribute theme.
93
94
95
|
# File 'lib/squared/workspace/application.rb', line 93
def theme
@theme
end
|
#verbose ⇒ Object
Returns the value of attribute verbose.
94
95
96
|
# File 'lib/squared/workspace/application.rb', line 94
def verbose
@verbose
end
|
#warning ⇒ Object
Returns the value of attribute warning.
94
95
96
|
# File 'lib/squared/workspace/application.rb', line 94
def warning
@warning
end
|
Class Method Details
.baseref ⇒ Object
75
76
77
|
# File 'lib/squared/workspace/application.rb', line 75
def baseref
impl_project.ref
end
|
.extends(obj) ⇒ Object
67
68
69
|
# File 'lib/squared/workspace/application.rb', line 67
def extends(obj)
@kind_extend.any? { |impl| obj < impl }
end
|
.find(ref: nil, path: nil) ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/squared/workspace/application.rb', line 32
def find(ref: nil, path: nil)
if ref && (ret = kind_project.find { |proj| proj.ref == ref })
ret
elsif path
(kind_project - @kind_extend).find { |proj| proj.config?(path) } ||
@kind_extend.find { |proj| proj.config?(path) }
end
end
|
.impl_project ⇒ Object
71
72
73
|
# File 'lib/squared/workspace/application.rb', line 71
def impl_project
@kind_extend.first
end
|
.implement(*objs, base: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/squared/workspace/application.rb', line 15
def implement(*objs, base: nil)
objs.each_with_index do |obj, index|
if base && index == 0
case base
when 0, true
@kind_extend[0] = obj
next
when 1
@kind_extend.insert(1, obj)
else
@kind_extend.push(obj)
end
end
kind_project.unshift(obj) if extends(obj)
end
end
|
.load_ref(path, gem: nil) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/squared/workspace/application.rb', line 46
def load_ref(path, gem: nil)
if gem
unless @gemsdir
IO.popen('bundle env').each do |val|
next unless val =~ /^\s+Gem Home\s+(.+)$/
@gemsdir = File.join($1, 'gems')
break
end
end
dir = if gem.match?(/-\d+(\.|$)/)
gem
else
Dir.glob("#{gem}-*", base: @gemsdir).pop
end
path = File.join(@gemsdir, dir, path) if dir
end
path = Pathname.new(path)
@load_project.unshift(path.cleanpath.to_s) if path.absolute? && path.exist?
end
|
.register(app, base, exclude: []) ⇒ Object
41
42
43
44
|
# File 'lib/squared/workspace/application.rb', line 41
def register(app, base, exclude: [])
@session << app
impl_series.new(app, (@kind_extend + base).uniq, exclude: exclude.map(&:to_sym))
end
|
.to_s ⇒ Object
79
80
81
|
# File 'lib/squared/workspace/application.rb', line 79
def to_s
super[/[^:]+\z/, 0]
end
|
Instance Method Details
#add(path, project = nil, **kwargs, &blk) ⇒ Object
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'lib/squared/workspace/application.rb', line 391
def add(path, project = nil, **kwargs, &blk)
kwargs = Support.hashdup(@withargs).update(kwargs) if @withargs
ref = kwargs.key?(:ref) ? kwargs.delete(:ref) : @ref
kwargs[:group] = @group if @group && !kwargs.key?(:group)
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
unless ref.is_a?(Symbol) && (proj = @base.find { |item| item.ref == ref })
proj = if !ref.is_a?(Class)
require_project(ref) || Application.find(ref: ref, path: path)
elsif Application.extends(ref)
ref
end || @kind[name]&.last
if proj
@base << proj
@banner.items.concat(Array(proj.bannerargs))
else
proj = Application.impl_project
end
end
proj = proj.new(self, path, name, **kwargs)
proj.__send__(:index_set, size)
@project[name] = proj
__get__(:project)[name] = proj unless kwargs[:private]
proj.instance_eval(&blk) if block_given?
self
end
|
#apply(&blk) ⇒ Object
444
445
446
447
|
# File 'lib/squared/workspace/application.rb', line 444
def apply(&blk)
instance_eval(&blk)
self
end
|
#banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref) ⇒ Object
334
335
336
337
338
339
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
|
# File 'lib/squared/workspace/application.rb', line 334
def banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref)
data = Struct::BannerData.new(command, check_style(styles, empty: false), 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
banner_include?(val)
when String
true
else
false
end
end
if !found
next
elsif meth.size == 1
meth = meth.first
end
elsif !banner_include?(meth = meth.to_sym)
next
end
data.order << meth
end
Array(if group
label = :group
group
else
label = :ref
ref || :_
end).each { |val| @banner[label][val.to_sym] = data }
self
end
|
#banner_get(*ref, group: nil) ⇒ Object
678
679
680
681
682
683
684
685
|
# File 'lib/squared/workspace/application.rb', line 678
def banner_get(*ref, group: nil)
if group && @banner.group.key?(group = group.to_sym)
@banner.group[group]
else
ref.reverse_each { |val| return @banner.ref[val] if @banner.ref.key?(val) }
@banner.ref[:_] if @banner.ref.key?(:_)
end
end
|
#baseref ⇒ Object
779
780
781
|
# File 'lib/squared/workspace/application.rb', line 779
def baseref
Application.baseref
end
|
#batch(*args) ⇒ Object
381
382
383
384
|
# File 'lib/squared/workspace/application.rb', line 381
def batch(*args)
(@config[:batch] ||= []) << args
self
end
|
#build(parallel: [], **kwargs) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/squared/workspace/application.rb', line 153
def build(parallel: [], **kwargs)
return self unless enabled? && !@closed
self.closed = 'init'
kwargs[:parallel] = if kwargs[:pattern].is_a?(Array)
parallel.map(&:to_s)
else
kwargs[:pattern] = []
parallel.reject { |val| kwargs[:pattern] << val if val.is_a?(Regexp) }.map(&:to_s)
end
@pass.items.concat(kwargs[:pass].map { |val| val.is_a?(Regexp) ? val : val.to_s }) if kwargs[:pass]
@series = Application.register(self, @base.to_a, exclude: kwargs.fetch(:exclude, []))
self.closed = 'begin'
pb = @stage.key?('project:begin')
pe = @stage.key?('project:end')
keys = @series.keys
each do |proj|
self.closed = ['project:begin', proj] if pb
if proj.enabled?
proj.populate(keys.dup, **kwargs)
elsif proj.enabled?(base: false)
proj.generate([], **kwargs)
else
next
end
@series.populate(proj, **kwargs)
self.closed = ['project:end', proj] if pe
end
self.closed = 'populate'
@base.each { |obj| obj.populate(self, **kwargs) }
self.closed = 'extensions'
@extensions.each { |ext| __send__(ext, **kwargs) }
self.closed = 'series'
@series.build(**kwargs)
__build__(**kwargs)
if block_given?
self.closed = 'yield:begin'
yield self
self.closed = 'yield:end'
end
self.closed = 'finalize'
@finalize.each { |ext| __send__(ext, **kwargs) }
self.closed = 'end'
@closed = true
self
end
|
#chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false, group: @group, ref: @ref) ⇒ Object
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/squared/workspace/application.rb', line 260
def chain(task, *action, project: nil, step: 0, with: nil, before: nil, after: nil, sync: false,
group: @group, ref: @ref)
tasks = if project
action.map { |val| task_join(project.name, val) }
elsif (target = group || ref)
action.map { |val| task_name(task_join(val, target)) }
else
keys = @project.keys unless prefix
action.map { |val| task_name(val) }
end
ns = lambda do |val|
return if (ret = as_a(val, :to_s, flat: true)).empty?
ret.map do |arg|
if arg.include?(':') || (keys && !keys.include?(arg))
task_name(arg)
else
/#{Regexp.escape(arg)}:/
end
end
end
data = Struct::ChainData.new(tasks, step, ns.call(with), ns.call(before), ns.call(after), sync)
@chain[task_name(task.to_s)] << data
self
end
|
#clean(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
298
299
300
|
# File 'lib/squared/workspace/application.rb', line 298
def clean(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :clean, script, group, ref, on, &blk
end
|
#compose(name, &blk) ⇒ Object
439
440
441
442
|
# File 'lib/squared/workspace/application.rb', line 439
def compose(name, &blk)
namespace(task_name(name), &blk)
self
end
|
#config_get(key, default = nil, &blk) ⇒ Object
694
695
696
|
# File 'lib/squared/workspace/application.rb', line 694
def config_get(key, default = nil, &blk)
@config.fetch(key, block_given? ? blk : default)
end
|
#depend(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
290
291
292
|
# File 'lib/squared/workspace/application.rb', line 290
def depend(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :depend, script, group, ref, on, &blk
end
|
#describe(data) ⇒ Object
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
# File 'lib/squared/workspace/application.rb', line 483
def describe(data)
@describe ||= {
alias: {},
replace: [],
pattern: {}
}
data.each do |key, val|
key = key.to_s
if key.start_with?('\A', '^') || key.end_with?('\z', '$')
@describe[:replace] << [Regexp.new(key), val]
else
@describe[val.is_a?(Regexp) ? :pattern : :alias][key] = val
end
end
self
end
|
#dev?(**kwargs) ⇒ Boolean
731
732
733
|
# File 'lib/squared/workspace/application.rb', line 731
def dev?(**kwargs)
script?(:dev, **kwargs)
end
|
#doc(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
302
303
304
|
# File 'lib/squared/workspace/application.rb', line 302
def doc(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :doc, script, group, ref, on, &blk
end
|
#docker? ⇒ Boolean
751
752
753
|
# File 'lib/squared/workspace/application.rb', line 751
def docker?
!Dir['/.dockerenv', '/docker-*.{sh,d}'].empty?
end
|
#each(&blk) ⇒ Object
147
148
149
150
151
|
# File 'lib/squared/workspace/application.rb', line 147
def each(&blk)
return to_enum(:each) unless block_given?
@project.each_value(&blk)
end
|
#enabled? ⇒ Boolean
698
699
700
|
# File 'lib/squared/workspace/application.rb', line 698
def enabled?
!@extensions.empty? || any? { |proj| proj.enabled?(base: false) }
end
|
#events_get(*args, group: nil, ref: nil) ⇒ Object
674
675
676
|
# File 'lib/squared/workspace/application.rb', line 674
def events_get(*args, group: nil, ref: nil)
data_get(*args, target: @events, group: group, ref: ref)
end
|
#exclude(base, group: @group, ref: @ref) ⇒ Object
318
319
320
|
# File 'lib/squared/workspace/application.rb', line 318
def exclude(base, group: @group, ref: @ref)
script_command :exclude, as_a(base, :to_sym).freeze, group, ref
end
|
#find(path = nil, name: nil, group: nil, ref: nil, &blk) ⇒ Object
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
# File 'lib/squared/workspace/application.rb', line 500
def find(path = nil, name: nil, group: nil, ref: nil, &blk)
return @project.values.find(&blk) if block_given? && !path && !name && !group && !ref
ret = group ? select { |item| item.group == group } : []
if path.is_a?(Symbol)
ref ||= path
path = nil
end
if ret.empty?
ret = select { |item| item.ref?(ref) } if ref
if ret.empty? && (path || name)
path &&= rootpath path
name &&= name.to_s
if (proj = find { |item| item.path == path || item.name == name })
ret << proj
end
end
end
return (group || ref ? ret : ret.first) unless block_given?
ret.each(&blk)
self
end
|
#find_base(obj) ⇒ Object
532
533
534
|
# File 'lib/squared/workspace/application.rb', line 532
def find_base(obj)
@base.find { |proj| obj.instance_of?(proj) }
end
|
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
|
# File 'lib/squared/workspace/application.rb', line 631
def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false)
return unless TASK_METADATA
val = val.split(':') if val.is_a?(String)
if before || after || opts
pos = []
pos << (before.is_a?(Array) ? before.join(',') : before) if before
if opts
pos << if opts.is_a?(Array)
arg ? "#{arg}=#{opts.join(',')}" : opts.join('|')
else
opts
end
end
pos << (after.is_a?(Array) ? after.join(',') : after) if after
val << "#{val.pop}[#{pos.join(',')}]"
end
out ? message(*val) : task_desc(*val)
end
|
#get(name, &blk) ⇒ Object
524
525
526
527
528
529
530
|
# File 'lib/squared/workspace/application.rb', line 524
def get(name, &blk)
ret = @project[name.to_s]
return ret unless block_given?
ret&.instance_eval(&blk)
self
end
|
#graph(script, group: @group, ref: @ref, on: nil) ⇒ Object
294
295
296
|
# File 'lib/squared/workspace/application.rb', line 294
def graph(script, group: @group, ref: @ref, on: nil)
script_command :graph, as_a(script, :to_s).freeze, group, ref, on
end
|
#group(path, val, override: {}, **kwargs, &blk) ⇒ Object
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'lib/squared/workspace/application.rb', line 424
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.update(opts) if opts
add(dir, basename, group: val, **args, &blk)
end
self
end
|
#home? ⇒ Boolean
739
740
741
|
# File 'lib/squared/workspace/application.rb', line 739
def home?
!!find(home)&.enabled?
end
|
#homepath(*args) ⇒ Object
771
772
773
|
# File 'lib/squared/workspace/application.rb', line 771
def homepath(*args)
home.join(*args)
end
|
#inspect ⇒ Object
795
796
797
|
# File 'lib/squared/workspace/application.rb', line 795
def inspect
"#<#{self.class}: #{main} => #{self}>"
end
|
#invokeargs ⇒ Object
783
784
785
|
# File 'lib/squared/workspace/application.rb', line 783
def invokeargs
{ exception: exception?, warning: warning }
end
|
#join(task, *cmd, invoke: nil, args: [], group: @group, ref: @ref, **kwargs, &blk) ⇒ Object
247
248
249
250
251
252
253
254
|
# File 'lib/squared/workspace/application.rb', line 247
def join(task, *cmd, invoke: nil, args: [], group: @group, ref: @ref, **kwargs, &blk)
unless block_given?
invoke ||= cmd.shift
args = cmd if (args = Array(args)).empty?
args.unshift(invoke)
end
script_command task.to_sym, args, group, ref, @join, kwargs, &blk
end
|
#lint(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
306
307
308
|
# File 'lib/squared/workspace/application.rb', line 306
def lint(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :lint, script, group, ref, on, &blk
end
|
#log(script, group: @group, ref: @ref) ⇒ Object
314
315
316
|
# File 'lib/squared/workspace/application.rb', line 314
def log(script, group: @group, ref: @ref)
script_command :log, script, group, ref
end
|
#mri? ⇒ Boolean
747
748
749
|
# File 'lib/squared/workspace/application.rb', line 747
def mri?
RUBY_ENGINE == 'ruby'
end
|
#pass(name, group: @group, ref: @ref, &blk) ⇒ Object
322
323
324
325
326
327
328
329
330
331
332
|
# File 'lib/squared/workspace/application.rb', line 322
def pass(name, group: @group, ref: @ref, &blk)
data = if group
@pass.group[group.to_s]
elsif ref
@pass.ref[ref.to_sym]
else
@pass.store
end
data[name.to_sym] = blk
self
end
|
#powershell? ⇒ Boolean
755
756
757
758
759
760
761
762
763
764
765
|
# File 'lib/squared/workspace/application.rb', line 755
def powershell?
return true if ENV['SHELL']&.end_with?(File.join('', 'pwsh'))
return false unless windows?
case ENV['TERM_PROGRAM']
when 'powershell.exe', 'vscode'
true
else
ENV.fetch('PSModulePath', '').split(';', 2).size > 1
end
end
|
#prod?(**kwargs) ⇒ Boolean
735
736
737
|
# File 'lib/squared/workspace/application.rb', line 735
def prod?(**kwargs)
script?(:prod, **kwargs)
end
|
#pwd ⇒ Object
775
776
777
|
# File 'lib/squared/workspace/application.rb', line 775
def pwd
Pathname.new(Rake.application.original_dir)
end
|
#rename(task, val) ⇒ Object
386
387
388
389
|
# File 'lib/squared/workspace/application.rb', line 386
def rename(task, val)
(@config[:rename] ||= {})[task.to_sym] = val.to_s
self
end
|
#rootpath(*args) ⇒ Object
767
768
769
|
# File 'lib/squared/workspace/application.rb', line 767
def rootpath(*args)
root.join(*args)
end
|
#run(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
256
257
258
|
# File 'lib/squared/workspace/application.rb', line 256
def run(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :run, script, group, ref, on, &blk
end
|
#script(script, group: @group, ref: @ref, on: nil) ⇒ Object
286
287
288
|
# File 'lib/squared/workspace/application.rb', line 286
def script(script, group: @group, ref: @ref, on: nil)
script_command :script, script, group, ref, on
end
|
#script_find(*args, name: nil) ⇒ Object
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
|
# File 'lib/squared/workspace/application.rb', line 651
def script_find(*args, name: nil)
target = @global[name || '_']
group, ref, exclude = target.fetch_values(:group, :ref, :exclude)
ret = nil
args.reverse_each do |val|
next unless val
if exclude.include?(val)
ret = nil
break
elsif ret
next
elsif (ret = val.is_a?(Symbol) ? ref[val] : group[val]) && exclude.empty?
break
end
end
ret || (target[:script] ||= scriptobj)
end
|
#script_get(*args, group: nil, ref: nil) ⇒ Object
670
671
672
|
# File 'lib/squared/workspace/application.rb', line 670
def script_get(*args, group: nil, ref: nil)
data_get(*args, target: @script, group: group, ref: ref)
end
|
#size ⇒ Object
787
788
789
|
# File 'lib/squared/workspace/application.rb', line 787
def size
@project.size
end
|
#stage(val, first: false, &blk) ⇒ Object
449
450
451
452
453
454
455
456
457
458
459
|
# File 'lib/squared/workspace/application.rb', line 449
def stage(val, first: false, &blk)
data = @stage[val]
if first == true
data.unshift(blk)
elsif first.is_a?(Numeric) && first < data.size
data.insert(first, blk)
else
data.push(blk)
end
self
end
|
#style(obj, *args, target: nil, empty: false) ⇒ Object
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
# File 'lib/squared/workspace/application.rb', line 461
def style(obj, *args, target: nil, empty: false)
data = nil
if target
Array(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
if obj.is_a?(String)
obj = begin
JSON.parse(homepath(obj).read, { symbolize_names: true })
rescue => e
warn log_message(Logger::ERROR, e)
end
end
apply_style(data || theme, obj, args, empty: empty) if obj && (!target || data)
self
end
|
#task_base?(key) ⇒ Boolean
702
703
704
|
# File 'lib/squared/workspace/application.rb', line 702
def task_base?(key)
series.base?(key)
end
|
#task_defined?(*key) ⇒ Boolean
727
728
729
|
# File 'lib/squared/workspace/application.rb', line 727
def task_defined?(*key)
Rake::Task.task_defined?(key.size == 1 ? key.first : task_join(*key))
end
|
#task_desc(*args, **kwargs) ⇒ Object
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
# File 'lib/squared/workspace/application.rb', line 544
def task_desc(*args, **kwargs)
return unless TASK_METADATA
name = kwargs.delete(:name)
if @describe
val = name || task_join(*args)
found = false
sub = lambda do |data, out|
index = data.size
data.to_a.reverse_each { |group| out.sub!("%#{index -= 1}", group) }
out
end
@describe[:replace].each do |pat, tmpl|
next unless val =~ pat
val = sub.call($~, tmpl.dup)
found = true
end
if (out = @describe[:alias][val])
val = out
found = true
else
@describe[:pattern].each do |key, pat|
next unless val =~ pat
val = sub.call($~, key.dup)
found = true
break
end
end
args = split_escape(val, char: ':').map { |s| s.gsub('\\:', ':') } if found
end
desc message(*args, **kwargs)
end
|
#task_exclude?(key, obj = nil) ⇒ Boolean
716
717
718
719
720
721
722
723
724
725
|
# File 'lib/squared/workspace/application.rb', line 716
def task_exclude?(key, obj = nil)
if obj
data = obj.group ? @pass.group[obj.group] : @pass.ref[obj.ref]
blk = (data && data[key.to_sym]) || @pass.store[key.to_sym]
return true if blk && obj.instance_eval(&blk)
key = task_join(task_localname(obj.name), key)
end
@pass.items.any? { |item| item.is_a?(Regexp) ? item.match?(key) : item == key }
end
|
#task_extend?(obj, key) ⇒ Boolean
706
707
708
|
# File 'lib/squared/workspace/application.rb', line 706
def task_extend?(obj, key)
series.extend?(obj, key)
end
|
#task_include?(obj, key, ref: nil) ⇒ Boolean
710
711
712
713
714
|
# File 'lib/squared/workspace/application.rb', line 710
def task_include?(obj, key, ref: nil)
return false if series.exclude?(key)
task_base?(key) ? obj.has?(key, ref: ref || baseref) : task_extend?(obj, key)
end
|
#task_localname(val) ⇒ Object
540
541
542
|
# File 'lib/squared/workspace/application.rb', line 540
def task_localname(val)
prefix && val.is_a?(String) ? val.sub(/^#{Regexp.escape(prefix)}:/, '') : val.to_s
end
|
#task_name(val) ⇒ Object
536
537
538
|
# File 'lib/squared/workspace/application.rb', line 536
def task_name(val)
prefix ? task_join(prefix, val) : val.to_s
end
|
#task_namespace(val, first: false) ⇒ Object
579
580
581
582
583
|
# File 'lib/squared/workspace/application.rb', line 579
def task_namespace(val, first: false)
return unless (ret = val.to_s.split(':')).size > 1
first ? ret.first : task_join(*ret[0..-2])
end
|
#task_resolve(obj, key) ⇒ Object
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
# File 'lib/squared/workspace/application.rb', line 585
def task_resolve(obj, key)
tasks = []
if (base = task_base?(key))
tasks << key if obj.has?(key, ref: baseref)
elsif (batch = series.batch_get(key))
obj.allref do |ref|
next unless obj.has?(key, ref: ref, missing: series.missing?(ref, key)) && (data = batch[ref])
data.each do |val|
if (items = task_resolve(obj, val)).empty?
tasks.clear
break
end
tasks.concat(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 do |ref|
next unless obj.has?(key, ref: 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
626
627
628
629
|
# File 'lib/squared/workspace/application.rb', line 626
def task_sync(key)
key = task_name key
task_defined?(ret = task_join(key, 'sync')) ? ret : key
end
|
#test(script = nil, group: @group, ref: @ref, on: nil, &blk) ⇒ Object
310
311
312
|
# File 'lib/squared/workspace/application.rb', line 310
def test(script = nil, group: @group, ref: @ref, on: nil, &blk)
script_command :test, script, group, ref, on, &blk
end
|
#timeout(data, group: @group, ref: @ref) ⇒ Object
370
371
372
373
374
375
376
377
378
379
|
# File 'lib/squared/workspace/application.rb', line 370
def timeout(data, group: @group, ref: @ref)
if group
@timeout.group[group.to_s].update(data)
elsif ref
@timeout.ref[ref.to_sym].update(data)
else
@timeout.store.update(data)
end
self
end
|
#timeout_get(*ref, group: nil) ⇒ Object
687
688
689
690
691
692
|
# File 'lib/squared/workspace/application.rb', line 687
def timeout_get(*ref, group: nil)
ret = @timeout.store.dup
ref.each { |val| ret.update(@timeout.ref[val]) if @timeout.ref.key?(val) }
ret.update(@timeout.group[group]) if group && @timeout.group.key?(group)
ret
end
|
#to_s ⇒ Object
791
792
793
|
# File 'lib/squared/workspace/application.rb', line 791
def to_s
(home? ? home : root).to_s
end
|
#windows? ⇒ Boolean
743
744
745
|
# File 'lib/squared/workspace/application.rb', line 743
def windows?
Rake::Win32.windows?
end
|
#with(*val, hide: false, group: nil, **kwargs, &blk) ⇒ Object
200
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
239
240
241
242
243
244
245
|
# File 'lib/squared/workspace/application.rb', line 200
def with(*val, hide: false, group: nil, **kwargs, &blk)
if hide
return self if hide == true
Array(hide).each do |args|
if args.is_a?(Array)
if respond_to?(hint = args.first)
next unless __send__(*args)
return self
end
elsif respond_to?(args)
next unless __send__(args)
return self
end
raise 'method not found'
rescue => e
warn log_message(Logger::WARN, e, subject: main, hint: hint || args)
end
end
@group = nil
@ref = nil
@withargs = unless kwargs.empty?
kwargs.delete(:parent)
kwargs
end
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 TypeError, message('not a group/ref', hint: kind || 'nil') if block_given?
end
if block_given?
instance_eval(&blk)
@group = nil
@ref = nil
@withargs = nil
end
self
end
|