squared 0.4.14 → 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.
@@ -15,7 +15,8 @@ module Squared
15
15
  def parse(gem, namespace, ext = [pkg])
16
16
  require gem
17
17
  obj = eval namespace
18
- Array(ext).each { |val| @@mime_obj[val] = [obj, ext] }
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 = Viewer.new(main, name, project: project, **kwargs)
30
+ ret = new(main, name, project: project, **kwargs)
30
31
  ret.instance_eval(&blk) if block_given?
31
32
  ret
32
33
  end
@@ -88,7 +89,7 @@ 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
@@ -128,7 +129,7 @@ module Squared
128
129
  require(gem || type)
129
130
  obj = eval namespace
130
131
  else
131
- Array(ext).each do |val|
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 = Array(ext)).empty?
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(theme, name, args)
173
+ apply_style theme, name, args
173
174
  self
174
175
  end
175
176
 
@@ -212,7 +213,7 @@ module Squared
212
213
  file = nil
213
214
  ext[0] = mime
214
215
  elsif file
215
- keys.unshift(file)
216
+ keys.prepend(file)
216
217
  alt = basepath("#{main}.{#{ext.join(',')}}")
217
218
  file = Dir[alt].first
218
219
  else
@@ -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(.+)( : (?!undefined).+)\z/m, styles: theme[:key] },
246
- { pat: /\A(.+ : )(-?[\d.]+)(\s*)\z/m, styles: theme[:number],
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(.+ : ")(.+)("\s*)\z/m, styles: theme[:string], index: 2 },
249
- { pat: /\A(.+ : \{)(.+)(\}\s*)\z/m, styles: theme[:hash], index: 2 },
250
- { pat: /\A(.+ : \[)(.+)(\]\s*)\z/m, styles: theme[:array], index: 2 },
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(.+ : (?!undefined))([^"\[{].*)\z/m, styles: theme[:value],
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(':').push(command, val)
312
+ args = *name.split(':').append(command, val)
313
313
  if project
314
314
  project.workspace.task_desc(*args)
315
315
  else
@@ -347,7 +347,7 @@ module Squared
347
347
  end
348
348
 
349
349
  def basepath(file)
350
- project ? project.basepath(file) : Pathname.new(file).realdirpath
350
+ project ? project.basepath(file) : Pathname.pwd + file
351
351
  end
352
352
  end
353
353
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.4.14'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -29,7 +29,7 @@ module Squared
29
29
  @impl_project = obj
30
30
  impl_series.base_set(obj)
31
31
  else
32
- kind_project.unshift(obj)
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)
@@ -73,7 +73,7 @@ module Squared
73
73
  end
74
74
 
75
75
  @kind_project = []
76
- @task_exclude = SymSet.new
76
+ @task_exclude = Set.new
77
77
 
78
78
  attr_reader :root, :home, :main, :prefix, :exception, :warning, :pipe, :verbose, :theme, :series, :closed
79
79
 
@@ -94,7 +94,7 @@ module Squared
94
94
  @project = {}
95
95
  @kind = {}
96
96
  @extensions = []
97
- @envname = env_key(@main).freeze
97
+ @envname = @main.gsub(/[^\w]+/, '_').upcase.freeze
98
98
  @pipe = env_pipe(pipe, (ARG[:OUT] && env(ARG[:OUT])) || 1, root: @home)
99
99
  @exception = env_bool exception
100
100
  @verbose = env_bool(verbose, verbose.nil? || verbose.is_a?(String) ? @pipe != 0 : verbose, index: true)
@@ -220,11 +220,11 @@ module Squared
220
220
  if arg.include?(':') || (keys && !keys.include?(arg))
221
221
  task_name(arg)
222
222
  else
223
- /\A#{Regexp.escape(task_name(arg))}:/
223
+ /#{Regexp.escape(arg)}:/
224
224
  end
225
225
  end
226
226
  end
227
- data = Struct::ChainData.new(action, step, ns.call(with), ns.call(before), ns.call(after), sync)
227
+ data = Support::ChainData.new(action, step, ns.call(with), ns.call(before), ns.call(after), sync)
228
228
  (@chain[task_name(task.to_s)] ||= []) << data
229
229
  self
230
230
  end
@@ -278,7 +278,7 @@ module Squared
278
278
  end
279
279
 
280
280
  def banner(*args, command: true, styles: nil, border: nil, group: @group, ref: @ref)
281
- data = { command: command, order: [], styles: check_style(styles, empty: false), border: check_style(border) }
281
+ data = Support::BannerData.new(command, [], check_style(styles, empty: false), check_style(border))
282
282
  args.each do |meth|
283
283
  if meth.is_a?(Array)
284
284
  found = false
@@ -301,26 +301,21 @@ module Squared
301
301
  elsif !Application.attr_banner.include?(meth = meth.to_sym)
302
302
  next
303
303
  end
304
- data[:order] << meth
304
+ data.order << meth
305
305
  end
306
- data = {} if !command && data[:order].empty?
307
306
  if group
308
307
  label = :group
309
- items = Array(group)
308
+ items = as_a group
310
309
  else
311
310
  label = :ref
312
- items = Array(ref || :_)
311
+ items = ref ? as_a(ref) : [:_]
313
312
  end
314
313
  items.each { |val| @banner[label][val.to_sym] = data }
315
314
  self
316
315
  end
317
316
 
318
317
  def add(path, project = nil, **kwargs, &blk)
319
- if @withargs
320
- data = @withargs.dup
321
- data.merge!(kwargs)
322
- kwargs = data
323
- end
318
+ kwargs = @withargs.yield_self { |data| data.dup.update(kwargs) } if @withargs
324
319
  ref = if kwargs.key?(:ref)
325
320
  kwargs = kwargs.dup unless @withargs
326
321
  kwargs.delete(:ref)
@@ -360,14 +355,14 @@ module Squared
360
355
  end
361
356
  .each do |dir, basename, opts|
362
357
  args = kwargs.dup
363
- args.merge!(opts) if opts
358
+ args.update(opts) if opts
364
359
  add(dir, basename, group: val, **args, &blk)
365
360
  end
366
361
  self
367
362
  end
368
363
 
369
364
  def compose(name, &blk)
370
- namespace(task_name(name), &blk)
365
+ namespace(task_name(name), &blk) if block_given?
371
366
  self
372
367
  end
373
368
 
@@ -379,7 +374,7 @@ module Squared
379
374
  def style(obj, *args, target: nil, empty: false)
380
375
  data = nil
381
376
  if target
382
- Array(target).each_with_index do |key, i|
377
+ as_a(target).each_with_index do |key, i|
383
378
  if i == 0
384
379
  break unless (data = __get__(:theme)[key.to_sym])
385
380
  else
@@ -399,7 +394,7 @@ module Squared
399
394
  }
