squared 0.6.2 → 0.6.4

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.
@@ -3,6 +3,7 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  class Application
6
+ include Enumerable
6
7
  include Common::Format
7
8
  include Utils
8
9
  include Support::Variables
@@ -23,7 +24,7 @@ module Squared
23
24
  impl_series.base_set(obj)
24
25
  else
25
26
  kind_project.unshift(obj)
26
- obj.tasks&.each { |task| impl_series.add(task, obj) }
27
+ impl_series.extend_set(obj)
27
28
  end
28
29
  if (args = obj.batchargs)
29
30
  impl_series.batch(*args)
@@ -49,10 +50,31 @@ module Squared
49
50
  @task_exclude.merge(args.map!(&:to_sym))
50
51
  end
51
52
 
52
- def series_wrap(app)
53
+ def register(app)
54
+ @session << app
53
55
  impl_series.new(app, exclude: @task_exclude.to_a)
54
56
  end
55
57
 
58
+ def load_ref(path, gem: nil)
59
+ if gem
60
+ unless @gemsdir
61
+ IO.popen('bundle env').each do |val|
62
+ next unless val =~ /^\s+Gem Home\s+(.+)$/
63
+
64
+ @gemsdir = File.join($1, 'gems')
65
+ break
66
+ end
67
+ end
68
+ dir = if gem.match?(/-\d+(?:\.|$)/)
69
+ gem
70
+ else
71
+ Dir.glob("#{gem}-*", base: @gemsdir).pop
72
+ end
73
+ path = File.join(@gemsdir, dir, path) if dir
74
+ end
75
+ @load_project.unshift(path.cleanpath.to_s) if (path = Pathname.new(path)).absolute? && path.exist?
76
+ end
77
+
56
78
  def baseref
57
79
  impl_project.ref
58
80
  end
@@ -61,11 +83,15 @@ module Squared
61
83
  super[/[^:]+\z/, 0]
62
84
  end
63
85
 
64
- attr_reader :kind_project
86
+ alias series_wrap register
87
+
88
+ attr_reader :kind_project, :load_project, :session
65
89
  attr_accessor :impl_series, :impl_project, :attr_banner
66
90
  end
67
91
 
68
92
  @kind_project = []
93
+ @load_project = [File.expand_path('project', __dir__)]
94
+ @session = []
69
95
  @task_exclude = Set.new
70
96
 
71
97
  attr_reader :root, :home, :main, :prefix, :theme, :series, :closed
@@ -84,7 +110,7 @@ module Squared
84
110
  @home.mkpath rescue nil
85
111
  @root = @home.parent
86
112
  @prefix = prefix
87
- @series = Application.series_wrap(self)
113
+ @series = Application.register(self)
88
114
  @project = {}
89
115
  @kind = hashlist
90
116
  @extensions = []
@@ -138,6 +164,12 @@ module Squared
138
164
  puts bord, msg, bord
139
165
  end
140
166
 
167
+ def each(&blk)
168
+ return to_enum(:each) unless block_given?
169
+
170
+ @project.each_value(&blk)
171
+ end
172
+
141
173
  def build(parallel: [], pass: nil, **kwargs)
142
174
  return self unless enabled? && !@closed
143
175
 
@@ -148,7 +180,8 @@ module Squared
148
180
  parallel.reject { |val| kwargs[:pattern] << val if val.is_a?(Regexp) }.map!(&:to_s)
149
181
  end
150
182
  @pass[:pattern].concat(pass.map { |val| val.is_a?(Regexp) ? val : val.to_s }) if pass
151
- @project.each_value do |proj|
183
+ series.reset
184
+ each do |proj|
152
185
  if proj.enabled?
153
186
  proj.populate(series.keys.dup, **kwargs)
154
187
  elsif proj.enabled?(base: false)
@@ -330,11 +363,12 @@ module Squared
330
363
  name = task_name "#{project}-#{index}"
331
364
  end
332
365
  proj = ((if !ref.is_a?(Class)
366
+ require_project ref
333
367
  Application.find(ref, path: path)
334
368
  elsif ref < Project::Base
335
369
  ref
336
370
  end) || @kind[name]&.last || Project::Base).new(self, path, name, **kwargs)
337
- proj.__send__(:index_set, @project.size)
371
+ proj.__send__(:index_set, size)
338
372
  @project[name] = proj
339
373
  __get__(:project)[name] = proj unless kwargs[:private]
340
374
  proj.instance_eval(&blk) if block_given?
@@ -348,11 +382,11 @@ module Squared
348
382
  basename = dir.basename.to_s
349
383
  [dir, basename, override[basename.to_sym]]
350
384
  end
351
- .each do |dir, basename, opts|
352
- args = kwargs.dup
353
- args.update(opts) if opts
354
- add(dir, basename, group: val, **args, &blk)
355
- end
385
+ .each do |dir, basename, opts|
386
+ args = kwargs.dup
387
+ args.update(opts) if opts
388
+ add(dir, basename, group: val, **args, &blk)
389
+ end
356
390
  self
