squared 0.4.24 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -357
- data/README.md +1279 -650
- data/README.ruby.md +722 -0
- data/lib/squared/common/base.rb +8 -9
- data/lib/squared/common/format.rb +17 -24
- data/lib/squared/common/prompt.rb +38 -42
- data/lib/squared/common/shell.rb +29 -29
- data/lib/squared/common/system.rb +34 -37
- data/lib/squared/common/utils.rb +3 -28
- data/lib/squared/common.rb +2 -1
- data/lib/squared/config.rb +21 -21
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +57 -93
- data/lib/squared/workspace/project/base.rb +354 -480
- data/lib/squared/workspace/project/docker.rb +175 -203
- data/lib/squared/workspace/project/git.rb +357 -498
- data/lib/squared/workspace/project/node.rb +138 -213
- data/lib/squared/workspace/project/python.rb +88 -306
- data/lib/squared/workspace/project/ruby.rb +220 -300
- data/lib/squared/workspace/project/support/class.rb +94 -288
- data/lib/squared/workspace/project.rb +0 -10
- data/lib/squared/workspace/repo.rb +53 -92
- data/lib/squared/workspace/series.rb +34 -32
- data/lib/squared/workspace/support/data.rb +3 -2
- data/lib/squared/workspace/support.rb +0 -1
- data/lib/squared/workspace.rb +1 -1
- data/squared.gemspec +5 -5
- metadata +7 -8
- data/lib/squared/common/class.rb +0 -110
- data/lib/squared/workspace/support/base.rb +0 -17
data/lib/squared/config.rb
CHANGED
|
@@ -15,7 +15,8 @@ module Squared
|
|
|
15
15
|
def parse(gem, namespace, ext = [pkg])
|
|
16
16
|
require gem
|
|
17
17
|
obj = eval namespace
|
|
18
|
-
|
|
18
|
+
ext = [ext] unless ext.is_a?(Array)
|
|
19
|
+
ext.each { |val| @@mime_obj[val] = [obj, ext] }
|
|
19
20
|
rescue LoadError, NameError => e
|
|
20
21
|
warn e
|
|
21
22
|
nil
|
|
@@ -26,7 +27,7 @@ module Squared
|
|
|
26
27
|
def link(project, main = project.dependfile.basename, name = nil, **kwargs, &blk)
|
|
27
28
|
return unless project.enabled?
|
|
28
29
|
|
|
29
|
-
ret =
|
|
30
|
+
ret = new(main, name, project: project, **kwargs)
|
|
30
31
|
ret.instance_eval(&blk) if block_given?
|
|
31
32
|
ret
|
|
32
33
|
end
|
|
@@ -88,16 +89,16 @@ module Squared
|
|
|
88
89
|
@required = true
|
|
89
90
|
project ? [project, 'not found'] : ['name', 'missing']
|
|
90
91
|
end
|
|
91
|
-
warn log_message(Logger::WARN, msg, subject: self.class, hint: hint)
|
|
92
|
+
warn log_message(Logger::WARN, msg, subject: self.class, hint: hint, pass: true)
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def build
|
|
95
96
|
return unless enabled?
|
|
96
97
|
|
|
97
|
-
namespace task_name(name) do
|
|
98
|
+
namespace(ns = task_name(name)) do
|
|
98
99
|
@mime.each do |type, items|
|
|
99
100
|
items.each do |command, file, opts|
|
|
100
|
-
next if Rake::Task.task_defined?("#{ns
|
|
101
|
+
next if Rake::Task.task_defined?("#{ns}:#{command}:#{type}")
|
|
101
102
|
|
|
102
103
|
namespace command do
|
|
103
104
|
unless (data = @@mime_obj[type])
|
|
@@ -128,7 +129,7 @@ module Squared
|
|
|
128
129
|
require(gem || type)
|
|
129
130
|
obj = eval namespace
|
|
130
131
|
else
|
|
131
|
-
|
|
132
|
+
as_a(ext).each do |val|
|
|
132
133
|
next unless (data = @@mime_obj[val])
|
|
133
134
|
|
|
134
135
|
obj = data.first
|
|
@@ -136,7 +137,7 @@ module Squared
|
|
|
136
137
|
end
|
|
137
138
|
end
|
|
138
139
|
if obj
|
|
139
|
-
ext << type if (ext =
|
|
140
|
+
ext << type if (ext = as_a(ext)).empty?
|
|
140
141
|
if !file && target?
|
|
141
142
|
ext.each do |val|
|
|
142
143
|
next unless (out = basepath("#{main}.#{val}")).exist?
|
|
@@ -169,7 +170,7 @@ module Squared
|
|
|
169
170
|
end
|
|
170
171
|
|
|
171
172
|
def style(name, *args)
|
|
172
|
-
apply_style
|
|
173
|
+
apply_style theme, name, args
|
|
173
174
|
self
|
|
174
175
|
end
|
|
175
176
|
|
|
@@ -196,7 +197,7 @@ module Squared
|
|
|
196
197
|
private
|
|
197
198
|
|
|
198
199
|
def puts(*args)
|
|
199
|
-
|
|
200
|
+
puts_oe(*args, pipe: pipe)
|
|
200
201
|
end
|
|
201
202
|
|
|
202
203
|
def log
|
|
@@ -212,8 +213,8 @@ module Squared
|
|
|
212
213
|
file = nil
|
|
213
214
|
ext[0] = mime
|
|
214
215
|
elsif file
|
|
215
|
-
keys.
|
|
216
|
-
alt = basepath
|
|
216
|
+
keys.prepend(file)
|
|
217
|
+
alt = basepath("#{main}.{#{ext.join(',')}}")
|
|
217
218
|
file = Dir[alt].first
|
|
218
219
|
else
|
|
219
220
|
alt = main
|
|
@@ -242,15 +243,14 @@ module Squared
|
|
|
242
243
|
[
|
|
243
244
|
{ pat: /\A((?:[^:]|(?<! ):(?! ))+)\z/, styles: theme[:banner] },
|
|
244
245
|
{ pat: /\A(.*?)(<[^>]+>)(.+)\z/m, styles: theme[:undefined], index: 2 },
|
|
245
|
-
{ pat: /\A(
|
|
246
|
-
{ pat: /\A(
|
|
246
|
+
{ pat: /\A((?~ : ))( : (?!undefined).+)\z/m, styles: theme[:key] },
|
|
247
|
+
{ pat: /\A((?~: ): )(-?[\d.]+)(\s*)\z/m, styles: theme[:number],
|
|
247
248
|
index: 2 },
|
|
248
|
-
{ pat: /\A(
|
|
249
|
-
{ pat: /\A(
|
|
250
|
-
{ pat: /\A(
|
|
251
|
-
{ pat: /\A(.+ : )(true|false)(\s*)\z/m, styles: theme[:boolean],
|
|
249
|
+
{ pat: /\A((?~: ): ")(.+)("\s*)\z/m, styles: theme[:string], index: 2 },
|
|
250
|
+
{ pat: /\A((?~: ): \{)(.+)(\}\s*)\z/m, styles: theme[:hash], index: 2 },
|
|
251
|
+
{ pat: /\A((?~: ): \[)(.+)(\]\s*)\z/m, styles: theme[:array],
|
|
252
252
|
index: 2 },
|
|
253
|
-
{ pat: /\A(
|
|
253
|
+
{ pat: /\A((?~: ): (?!undefined))([^"\[{].*)\z/m, styles: theme[:value],
|
|
254
254
|
index: 2 }
|
|
255
255
|
]
|
|
256
256
|
end, border: theme[:border])
|
|
@@ -309,7 +309,7 @@ module Squared
|
|
|
309
309
|
return unless Rake::TaskManager.record_task_metadata
|
|
310
310
|
|
|
311
311
|
val = "#{ext.first}[#{target ? '' : "file?=#{File.basename(main)}.#{ext.last},"}keys+]"
|
|
312
|
-
args = *name.split(':').
|
|
312
|
+
args = *name.split(':').append(command, val)
|
|
313
313
|
if project
|
|
314
314
|
project.workspace.task_desc(*args)
|
|
315
315
|
else
|
|
@@ -346,8 +346,8 @@ module Squared
|
|
|
346
346
|
basepath(file = main + @ext).to_s rescue file
|
|
347
347
|
end
|
|
348
348
|
|
|
349
|
-
def basepath(
|
|
350
|
-
project ? project.basepath(
|
|
349
|
+
def basepath(file)
|
|
350
|
+
project ? project.basepath(file) : Pathname.pwd + file
|
|
351
351
|
end
|
|
352
352
|
end
|
|
353
353
|
end
|
data/lib/squared/version.rb
CHANGED
|
@@ -26,10 +26,10 @@ module Squared
|
|
|
26
26
|
next unless base || obj < impl_project
|
|
27
27
|
|
|
28
28
|
if base
|
|
29
|
-
|
|
29
|
+
@impl_project = obj
|
|
30
30
|
impl_series.base_set(obj)
|
|
31
31
|
else
|
|
32
|
-
kind_project.
|
|
32
|
+
kind_project.prepend(obj)
|
|
33
33
|
obj.tasks&.each { |task| impl_series.add(task, obj) }
|
|
34
34
|
end
|
|
35
35
|
if (args = obj.batchargs)
|
|
@@ -39,7 +39,7 @@ module Squared
|
|
|
39
39
|
impl_series.alias(*args)
|
|
40
40
|
end
|
|
41
41
|
if (args = obj.bannerargs)
|
|
42
|
-
attr_banner.merge(args)
|
|
42
|
+
@attr_banner.merge(args)
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
end
|
|
@@ -73,7 +73,7 @@ module Squared
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
@kind_project = []
|
|
76
|
-
@task_exclude =
|
|
76
|
+
@task_exclude = Set.new
|
|
77
77
|
|
|
78
78
|
attr_reader :root, :home, :main, :prefix, :exception, :warning, :pipe, :verbose, :theme, :series, :closed
|
|
79
79
|
|
|
@@ -92,18 +92,12 @@ module Squared
|
|
|
92
92
|
@prefix = prefix
|
|
93
93
|
@series = Application.series_wrap(self)
|
|
94
94
|
@project = {}
|
|
95
|
-
@kind =
|
|
95
|
+
@kind = {}
|
|
96
96
|
@extensions = []
|
|
97
|
-
@envname =
|
|
98
|
-
@pipe =
|
|
97
|
+
@envname = @main.gsub(/[^\w]+/, '_').upcase.freeze
|
|
98
|
+
@pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
|
|
99
99
|
@exception = env_bool exception
|
|
100
|
-
@verbose =
|
|
101
|
-
false
|
|
102
|
-
elsif verbose.nil?
|
|
103
|
-
@pipe != 0
|
|
104
|
-
else
|
|
105
|
-
env_bool(verbose, verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
|
|
106
|
-
end
|
|
100
|
+
@verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
|
|
107
101
|
@warning = @verbose != false
|
|
108
102
|
@closed = false
|
|
109
103
|
if common
|
|
@@ -112,20 +106,20 @@ module Squared
|
|
|
112
106
|
else
|
|
113
107
|
@theme = {}
|
|
114
108
|
end
|
|
115
|
-
@chain =
|
|
109
|
+
@chain = {}
|
|
116
110
|
@script = {
|
|
117
|
-
group:
|
|
118
|
-
ref:
|
|
111
|
+
group: {},
|
|
112
|
+
ref: {},
|
|
119
113
|
group!: {},
|
|
120
114
|
ref!: {}
|
|
121
115
|
}.freeze
|
|
122
116
|
@events = {
|
|
123
|
-
group:
|
|
124
|
-
ref:
|
|
117
|
+
group: {},
|
|
118
|
+
ref: {}
|
|
125
119
|
}.freeze
|
|
126
120
|
@pass = {
|
|
127
|
-
group:
|
|
128
|
-
ref:
|
|
121
|
+
group: {},
|
|
122
|
+
ref: {},
|
|
129
123
|
global: {},
|
|
130
124
|
pattern: []
|
|
131
125
|
}.freeze
|
|
@@ -140,7 +134,7 @@ module Squared
|
|
|
140
134
|
return unless @pipe.is_a?(Pathname)
|
|
141
135
|
|
|
142
136
|
msg = "Session started on #{Time.now} by #{@main}"
|
|
143
|
-
bord = '#' *
|
|
137
|
+
bord = '#' * s.size
|
|
144
138
|
puts bord, msg, bord
|
|
145
139
|
end
|
|
146
140
|
|
|
@@ -226,12 +220,12 @@ module Squared
|
|
|
226
220
|
if arg.include?(':') || (keys && !keys.include?(arg))
|
|
227
221
|
task_name(arg)
|
|
228
222
|
else
|
|
229
|
-
|
|
223
|
+
/#{Regexp.escape(arg)}:/
|
|
230
224
|
end
|
|
231
225
|
end
|
|
232
226
|
end
|
|
233
|
-
data =
|
|
234
|
-
@chain[task_name(task.to_s)] << data
|
|
227
|
+
data = Support::ChainData.new(action, step, ns.call(with), ns.call(before), ns.call(after), sync)
|
|
228
|
+
(@chain[task_name(task.to_s)] ||= []) << data
|
|
235
229
|
self
|
|
236
230
|
end
|
|
237
231
|
|
|
@@ -273,9 +267,9 @@ module Squared
|
|
|
273
267
|
|
|
274
268
|
def pass(name, group: @group, ref: @ref, &blk)
|
|
275
269
|
data = if group
|
|
276
|
-
@pass[:group][group]
|
|
270
|
+
@pass[:group][group] ||= {}
|
|
277
271
|
elsif ref
|
|
278
|
-
@pass[:ref][ref]
|
|
272
|
+
@pass[:ref][ref] ||= {}
|
|
279
273
|
else
|
|
280
274
|
@pass[:global]
|
|
281
275
|
end
|
|
@@ -284,7 +278,7 @@ module Squared
|
|
|
284
278
|
end
|
|
285
279
|
|
|
286
280
|
def banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref)
|
|
287
|
-
data =
|
|
281
|
+
data = Support::BannerData.new(command, [], check_style(styles, empty: false), check_style(border))
|
|
288
282
|
args.each do |meth|
|
|
289
283
|
if meth.is_a?(Array)
|
|
290
284
|
found = false
|
|
@@ -307,26 +301,21 @@ module Squared
|
|
|
307
301
|
elsif !Application.attr_banner.include?(meth = meth.to_sym)
|
|
308
302
|
next
|
|
309
303
|
end
|
|
310
|
-
data
|
|
304
|
+
data.order << meth
|
|
311
305
|
end
|
|
312
|
-
data = {} if !command && data[:order].empty?
|
|
313
306
|
if group
|
|
314
307
|
label = :group
|
|
315
|
-
items =
|
|
308
|
+
items = as_a group
|
|
316
309
|
else
|
|
317
310
|
label = :ref
|
|
318
|
-
items =
|
|
311
|
+
items = ref ? as_a(ref) : [:_]
|
|
319
312
|
end
|
|
320
313
|
items.each { |val| @banner[label][val.to_sym] = data }
|
|
321
314
|
self
|
|
322
315
|
end
|
|
323
316
|
|
|
324
317
|
def add(path, project = nil, **kwargs, &blk)
|
|
325
|
-
if @withargs
|
|
326
|
-
data = @withargs.dup
|
|
327
|
-
data.merge!(kwargs)
|
|
328
|
-
kwargs = data
|
|
329
|
-
end
|
|
318
|
+
kwargs = @withargs.yield_self { |data| data.dup.update(kwargs) } if @withargs
|
|
330
319
|
ref = if kwargs.key?(:ref)
|
|
331
320
|
kwargs = kwargs.dup unless @withargs
|
|
332
321
|
kwargs.delete(:ref)
|
|
@@ -366,14 +355,14 @@ module Squared
|
|
|
366
355
|
end
|
|
367
356
|
.each do |dir, basename, opts|
|
|
368
357
|
args = kwargs.dup
|
|
369
|
-
args.
|
|
358
|
+
args.update(opts) if opts
|
|
370
359
|
add(dir, basename, group: val, **args, &blk)
|
|
371
360
|
end
|
|
372
361
|
self
|
|
373
362
|
end
|
|
374
363
|
|
|
375
364
|
def compose(name, &blk)
|
|
376
|
-
namespace(task_name(name), &blk)
|
|
365
|
+
namespace(task_name(name), &blk) if block_given?
|
|
377
366
|
self
|
|
378
367
|
end
|
|
379
368
|
|
|
@@ -385,7 +374,7 @@ module Squared
|
|
|
385
374
|
def style(obj, *args, target: nil, empty: false)
|
|
386
375
|
data = nil
|
|
387
376
|
if target
|
|
388
|
-
|
|
377
|
+
as_a(target).each_with_index do |key, i|
|
|
389
378
|
if i == 0
|
|
390
379
|
break unless (data = __get__(:theme)[key.to_sym])
|
|
391
380
|
else
|
|
@@ -405,7 +394,7 @@ module Squared
|
|
|
405
394
|
}
|
|
406
395
|
data.each do |key, val|
|
|
407
396
|
key = key.to_s
|
|
408
|
-
if key.
|
|
397
|
+
if key.start_with?(/(\\A|\^)/) || key.match?(/(\\z|\$)\z/)
|
|
409
398
|
@describe[:replace] << [Regexp.new(key), val]
|
|
410
399
|
else
|
|
411
400
|
@describe[val.is_a?(Regexp) ? :pattern : :alias][key.to_s] = val
|
|
@@ -423,13 +412,13 @@ module Squared
|
|
|
423
412
|
if ret.empty?
|
|
424
413
|
ret = @project.select { |_, item| item.ref?(ref) }.map(&:last) if ref
|
|
425
414
|
if ret.empty? && (path || name)
|
|
426
|
-
path &&= rootpath
|
|
415
|
+
path &&= rootpath path
|
|
427
416
|
name &&= name.to_s
|
|
428
417
|
proj = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last
|
|
429
418
|
ret << proj if proj
|
|
430
419
|
end
|
|
431
420
|
end
|
|
432
|
-
return (group || ref ? ret : ret
|
|
421
|
+
return (group || ref ? ret : ret[0]) unless block_given?
|
|
433
422
|
|
|
434
423
|
ret.each(&blk)
|
|
435
424
|
self
|
|
@@ -491,7 +480,7 @@ module Squared
|
|
|
491
480
|
end
|
|
492
481
|
|
|
493
482
|
def task_namespace(val, first: false)
|
|
494
|
-
return unless (ret = val.to_s.split(':')).size > 1
|
|
483
|
+
return nil unless (ret = val.to_s.split(':')).size > 1
|
|
495
484
|
|
|
496
485
|
first ? ret.first : task_join(*ret[0..-2])
|
|
497
486
|
end
|
|
@@ -523,7 +512,7 @@ module Squared
|
|
|
523
512
|
obj.allref.each do |ref|
|
|
524
513
|
next unless obj.has?(key, ref) && (alt = data[ref])
|
|
525
514
|
|
|
526
|
-
ret = task_resolve
|
|
515
|
+
ret = task_resolve obj, alt
|
|
527
516
|
break unless ret.empty?
|
|
528
517
|
end
|
|
529
518
|
else
|
|
@@ -543,7 +532,7 @@ module Squared
|
|
|
543
532
|
end
|
|
544
533
|
|
|
545
534
|
def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false)
|
|
546
|
-
return unless TASK_METADATA
|
|
535
|
+
return unless TASK_METADATA
|
|
547
536
|
|
|
548
537
|
val = val.split(':') if val.is_a?(String)
|
|
549
538
|
if before || after || opts
|
|
@@ -629,27 +618,13 @@ module Squared
|
|
|
629
618
|
end
|
|
630
619
|
|
|
631
620
|
def home?
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
proj.enabled?
|
|
621
|
+
!(proj = find(home)).nil? && proj.enabled?
|
|
635
622
|
end
|
|
636
623
|
|
|
637
624
|
def windows?
|
|
638
625
|
Rake::Win32.windows?
|
|
639
626
|
end
|
|
640
627
|
|
|
641
|
-
def mri?
|
|
642
|
-
RUBY_ENGINE == 'ruby'
|
|
643
|
-
end
|
|
644
|
-
|
|
645
|
-
def jruby?
|
|
646
|
-
RUBY_ENGINE == 'jruby'
|
|
647
|
-
end
|
|
648
|
-
|
|
649
|
-
def truffleruby?
|
|
650
|
-
RUBY_ENGINE == 'truffleruby'
|
|
651
|
-
end
|
|
652
|
-
|
|
653
628
|
def docker?
|
|
654
629
|
!Dir['/.dockerenv', '/docker-*.{sh,d}'].empty?
|
|
655
630
|
end
|
|
@@ -686,10 +661,6 @@ module Squared
|
|
|
686
661
|
{ exception: exception, warning: warning }
|
|
687
662
|
end
|
|
688
663
|
|
|
689
|
-
def size
|
|
690
|
-
@project.size
|
|
691
|
-
end
|
|
692
|
-
|
|
693
664
|
def to_s
|
|
694
665
|
(home? ? home : root).to_s
|
|
695
666
|
end
|
|
@@ -703,14 +674,9 @@ module Squared
|
|
|
703
674
|
private
|
|
704
675
|
|
|
705
676
|
def __build__(default: nil, **)
|
|
706
|
-
unless task_defined?(
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
end
|
|
710
|
-
end
|
|
711
|
-
if default && task_defined?(out = task_name(default))
|
|
712
|
-
task Rake.application.default_task_name => out
|
|
713
|
-
end
|
|
677
|
+
return unless default && task_defined?(out = task_name(default))
|
|
678
|
+
|
|
679
|
+
task Rake.application.default_task_name => out
|
|
714
680
|
end
|
|
715
681
|
|
|
716
682
|
def __chain__(*)
|
|
@@ -732,7 +698,7 @@ module Squared
|
|
|
732
698
|
else
|
|
733
699
|
step = 0
|
|
734
700
|
catch :found do
|
|
735
|
-
has = ->(c, d) { c.any? { |e| e.is_a?(Regexp) ? d.
|
|
701
|
+
has = ->(c, d) { c.any? { |e| e.is_a?(Regexp) ? d.start_with?(e) : d == e } }
|
|
736
702
|
w = data.with
|
|
737
703
|
a = data.after
|
|
738
704
|
b = data.before
|
|
@@ -791,7 +757,7 @@ module Squared
|
|
|
791
757
|
end
|
|
792
758
|
end
|
|
793
759
|
if step == -1
|
|
794
|
-
level.
|
|
760
|
+
level.prepend(data.action)
|
|
795
761
|
step = 0
|
|
796
762
|
elsif step > 0
|
|
797
763
|
(level[step -= 1] ||= []).concat(data.action)
|
|
@@ -812,8 +778,8 @@ module Squared
|
|
|
812
778
|
format_desc key
|
|
813
779
|
task key do
|
|
814
780
|
unless failed.empty? && group.empty?
|
|
815
|
-
puts
|
|
816
|
-
subject: 'failed placement', hint: false
|
|
781
|
+
puts log_message(Logger::ERROR, *(failed + group.map { |val| val.action }.flatten),
|
|
782
|
+
subject: 'failed placement', hint: false, pass: true)
|
|
817
783
|
end
|
|
818
784
|
cols = level.flatten(1).map(&:size).max
|
|
819
785
|
level.each_with_index do |grp, n|
|
|
@@ -829,13 +795,13 @@ module Squared
|
|
|
829
795
|
end
|
|
830
796
|
end
|
|
831
797
|
|
|
832
|
-
def puts(*args
|
|
833
|
-
|
|
798
|
+
def puts(*args)
|
|
799
|
+
puts_oe(*args, pipe: pipe)
|
|
834
800
|
end
|
|
835
801
|
|
|
836
802
|
def script_command(task, val, group, ref, on, &blk)
|
|
837
803
|
if block_given?
|
|
838
|
-
val =
|
|
804
|
+
val = Support::RunData.new(val, blk)
|
|
839
805
|
elsif !val
|
|
840
806
|
return self
|
|
841
807
|
end
|
|
@@ -847,8 +813,8 @@ module Squared
|
|
|
847
813
|
items = as_a(ref, :to_sym)
|
|
848
814
|
end
|
|
849
815
|
items.each do |name|
|
|
850
|
-
@script[label][name][task] = val
|
|
851
|
-
@events[label][name][task] = on if on.is_a?(Hash)
|
|
816
|
+
(@script[label][name] ||= {})[task] = val
|
|
817
|
+
(@events[label][name] ||= {})[task] = on if on.is_a?(Hash)
|
|
852
818
|
end
|
|
853
819
|
self
|
|
854
820
|
end
|
|
@@ -856,26 +822,24 @@ module Squared
|
|
|
856
822
|
def script_set(data, group: nil, ref: nil)
|
|
857
823
|
data.freeze
|
|
858
824
|
if group
|
|
859
|
-
|
|
825
|
+
as_a(group).each { |val| @script[:group!][val.to_sym] = data }
|
|
860
826
|
elsif ref
|
|
861
|
-
|
|
827
|
+
as_a(ref).each { |val| @script[:ref!][val.to_sym] = data }
|
|
862
828
|
else
|
|
863
829
|
@script[:ref!][:''] = data
|
|
864
830
|
end
|
|
865
831
|
end
|
|
866
832
|
|
|
867
833
|
def data_get(*args, group: nil, ref: nil, target: nil)
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
elsif ref.is_a?(Enumerable)
|
|
834
|
+
target[:group][group.to_sym] if group
|
|
835
|
+
if ref.is_a?(Enumerable)
|
|
871
836
|
ref.each do |key|
|
|
872
|
-
next unless target[:ref]
|
|
837
|
+
next unless (ret = target[:ref][key])
|
|
873
838
|
|
|
874
|
-
ret = target[:ref][key]
|
|
875
839
|
return ret if args.empty? || args.any? { |val| ret.key?(val) }
|
|
876
840
|
end
|
|
877
841
|
nil
|
|
878
|
-
elsif ref
|
|
842
|
+
elsif ref
|
|
879
843
|
target[:ref][ref]
|
|
880
844
|
end
|
|
881
845
|
end
|
|
@@ -883,7 +847,7 @@ module Squared
|
|
|
883
847
|
def root?(path, pass: [])
|
|
884
848
|
return false unless path.directory?
|
|
885
849
|
|
|
886
|
-
path.
|
|
850
|
+
path.each_child do |c|
|
|
887
851
|
name = c.basename.to_s
|
|
888
852
|
next if c.to_s == __FILE__ || (@main == name && c.directory? && c.empty?) || pass.any? { |val| val == name }
|
|
889
853
|
|
|
@@ -893,14 +857,14 @@ module Squared
|
|
|
893
857
|
end
|
|
894
858
|
|
|
895
859
|
def script?(state, target: nil, pat: nil, group: nil, ref: baseref, global: false)
|
|
896
|
-
data = script_find
|
|
860
|
+
data = script_find ref, group
|
|
897
861
|
if global
|
|
898
862
|
target = data[:script] || data[:run] if target.nil?
|
|
899
863
|
pat = data[state] if pat.nil?
|
|
900
864
|
end
|
|
901
865
|
return false if state == :prod && data[:dev] == true && data[:global]
|
|
902
866
|
|
|
903
|
-
target && pat.is_a?(Regexp) ?
|
|
867
|
+
target && pat.is_a?(Regexp) ? as_a(target).any?(pat) : pat == true
|
|
904
868
|
end
|
|
905
869
|
|
|
906
870
|
def scriptobj
|