400
395
  data.each do |key, val|
401
396
  key = key.to_s
402
- if key.match?(/\A(\\A|\^)/) || key.match?(/(\\z|\$)\z/)
397
+ if key.start_with?(/(\\A|\^)/) || key.match?(/(\\z|\$)\z/)
403
398
  @describe[:replace] << [Regexp.new(key), val]
404
399
  else
405
400
  @describe[val.is_a?(Regexp) ? :pattern : :alias][key.to_s] = val
@@ -417,7 +412,7 @@ module Squared
417
412
  if ret.empty?
418
413
  ret = @project.select { |_, item| item.ref?(ref) }.map(&:last) if ref
419
414
  if ret.empty? && (path || name)
420
- path &&= rootpath(path)
415
+ path &&= rootpath path
421
416
  name &&= name.to_s
422
417
  proj = @project.find { |_, item| (path && item.path == path) || (name && item.name == name) }&.last
423
418
  ret << proj if proj
@@ -485,7 +480,7 @@ module Squared
485
480
  end
486
481
 
487
482
  def task_namespace(val, first: false)
488
- return unless (ret = val.to_s.split(':')).size > 1
483
+ return nil unless (ret = val.to_s.split(':')).size > 1
489
484
 
490
485
  first ? ret.first : task_join(*ret[0..-2])
491
486
  end
@@ -517,7 +512,7 @@ module Squared
517
512
  obj.allref.each do |ref|
518
513
  next unless obj.has?(key, ref) && (alt = data[ref])
519
514
 
520
- ret = task_resolve(obj, alt)
515
+ ret = task_resolve obj, alt
521
516
  break unless ret.empty?