357
391
  end
358
392
 
@@ -406,18 +440,21 @@ module Squared
406
440
  end
407
441
 
408
442
  def find(path = nil, name: nil, group: nil, ref: nil, &blk)
409
- ret = group ? @project.select { |_, item| item.group == group }.map(&:last) : []
443
+ return @project.values.find(&blk) if block_given? && !path && !name && !group && !ref
444
+
445
+ ret = group ? select { |item| item.group == group } : []
410
446
  if path.is_a?(Symbol)
411
447
  ref ||= path
412
448
  path = nil
413
449
  end
414
450
  if ret.empty?
415
- ret = @project.select { |_, item| item.ref?(ref) }.map(&:last) if ref
451
+ ret = select { |item| item.ref?(ref) } if ref
416
452
  if ret.empty? && (path || name)
417
453
  path &&= rootpath path
418
454
  name &&= name.to_s
419
- proj = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last
420
- ret << proj if proj
455
+ if (proj = find { |item| (path && item.path == path) || (name && item.name == name) })
456
+ ret << proj
457
+ end
421
458
  end
422
459
  end
423
460
  return (group || ref ? ret : ret.first) unless block_given?
@@ -453,7 +490,7 @@ module Squared
453
490
  if @describe
454
491
  val = name || task_join(*args)
455
492
  found = false
456
- replace = lambda do |data, out|
493
+ sub = lambda do |data, out|
457
494
  index = data.size
458
495
  data.to_a.reverse_each { |group| out.sub!("%#{index -= 1}", group) }
459
496
  out
@@ -461,7 +498,7 @@ module Squared
461
498
  @describe[:replace].each do |pat, tmpl|
462
499
  next unless val =~ pat
463
500
 
464
- val = replace.call($~, tmpl.dup)
501
+ val = sub.call($~, tmpl.dup)
465
502
  found = true
466
503
  end
467
504
  if (out = @describe[:alias][val])
@@ -471,7 +508,7 @@ module Squared
471
508
  @describe[:pattern].each do |key, pat|
472
509
  next unless val =~ pat
473
510
 
474
- val = replace.call($~, key.dup)
511
+ val = sub.call($~, key.dup)
475
512
  found = true
476
513
  break
477
514
  end
@@ -579,7 +616,7 @@ module Squared
579
616
  end
580
617
 
581
618
  def enabled?
582
- !@extensions.empty? || @project.values.any? { |proj| proj.enabled?(base: false) }
619
+ !@extensions.empty? || any? { |proj| proj.enabled?(base: false) }
583
620
  end
584
621
 
585
622
  def task_base?(key)
@@ -591,7 +628,7 @@ module Squared
591
628
  end
592
629
 
593
630
  def task_include?(obj, key, ref = nil)
594
- return false if @series.exclude?(key)
631
+ return false if series.exclude?(key)
595
632
 
596
633
  task_base?(key) ? obj.has?(key, ref || baseref) : task_extend?(obj, key)
597
634
  end
@@ -726,7 +763,7 @@ module Squared
726
763
  a = data.after
727
764
  b = data.before
728
765
  level.each_with_index do |tasks, k|
729
- with = lambda do |n|
766
+ ac = lambda do |n|
730
767
  tasks.insert(n, *data.action)
731
768
  sync << tasks
732
769
  data.action.clear
@@ -735,14 +772,14 @@ module Squared
735
772
  index = k if w && has.call(w, v1)
736
773
  if a && has.call(a, v1)
737
774
  if index
738
- with.call(l.succ)
775
+ ac.call(l.succ)
739
776
  throw :found
740
777
  else
741
778
  index = k.succ
742
779
  end
743
780
  elsif b && has.call(b, v1)
744
781
  if index
745
- with.call(l)
782
+ ac.call(l)
746
783
  throw :found
747
784
  else
748
785
  index = k.pred
@@ -751,10 +788,10 @@ module Squared
751
788
  if a || b
752
789
  tasks.each_with_index do |v2, m|
753
790
  if a && has.call(a, v2)
754
- with.call(m.succ)
791
+ ac.call(m.succ)
755
792
  throw :found
756
793
  elsif b && has.call(b, v2)
757
- with.call(m)
794
+ ac.call(m)
758
795
  throw :found
759
796
  end
760
797
  end
@@ -865,6 +902,18 @@ module Squared
865
902
  end
866
903
  end
867
904
 
905
+ def require_project(ref)
906
+ return unless ref.is_a?(Symbol) && Application.kind_project.none? { |proj| proj.ref == ref }
907
+
908
+ name = ref.to_s
909
+ Application.load_project.each do |val|
910
+ next unless File.exist?("#{rb = File.join(val, name)}.rb")
911
+
912
+ require_relative rb
913
+ break
914
+ end
915
+ end
916
+
868
917
  def root?(path, pass: [])
869
918
  return false unless path.directory?
870
919