squared 0.4.14 → 0.5.1
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 +37 -0
- data/README.md +4 -4
- data/README.ruby.md +14 -11
- data/lib/squared/common/base.rb +5 -3
- data/lib/squared/common/format.rb +1 -1
- data/lib/squared/common/prompt.rb +44 -40
- data/lib/squared/common/shell.rb +13 -8
- data/lib/squared/common/system.rb +33 -29
- data/lib/squared/common/utils.rb +0 -12
- data/lib/squared/common.rb +2 -1
- data/lib/squared/config.rb +14 -13
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +16 -21
- data/lib/squared/workspace/project/base.rb +97 -132
- data/lib/squared/workspace/project/docker.rb +31 -30
- data/lib/squared/workspace/project/git.rb +74 -73
- data/lib/squared/workspace/project/node.rb +31 -20
- data/lib/squared/workspace/project/python.rb +11 -7
- data/lib/squared/workspace/project/ruby.rb +31 -31
- data/lib/squared/workspace/project/support/class.rb +80 -5
- data/lib/squared/workspace/project.rb +0 -10
- data/lib/squared/workspace/repo.rb +6 -6
- data/lib/squared/workspace/series.rb +8 -8
- data/lib/squared/workspace/support/data.rb +1 -0
- data/lib/squared/workspace.rb +1 -1
- data/squared.gemspec +1 -1
- metadata +2 -3
- data/lib/squared/common/class.rb +0 -110
@@ -557,7 +557,13 @@ module Squared
|
|
557
557
|
ret
|
558
558
|
end
|
559
559
|
|
560
|
-
def variable_set(key, *val,
|
560
|
+
def variable_set(key, *val, **, &blk)
|
561
|
+
if block_given?
|
562
|
+
case key
|
563
|
+
when :dependfile, :venv, :editable
|
564
|
+
val = block_args val, &blk
|
565
|
+
end
|
566
|
+
end
|
561
567
|
case key
|
562
568
|
when :dependfile
|
563
569
|
req = basepath(*val)
|
@@ -600,9 +606,7 @@ module Squared
|
|
600
606
|
|
601
607
|
def poetry_session(*cmd)
|
602
608
|
ret = session('poetry', *cmd, *preopts)
|
603
|
-
|
604
|
-
ret << quote_option('project', path + val)
|
605
|
-
end
|
609
|
+
option('project', ignore: false) { |val| ret << quote_option('project', path + val) }
|
606
610
|
ret
|
607
611
|
end
|
608
612
|
|
@@ -683,7 +687,7 @@ module Squared
|
|
683
687
|
end
|
684
688
|
|
685
689
|
def append_global(target: @session)
|
686
|
-
|
690
|
+
option('cache-dir', target: target) do |val|
|
687
691
|
target << case val
|
688
692
|
when '0', 'false'
|
689
693
|
'--no-cache-dir'
|
@@ -691,8 +695,8 @@ module Squared
|
|
691
695
|
quote_option('cache-dir', path + val)
|
692
696
|
end
|
693
697
|
end
|
694
|
-
|
695
|
-
|
698
|
+
option('proxy', target: target) { |val| target << shell_option('proxy', val) }
|
699
|
+
option('python', target: target) { |val| target << quote_option('python', path + val) }
|
696
700
|
append_nocolor(target: target)
|
697
701
|
end
|
698
702
|
|
@@ -231,7 +231,7 @@ module Squared
|
|
231
231
|
file = args.rb
|
232
232
|
args = args.extras
|
233
233
|
unless file && !file.include?('*')
|
234
|
-
file, opts, prog = choice_index('Select a file', Dir.glob(file ||
|
234
|
+
file, opts, prog = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
|
235
235
|
values: (file ? [] : ['Options']) << 'Arguments',
|
236
236
|
force: true, series: !args.include?('v'))
|
237
237
|
if file
|
@@ -304,7 +304,7 @@ module Squared
|
|
304
304
|
copy_dir(a, b, c, pass: pass, verbose: verbose)
|
305
305
|
rescue StandardError => e
|
306
306
|
log.error e
|
307
|
-
ret = on
|
307
|
+
ret = on :error, :copy, e
|
308
308
|
raise if exception && ret != true
|
309
309
|
end
|
310
310
|
end
|
@@ -319,7 +319,7 @@ module Squared
|
|
319
319
|
end
|
320
320
|
log.info cmd.to_s
|
321
321
|
on :first, :outdated
|
322
|
-
banner = format_banner
|
322
|
+
banner = format_banner cmd.to_s
|
323
323
|
print_item banner if sync
|
324
324
|
pwd_set(from: :outdated) do
|
325
325
|
start = 0
|
@@ -393,7 +393,7 @@ module Squared
|
|
393
393
|
index: 2)
|
394
394
|
end
|
395
395
|
end
|
396
|
-
out.call(
|
396
|
+
out.call('%2d. %s' % [start, line])
|
397
397
|
elsif line.start_with?('Gem')
|
398
398
|
unless stdin?
|
399
399
|
sub = { pat: /^(.+)(?<!\dm)(Gem|Latest)(.+)$/, styles: theme[:header], index: 2 }
|
@@ -410,7 +410,7 @@ module Squared
|
|
410
410
|
end
|
411
411
|
if found > 0
|
412
412
|
begin
|
413
|
-
if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])(
|
413
|
+
if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])((?~\1))\1|remote:\s+(\S+))/
|
414
414
|
status = ($2 || $3).chomp('/')
|
415
415
|
right = true
|
416
416
|
end
|
@@ -436,7 +436,7 @@ module Squared
|
|
436
436
|
def update(flag, opts = [])
|
437
437
|
bundle_session 'update', "--#{flag}"
|
438
438
|
append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
|
439
|
-
append: flag == :all ? nil : /\A
|
439
|
+
append: flag == :all ? nil : /\A[a-z\-]+=/)
|
440
440
|
run_rb(from: :update)
|
441
441
|
end
|
442
442
|
|
@@ -445,7 +445,7 @@ module Squared
|
|
445
445
|
when :file, :script
|
446
446
|
op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
|
447
447
|
if file
|
448
|
-
op.extras.
|
448
|
+
op.extras.prepend(shell_quote(path + file))
|
449
449
|
elsif command
|
450
450
|
op << quote_option('e', command, option: false)
|
451
451
|
end
|
@@ -472,8 +472,9 @@ module Squared
|
|
472
472
|
when 'rvm'
|
473
473
|
`rvm current`[/^\S+/, 0]
|
474
474
|
when 'rbenv'
|
475
|
-
|
476
|
-
|
475
|
+
`rbenv version-name`.yield_self do |name|
|
476
|
+
name.match?(SEM_VER) ? "ruby #{name}" : name
|
477
|
+
end
|
477
478
|
when 'chruby.sh'
|
478
479
|
chruby = session_output 'source', val
|
479
480
|
`#{chruby.with('ruby --version')}`
|
@@ -491,7 +492,7 @@ module Squared
|
|
491
492
|
when 'chruby.sh'
|
492
493
|
`#{chruby.with('chruby --version')}`.sub(':', '')
|
493
494
|
when 'install'
|
494
|
-
"asdf #{`asdf version`.
|
495
|
+
"asdf #{`asdf version`.delete_prefix('v')}"
|
495
496
|
else
|
496
497
|
`#{cmd} --version`
|
497
498
|
end)
|
@@ -522,7 +523,7 @@ module Squared
|
|
522
523
|
end
|
523
524
|
out.map!(&:split)
|
524
525
|
pad = out.map(&:first).map!(&:size).max
|
525
|
-
puts(out.map! { |line|
|
526
|
+
puts(out.map! { |line| '%*s %s' % [pad, line.first, line[1..-1].join(' ')] })
|
526
527
|
end
|
527
528
|
return
|
528
529
|
end
|
@@ -601,7 +602,7 @@ module Squared
|
|
601
602
|
|
602
603
|
a, b, c = item.first
|
603
604
|
if i == 0
|
604
|
-
line =
|
605
|
+
line = '%-*s %-*s %*s %*s' % [pad, ' #', d, a, e, b, f, c]
|
605
606
|
n = line.size
|
606
607
|
2.times do
|
607
608
|
line = sub_style(line, pat: /^(.+)(?<!\dm)(#{a}|#{c})(.*)$/, styles: theme[:header], index: 2)
|
@@ -645,15 +646,14 @@ module Squared
|
|
645
646
|
styles = %i[yellow]
|
646
647
|
pat = pat.last
|
647
648
|
end
|
648
|
-
b = b.rjust(e)
|
649
|
-
b = sub_style(b, *colormap(styles), pat: pat, index: 2)
|
649
|
+
b = sub_style(b.rjust(e), *colormap(styles), pat: pat, index: 2)
|
650
650
|
h = sub_style(c.rjust(f), styles: latest.flatten.compact, pat: pat, index: 2)
|
651
651
|
j += 1
|
652
652
|
if queue
|
653
653
|
puts queue
|
654
654
|
queue = nil
|
655
655
|
end
|
656
|
-
puts "#{
|
656
|
+
puts '%*s %s %s %s' % [pad, "#{j}.", g, b, h]
|
657
657
|
update << a if filter == 'interactive' && confirm_outdated(a, c, item.last)
|
658
658
|
end
|
659
659
|
end
|
@@ -664,15 +664,15 @@ module Squared
|
|
664
664
|
else
|
665
665
|
unless update.empty?
|
666
666
|
cmd = gem_output 'update', '-f'
|
667
|
-
|
667
|
+
option('document', prefix: 'gem', ignore: false) do |val|
|
668
668
|
cmd << case val
|
669
669
|
when '0', 'false'
|
670
670
|
'--no-document'
|
671
671
|
else
|
672
|
-
basic_option
|
672
|
+
basic_option 'document', val
|
673
673
|
end
|
674
674
|
end
|
675
|
-
|
675
|
+
option('user-install', prefix: 'gem', ignore: false) do |val|
|
676
676
|
cmd << case val
|
677
677
|
when '0', 'false'
|
678
678
|
'--no-user-install'
|
@@ -689,7 +689,7 @@ module Squared
|
|
689
689
|
return
|
690
690
|
when :build
|
691
691
|
if op.empty?
|
692
|
-
spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *
|
692
|
+
spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
|
693
693
|
op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
|
694
694
|
else
|
695
695
|
op << shell_quote(path + op.shift)
|
@@ -849,14 +849,15 @@ module Squared
|
|
849
849
|
pwd_set(pass: !pwd.nil?) do
|
850
850
|
out = `#{gem_output(pwd, 'list --local -d', project)}`
|
851
851
|
if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
852
|
+
$1.split(/\s*,\s*/)
|
853
|
+
.prepend(@version)
|
854
|
+
.uniq
|
855
|
+
.each do |val|
|
856
|
+
next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
|
857
|
+
|
858
|
+
set.call(val, $1)
|
859
|
+
break
|
860
|
+
end
|
860
861
|
end
|
861
862
|
end
|
862
863
|
end
|
@@ -979,10 +980,9 @@ module Squared
|
|
979
980
|
end
|
980
981
|
|
981
982
|
def rakefile
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
@rakefile = file ? path + file : ''
|
983
|
+
@rakefile ||= Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }.yield_self do |file|
|
984
|
+
file ? path + file : ''
|
985
|
+
end
|
986
986
|
end
|
987
987
|
|
988
988
|
def rakepwd
|
@@ -31,11 +31,11 @@ module Squared
|
|
31
31
|
def clear(target, opts, pass: true, styles: nil, **kwargs)
|
32
32
|
return if opts.empty?
|
33
33
|
|
34
|
-
kwargs[:subject] ||= stripext
|
34
|
+
kwargs[:subject] ||= stripext target.first
|
35
35
|
kwargs[:hint] ||= 'unrecognized'
|
36
36
|
append(target, opts, delim: true) if kwargs.delete(:append)
|
37
37
|
warn log_message(Logger::WARN, opts.join(', '), pass: true, **kwargs)
|
38
|
-
return if pass || confirm("Run? [#{sub_style(target, styles: styles)}]
|
38
|
+
return if pass || confirm("Run? [#{sub_style(target, styles: styles)}]", 'N')
|
39
39
|
|
40
40
|
raise_error 'user cancelled'
|
41
41
|
end
|
@@ -50,10 +50,11 @@ module Squared
|
|
50
50
|
def arg?(target, *args, value: false, **)
|
51
51
|
r, s = args.partition { |val| val.is_a?(Regexp) }
|
52
52
|
unless s.empty?
|
53
|
-
s.map! { |val| Regexp.escape(shell_option(val)) }
|
53
|
+
s.map! { |val| Regexp.escape(val.start_with?('-') ? val : shell_option(val)) }
|
54
54
|
r << /\A(?:#{s.join('|')})#{value ? '[ =].' : '(?: |=|\z)'}/
|
55
55
|
end
|
56
|
-
|
56
|
+
s = target.to_a.compact
|
57
|
+
r.any? { |pat| s.any?(pat) }
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -65,7 +66,7 @@ module Squared
|
|
65
66
|
:pop, :push, :join, :map, :map!, :select, :reject, :size
|
66
67
|
|
67
68
|
def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
|
68
|
-
@target = target.is_a?(Set) ? target :
|
69
|
+
@target = target.is_a?(Set) ? target : target.to_set
|
69
70
|
@project = project
|
70
71
|
@path = path || project&.path
|
71
72
|
@errors = []
|
@@ -245,6 +246,80 @@ module Squared
|
|
245
246
|
OptionPartition.arg?(target, *args, **kwargs)
|
246
247
|
end
|
247
248
|
end
|
249
|
+
|
250
|
+
class JoinSet < Set
|
251
|
+
def self.to_s
|
252
|
+
super[/[^:]+\z/, 0]
|
253
|
+
end
|
254
|
+
|
255
|
+
attr_reader :delim
|
256
|
+
|
257
|
+
def initialize(data = [], delim: ' ')
|
258
|
+
super(data.compact)
|
259
|
+
@delim = delim
|
260
|
+
end
|
261
|
+
|
262
|
+
def last(val, pat)
|
263
|
+
(@last ||= []).append([val, pat, $1]) if val =~ pat
|
264
|
+
self << val
|
265
|
+
end
|
266
|
+
|
267
|
+
def pass(&blk)
|
268
|
+
ret = to_a.map!(&:to_s).reject(&:empty?)
|
269
|
+
@last&.each do |val, pat, key|
|
270
|
+
i = []
|
271
|
+
j = nil
|
272
|
+
ret.each_with_index do |opt, index|
|
273
|
+
if opt == val
|
274
|
+
j = index
|
275
|
+
elsif j && opt[pat, 1] == key
|
276
|
+
i << index
|
277
|
+
end
|
278
|
+
end
|
279
|
+
next unless j && !i.empty?
|
280
|
+
|
281
|
+
val = ret[j]
|
282
|
+
cur = j
|
283
|
+
i.each do |k|
|
284
|
+
ret[cur] = ret[k]
|
285
|
+
cur = k
|
286
|
+
end
|
287
|
+
ret[i.last] = val
|
288
|
+
end
|
289
|
+
block_given? ? ret.reject(&blk) : ret
|
290
|
+
end
|
291
|
+
|
292
|
+
def and(*args)
|
293
|
+
self << '&&'
|
294
|
+
merge args
|
295
|
+
end
|
296
|
+
|
297
|
+
def or(*args)
|
298
|
+
self << '||'
|
299
|
+
merge args
|
300
|
+
end
|
301
|
+
|
302
|
+
def with(*args, &blk)
|
303
|
+
temp('&&', *args, &blk)
|
304
|
+
end
|
305
|
+
|
306
|
+
def temp(*args, &blk)
|
307
|
+
args.compact!
|
308
|
+
ret = pass(&blk)
|
309
|
+
ret = Set.new(ret.concat(args)).to_a unless args.empty?
|
310
|
+
ret.join(@delim)
|
311
|
+
end
|
312
|
+
|
313
|
+
def done
|
314
|
+
ret = to_s
|
315
|
+
clear
|
316
|
+
ret
|
317
|
+
end
|
318
|
+
|
319
|
+
def to_s
|
320
|
+
pass.join(@delim)
|
321
|
+
end
|
322
|
+
end
|
248
323
|
end
|
249
324
|
end
|
250
325
|
end
|
@@ -3,16 +3,6 @@
|
|
3
3
|
module Squared
|
4
4
|
module Workspace
|
5
5
|
module Project
|
6
|
-
class << self
|
7
|
-
attr_accessor :line_width
|
8
|
-
|
9
|
-
def max_width(lines)
|
10
|
-
n = [lines.max_by(&:size).size, 80].max
|
11
|
-
[n, Rake.application.terminal_width].min
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
@line_width = ENV.fetch('LOG_COLUMNS', 80).to_i
|
16
6
|
end
|
17
7
|
end
|
18
8
|
end
|
@@ -57,10 +57,10 @@ module Squared
|
|
57
57
|
when 'verbose'
|
58
58
|
@verbose = 1
|
59
59
|
if script.is_a?(Array)
|
60
|
-
script[0] = task_join
|
60
|
+
script[0] = task_join script[0], 'verbose'
|
61
61
|
script
|
62
62
|
else
|
63
|
-
task_join
|
63
|
+
task_join script, 'verbose'
|
64
64
|
end
|
65
65
|
when 'silent'
|
66
66
|
@verbose = false
|
@@ -81,8 +81,8 @@ module Squared
|
|
81
81
|
data[:run] = run
|
82
82
|
end
|
83
83
|
data[:global] = true
|
84
|
-
data[:dev] = env_match
|
85
|
-
data[:prod] = env_match
|
84
|
+
data[:dev] = env_match 'REPO_DEV', dev
|
85
|
+
data[:prod] = env_match 'REPO_PROD', prod
|
86
86
|
if (val = env('REPO_GROUP'))
|
87
87
|
script_set(data, group: val.split(','))
|
88
88
|
found = true
|
@@ -202,7 +202,7 @@ module Squared
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
series.sync.
|
205
|
+
series.sync.append(
|
206
206
|
task_join(name, 'all'),
|
207
207
|
task_join(name, 'init'),
|
208
208
|
task_join(name, 'sync')
|
@@ -215,7 +215,7 @@ module Squared
|
|
215
215
|
|
216
216
|
path = sub_style(root, styles: theme[:inline])
|
217
217
|
@repo_override = Common::Prompt.confirm(
|
218
|
-
"#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?
|
218
|
+
"#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
|
219
219
|
'N',
|
220
220
|
timeout: env('REPO_TIMEOUT', 15, ignore: '0')
|
221
221
|
)
|
@@ -68,7 +68,7 @@ module Squared
|
|
68
68
|
|
69
69
|
attr_reader :sync, :multiple, :parallel
|
70
70
|
|
71
|
-
def_delegators :@data, :[], :each, :each_key, :keys, :fetch, :
|
71
|
+
def_delegators :@data, :[], :each, :each_key, :keys, :key?, :fetch, :update, :merge!, :to_a, :to_s, :inspect
|
72
72
|
def_delegators :@workspace, :task_desc, :task_name, :task_namespace, :task_join, :format_desc
|
73
73
|
|
74
74
|
def initialize(workspace, exclude: [])
|
@@ -112,29 +112,29 @@ module Squared
|
|
112
112
|
|
113
113
|
def build(parallel: [], pattern: [], **)
|
114
114
|
subcheck = ->(val) { (ns = task_namespace(val)) && parallel.include?(ns) }
|
115
|
-
@data.
|
116
|
-
@data.
|
115
|
+
@data.update(@session[:parent]) if @session[:id].uniq.size > 1
|
116
|
+
@data.update(@session[:group])
|
117
117
|
@data.each do |key, items|
|
118
118
|
next if exclude?(key, true) || @workspace.task_exclude?(t = name_get(key))
|
119
119
|
|
120
120
|
key = task_name t
|
121
|
-
|
121
|
+
title = format_desc(key, out: true)
|
122
122
|
if items.size > 1
|
123
123
|
@multiple << key
|
124
124
|
if parallel.include?(t) || pattern.any? { |pat| t.match?(pat) } || subcheck.call(t)
|
125
|
-
task_desc("#{
|
125
|
+
task_desc("#{title} (thread)", name: key) if title
|
126
126
|
multitask key => items
|
127
127
|
@parallel << key
|
128
128
|
|
129
|
-
s = task_join
|
130
|
-
task_desc("#{
|
129
|
+
s = task_join key, 'sync'
|
130
|
+
task_desc("#{title} (sync)", name: s) if title
|
131
131
|
task s => items
|
132
132
|
@sync << s
|
133
133
|
next
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
-
task_desc(
|
137
|
+
task_desc(title, name: key) if title
|
138
138
|
task key => items
|
139
139
|
end
|
140
140
|
@multiple.concat(sync)
|
data/lib/squared/workspace.rb
CHANGED
@@ -10,7 +10,7 @@ module Squared
|
|
10
10
|
if id.is_a?(Symbol)
|
11
11
|
project id
|
12
12
|
else
|
13
|
-
__get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id) }
|
13
|
+
__get__(:project).find { |_, val| File.expand_path(val.path) == File.expand_path(id, __dir__) }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
ret.size == 1 ? ret.first : ret
|
data/squared.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = %q{Rake task generator for managing multi-language workspaces.}
|
12
12
|
spec.description = %q{Rake task generator for managing multi-language workspaces.}
|
13
13
|
spec.homepage = "https://github.com/anpham6/squared"
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
15
|
spec.licenses = ["BSD-3-Clause"]
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- An Pham
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- lib/squared/app.rb
|
81
81
|
- lib/squared/common.rb
|
82
82
|
- lib/squared/common/base.rb
|
83
|
-
- lib/squared/common/class.rb
|
84
83
|
- lib/squared/common/format.rb
|
85
84
|
- lib/squared/common/prompt.rb
|
86
85
|
- lib/squared/common/shell.rb
|
@@ -118,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
117
|
requirements:
|
119
118
|
- - ">="
|
120
119
|
- !ruby/object:Gem::Version
|
121
|
-
version: 2.
|
120
|
+
version: 2.5.0
|
122
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
122
|
requirements:
|
124
123
|
- - ">="
|
data/lib/squared/common/class.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'set'
|
4
|
-
require 'forwardable'
|
5
|
-
|
6
|
-
module Squared
|
7
|
-
module Common
|
8
|
-
class SymSet
|
9
|
-
extend Forwardable
|
10
|
-
|
11
|
-
def self.to_s
|
12
|
-
super[/[^:]+\z/, 0]
|
13
|
-
end
|
14
|
-
|
15
|
-
def_delegators :@data, :+, :each, :each_with_index, :entries, :merge, :include?
|
16
|
-
|
17
|
-
def initialize(data = [])
|
18
|
-
@data = Set.new(data)
|
19
|
-
end
|
20
|
-
|
21
|
-
def add(val)
|
22
|
-
@data.add(val.to_sym)
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_a
|
26
|
-
@data.to_a.freeze
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_s
|
30
|
-
@data.to_s.sub('Set', SymSet.to_s)
|
31
|
-
end
|
32
|
-
|
33
|
-
alias inspect to_s
|
34
|
-
end
|
35
|
-
|
36
|
-
class JoinSet < Set
|
37
|
-
def self.to_s
|
38
|
-
super[/[^:]+\z/, 0]
|
39
|
-
end
|
40
|
-
|
41
|
-
attr_reader :delim
|
42
|
-
|
43
|
-
def initialize(data = [], delim: ' ')
|
44
|
-
super(data.compact)
|
45
|
-
@delim = delim
|
46
|
-
end
|
47
|
-
|
48
|
-
def last(val, pat)
|
49
|
-
(@last ||= []).push([val, pat, $1]) if val =~ pat
|
50
|
-
self << val
|
51
|
-
end
|
52
|
-
|
53
|
-
def pass(&blk)
|
54
|
-
ret = to_a.map!(&:to_s).reject(&:empty?)
|
55
|
-
@last&.each do |val, pat, key|
|
56
|
-
i = []
|
57
|
-
j = nil
|
58
|
-
ret.each_with_index do |opt, index|
|
59
|
-
if opt == val
|
60
|
-
j = index
|
61
|
-
elsif j && opt[pat, 1] == key
|
62
|
-
i << index
|
63
|
-
end
|
64
|
-
end
|
65
|
-
next unless j && !i.empty?
|
66
|
-
|
67
|
-
val = ret[j]
|
68
|
-
cur = j
|
69
|
-
i.each do |k|
|
70
|
-
ret[cur] = ret[k]
|
71
|
-
cur = k
|
72
|
-
end
|
73
|
-
ret[i.last] = val
|
74
|
-
end
|
75
|
-
block_given? ? ret.reject(&blk) : ret
|
76
|
-
end
|
77
|
-
|
78
|
-
def and(*args)
|
79
|
-
self << '&&'
|
80
|
-
merge(args)
|
81
|
-
end
|
82
|
-
|
83
|
-
def or(*args)
|
84
|
-
self << '||'
|
85
|
-
merge(args)
|
86
|
-
end
|
87
|
-
|
88
|
-
def with(*args, &blk)
|
89
|
-
temp('&&', *args, &blk)
|
90
|
-
end
|
91
|
-
|
92
|
-
def temp(*args, &blk)
|
93
|
-
args.compact!
|
94
|
-
ret = pass(&blk)
|
95
|
-
ret = Set.new(ret.concat(args)).to_a unless args.empty?
|
96
|
-
ret.join(@delim)
|
97
|
-
end
|
98
|
-
|
99
|
-
def done
|
100
|
-
ret = to_s
|
101
|
-
clear
|
102
|
-
ret
|
103
|
-
end
|
104
|
-
|
105
|
-
def to_s
|
106
|
-
pass.join(@delim)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|