522
517
  end
523
518
  else
@@ -537,7 +532,7 @@ module Squared
537
532
  end
538
533
 
539
534
  def format_desc(val, opts = nil, arg: 'opts*', before: nil, after: nil, out: false)
540
- return unless TASK_METADATA || out
535
+ return unless TASK_METADATA
541
536
 
542
537
  val = val.split(':') if val.is_a?(String)
543
538
  if before || after || opts
@@ -630,14 +625,6 @@ module Squared
630
625
  Rake::Win32.windows?
631
626
  end
632
627
 
633
- def jruby?
634
- RUBY_ENGINE == 'jruby'
635
- end
636
-
637
- def jruby_win?
638
- jruby? && windows?
639
- end
640
-
641
628
  def docker?
642
629
  !Dir['/.dockerenv', '/docker-*.{sh,d}'].empty?
643
630
  end
@@ -711,7 +698,7 @@ module Squared
711
698
  else
712
699
  step = 0
713
700
  catch :found do
714
- has = ->(c, d) { c.any? { |e| e.is_a?(Regexp) ? d.match?(e) : d == e } }
701
+ has = ->(c, d) { c.any? { |e| e.is_a?(Regexp) ? d.start_with?(e) : d == e } }
715
702
  w = data.with
716
703
  a = data.after
717
704
  b = data.before
@@ -770,7 +757,7 @@ module Squared
770
757
  end
771
758
  end
772
759
  if step == -1
773
- level.unshift(data.action)
760
+ level.prepend(data.action)
774
761
  step = 0
775
762
  elsif step > 0
776
763
  (level[step -= 1] ||= []).concat(data.action)
@@ -792,7 +779,7 @@ module Squared
792
779
  task key do
793
780
  unless failed.empty? && group.empty?
794
781
  puts log_message(Logger::ERROR, *(failed + group.map { |val| val.action }.flatten),
795
- subject: 'failed placement', hint: false)
782
+ subject: 'failed placement', hint: false, pass: true)
796
783
  end
797
784
  cols = level.flatten(1).map(&:size).max
798
785
  level.each_with_index do |grp, n|
@@ -814,7 +801,7 @@ module Squared
814
801
 
815
802
  def script_command(task, val, group, ref, on, &blk)
816
803
  if block_given?
817
- val = Struct::RunData.new(val, blk)
804
+ val = Support::RunData.new(val, blk)
818
805
  elsif !val
819
806
  return self
820
807
  end
@@ -835,9 +822,9 @@ module Squared
835
822
  def script_set(data, group: nil, ref: nil)
836
823
  data.freeze
837
824
  if group
838
- Array(group).each { |val| @script[:group!][val.to_sym] = data }
825
+ as_a(group).each { |val| @script[:group!][val.to_sym] = data }
839
826
  elsif ref
840
- Array(ref).each { |val| @script[:ref!][val.to_sym] = data }
827
+ as_a(ref).each { |val| @script[:ref!][val.to_sym] = data }
841
828
  else
842
829
  @script[:ref!][:''] = data
843
830
  end
@@ -860,7 +847,7 @@ module Squared
860
847
  def root?(path, pass: [])
861
848
  return false unless path.directory?
862
849
 
863
- path.children.each do |c|
850
+ path.each_child do |c|
864
851
  name = c.basename.to_s
865
852
  next if c.to_s == __FILE__ || (@main == name && c.directory? && c.empty?) || pass.any? { |val| val == name }
866
853
 
@@ -870,14 +857,14 @@ module Squared
870
857
  end
871
858
 
872
859
  def script?(state, target: nil, pat: nil, group: nil, ref: baseref, global: false)
873
- data = script_find(ref, group)
860
+ data = script_find ref, group
874
861
  if global
875
862
  target = data[:script] || data[:run] if target.nil?
876
863
  pat = data[state] if pat.nil?
877
864
  end
878
865
  return false if state == :prod && data[:dev] == true && data[:global]
879
866
 
880
- target && pat.is_a?(Regexp) ? Array(target).any? { |val| val.match?(pat) } : pat == true
867
+ target && pat.is_a?(Regexp) ? as_a(target).any?(pat) : pat == true
881
868
  end
882
869
 
883
870
  def scriptobj