squared 0.4.19 → 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.
@@ -4,7 +4,7 @@ module Squared
4
4
  module Workspace
5
5
  module Project
6
6
  class Ruby < Git
7
- GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb gems.rb Isolate].freeze
7
+ GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
8
8
  DIR_RUBY = (GEMFILE + Rake::Application::DEFAULT_RAKEFILES + ['README.rdoc']).freeze
9
9
  OPT_RUBY = {
10
10
  ruby: %w[0=im? a c e=q E=bm F=qm i=bm? I=pm l n p r=bm s S w W=bm? x=pm? d|debug jit rjit v|verbose y|yydebug
@@ -25,8 +25,8 @@ module Squared
25
25
  common: %w[no-color V|verbose retry=i].freeze,
26
26
  install: %w[frozen no-cache no-prune system binstubs=p? path=p standalone=q? target-rbconfig=p trust-policy=b
27
27
  with=q without=q].freeze,
28
- install_base: %w[force full-index quiet redownload retry gemfile=p j|jobs=i].freeze,
29
- update: %w[conservative local pre ruby strict bundler=b? g|group=q source=b].freeze,
28
+ install_base: %w[full-index quiet retry gemfile=p j|jobs=i].freeze,
29
+ update: %w[conservative local pre redownload ruby strict bundler=b? g|group=q source=b].freeze,
30
30
  outdated: %w[filter-major filter-minor filter-patch groups local parseable pre only-explicit strict
31
31
  update-strict g|group=q source=b].freeze,
32
32
  exec: %w[gemfile=p].freeze,
@@ -81,7 +81,7 @@ module Squared
81
81
  'install' => %i[redownload local prefer-local].freeze,
82
82
  'update' => %i[patch minor major all].freeze,
83
83
  'outdated' => %i[patch minor major].freeze,
84
- 'gem' => %i[install uninstall update pristine outdated build push exec].freeze,
84
+ 'gem' => %i[install uninstall update pristine outdated push build exec].freeze,
85
85
  'ruby' => %i[file script version].freeze,
86
86
  'exec' => nil,
87
87
  'cache' => nil,
@@ -91,7 +91,7 @@ module Squared
91
91
  'irb' => nil
92
92
  })
93
93
 
94
- def initialize(*, autodetect: false, gemspec: nil, **kwargs)
94
+ def initialize(*, autodetect: false, **kwargs)
95
95
  super
96
96
  if @pass.include?(Ruby.ref)
97
97
  initialize_ref Ruby.ref
@@ -102,17 +102,11 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- @gemfile = if gemspec == false
106
- false
107
- elsif gemspec
108
- path + (gemspec.include?('.') ? gemspec : "#{gemspec}.gemspec")
109
- elsif (gemspec = path + "#{name}.gemspec").exist? || (gemspec = path + "#{project}.gemspec").exist?
110
- gemspec
111
- end
112
- return if !@output[0].nil? || !@copy.nil? || version || @autodetect || !rakefile
105
+ @rakelist = nil
106
+ return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
113
107
 
114
108
  begin
115
- File.foreach(rakefile) do |line|
109
+ File.foreach(file) do |line|
116
110
  next unless line.match?(%r{\brequire\s+(["'])bundler/gem_tasks\1})
117
111
 
118
112
  cmd = bundle_output('exec rake').to_s
@@ -132,59 +126,54 @@ module Squared
132
126
 
133
127
  def populate(*, **)
134
128
  super
135
- return unless (outdated? && ref?(Ruby.ref)) || @only
129
+ return unless outdated? && ref?(Ruby.ref)
136
130
 
137
131
  namespace name do
138
132
  Ruby.subtasks do |action, flags|
139
- next if task_pass?(action)
133
+ next if @pass.include?(action)
140
134
 
141
135
  if flags.nil?
142
136
  case action
143
137
  when 'rake'
144
138
  next unless rakefile
145
139
 
146
- format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
140
+ format_desc action, nil, 'tasks*,opts*|^index|#,pattern*'
147
141
  task action, [:command] do |_, args|
148
142
  if args.command == '#'
149
- format_list(raketasks, "rake[#{indexchar}N]", 'tasks', grep: args.extras, from: rakefile,
150
- each: ->(val) { val[0] + val[1].to_s })
151
- else
152
- args, opts = args.to_a.partition { |val| indexitem(val) }
153
- if args.empty?
154
- rake(opts: opts)
143
+ format_list(read_rakefile, 'rake[^N]', 'tasks', grep: args.extras, from: rakefile.to_s,
144
+ each: ->(val) { val[0] + val[1].to_s })
145
+ elsif (n, opts = indexitem(args.command))
146
+ list = read_rakefile
147
+ if (item = list[n - 1])
148
+ cmd = opts ? "#{opts} #{item.first}" : item.first
149
+ elsif exception
150
+ indexerror n, list
155
151
  else
156
- tasks = raketasks
157
- while (n, pre = indexitem(args.shift))
158
- if (item = tasks[n - 1])
159
- cmd = pre ? "#{pre} #{item.first}" : item.first
160
- elsif exception
161
- indexerror n, tasks
162
- else
163
- log.warn "rake task #{n} of #{tasks.size} (out of range)"
164
- next
165
- end
166
- if opts.empty?
167
- rake cmd
168
- else
169
- rake(cmd + shell_escape("[#{opts.join(',')}]"))
170
- opts.clear
171
- end
172
- end
152
+ log.warn "rake task #{n} of #{list.size} (out of range)"
153
+ next
173
154
  end
155
+ rake(args.extras.empty? ? cmd : cmd + shell_escape("[#{args.extras.join(',')}]"))
156
+ else
157
+ rake(opts: args.to_a)
174
158
  end
175
159
  end
176
160
  when 'irb'
161
+ next unless (spec = basepath("#{project}.gemspec") || basepath("#{name}.gemspec"))
162
+ next unless basepath('lib').join("#{gemname = stripext(spec)}.rb").exist?
163
+
177
164
  format_desc action, nil, 'opts*,args*|:'
178
165
  task action do |_, args|
179
166
  args = args.to_a
180
- name = gemlib.any? { |file| basepath(file).join("#{gemname}.rb").exist? } ? gemname : nil
181
- irb(name, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
167
+ if args.last == ':'
168
+ args.pop
169
+ load = readline('Enter file and arguments', force: false)
170
+ end
171
+ irb(gemname, args, load: load)
182
172
  end
183
173
  else
184
- format_desc(action, nil, 'opts*', before: case action
185
- when 'cache', 'check' then nil
186
- else 'command+'
187
- end)
174
+ format_desc(action, nil, OPT_BUNDLE[action.to_sym], after: case action
175
+ when 'cache', 'check' then nil
176
+ else 'command+' end)
188
177
  task action do |_, args|
189
178
  bundle(action, *args.to_a)
190
179
  end
@@ -206,24 +195,20 @@ module Squared
206
195
  case (filter = args.semver)
207
196
  when 'major', 'minor', 'patch', 'interactive', 'i'
208
197
  filter = 'interactive' if filter == 'i'
209
- args = args.extras
198
+ args = args.to_a.drop(1)
210
199
  else
211
200
  filter = nil
212
201
  args = args.to_a
213
202
  end
214
203
  gem!(flag, args, filter: filter)
215
204
  end
216
- when :build, :push, :exec, :update
217
- format_desc(action, flag, 'opts*', after: case flag
218
- when :exec then 'command,args*'
219
- when :push then 'file?'
220
- when :update then 'name*'
221
- end)
205
+ when :build, :push, :exec
206
+ format_desc(action, flag, 'opts*', before: flag == :exec ? 'command,args*' : nil)
222
207
  task flag do |_, args|
223
208
  gem! flag, args.to_a
224
209
  end
225
210
  else
226
- format_desc(action, flag, 'opts*', after: flag == :pristine ? 'name*|name?@version' : 'name*')
211
+ format_desc action, flag, "opts*,name+#{flag == :pristine ? '|name?@version' : ''}"
227
212
  task flag do |_, args|
228
213
  args = param_guard(action, flag, args: args.to_a)
229
214
  gem! flag, args
@@ -235,18 +220,19 @@ module Squared
235
220
  format_desc action, flag, 'path,opts*,args*'
236
221
  task flag, [:rb] do |_, args|
237
222
  file = args.rb
238
- args = args.extras
223
+ args = args.to_a.drop(1)
239
224
  unless file && !file.include?('*')
240
- file, opts, prog = choice_index('Select a file', Dir.glob(file || (path + '*.rb')),
241
- values: (file ? [] : ['Options']) << 'Arguments',
242
- force: true, series: !args.include?('v'))
225
+ values = ['Arguments']
226
+ values.prepend('Options') unless file
227
+ file, opts, extra = choice_index('Select a file', Dir.glob(file || '*.rb', base: path),
228
+ values: values, force: true, series: !args.include?('v'))
243
229
  if file
244
- prog = opts
230
+ extra = opts
245
231
  else
246
232
  args.concat(OptionPartition.strip(opts))
247
233
  end
248
234
  end
249
- ruby(flag, args, file: file, args: prog)
235
+ ruby(flag, args, file: file, args: extra)
250
236
  end
251
237
  when :script
252
238
  format_desc action, flag, 'opts*,args*'
@@ -282,7 +268,7 @@ module Squared
282
268
  end
283
269
  end
284
270
 
285
- def copy(from: gemlib, into: @gemdir, override: false, **kwargs)
271
+ def copy(from: 'lib', into: @gemdir, override: false, **kwargs)
286
272
  glob = kwargs[:include]
287
273
  pass = kwargs[:exclude]
288
274
  if @copy && !override
@@ -300,8 +286,8 @@ module Squared
300
286
  on :first, :copy
301
287
  dest = Pathname.new(into).realpath
302
288
  print_item unless @output[0] || task_invoked?(/^copy(?::#{Ruby.ref}|$)/)
303
- glob = Array(glob || '**/*')
304
- Array(from).each_with_index do |val, i|
289
+ glob = as_a(glob || '**/*')
290
+ as_a(from).each_with_index do |val, i|
305
291
  a = path + val
306
292
  b = dest + val
307
293
  c = glob[i] || glob.first
@@ -309,7 +295,9 @@ module Squared
309
295
  begin
310
296
  copy_dir(a, b, c, pass: pass, verbose: verbose)
311
297
  rescue StandardError => e
312
- on_error e, :copy
298
+ log.error e
299
+ ret = on(:error, :copy, e)
300
+ raise if exception && ret != true
313
301
  end
314
302
  end
315
303
  on :last, :copy
@@ -323,7 +311,7 @@ module Squared
323
311
  end
324
312
  log.info cmd.to_s
325
313
  on :first, :outdated
326
- banner = format_banner(cmd.to_s)
314
+ banner = format_banner cmd.to_s
327
315
  print_item banner if sync
328
316
  pwd_set(from: :outdated) do
329
317
  start = 0
@@ -414,7 +402,7 @@ module Squared
414
402
  end
415
403
  if found > 0
416
404
  begin
417
- if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])(.+?)\1|remote:\s+(\S+))/
405
+ if major == 0 && dependfile.read =~ /\b(?:source\s+(["'])((?~\1))\1|remote:\s+(\S+))/
418
406
  status = ($2 || $3).chomp('/')
419
407
  right = true
420
408
  end
@@ -433,23 +421,14 @@ module Squared
433
421
 
434
422
  def install(flag, opts = [])
435
423
  bundle_session 'install', "--#{flag}"
436
- op = append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:install] + OPT_BUNDLE[:common]
437
- if op.arg?('force')
438
- op.delete('--force')
439
- if flag != :redownload
440
- op << '--redownload'
441
- elsif (lock = basepath('Gemfile.lock')).exist?
442
- config = basepath('.bundle', 'config')
443
- lock.delete unless config.exist? && config.read.match?(/\bBUNDLE_FROZEN:\s+"true"/)
444
- end
445
- end
424
+ append_bundle opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:install] + OPT_BUNDLE[:common]
446
425
  run_rb(from: :install)
447
426
  end
448
427
 
449
428
  def update(flag, opts = [])
450
429
  bundle_session 'update', "--#{flag}"
451
430
  append_bundle(opts, OPT_BUNDLE[:install_base] + OPT_BUNDLE[:update] + OPT_BUNDLE[:common],
452
- append: flag == :all ? nil : /\A[a-z-]+=/)
431
+ append: flag == :all ? nil : /\A[a-z\-]+=/)
453
432
  run_rb(from: :update)
454
433
  end
455
434
 
@@ -458,11 +437,11 @@ module Squared
458
437
  when :file, :script
459
438
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
460
439
  if file
461
- op.unshift(shell_quote(path + file))
440
+ op.extras.prepend(shell_quote(path + file))
462
441
  elsif command
463
442
  op << quote_option('e', command, option: false)
464
443
  end
465
- op.push(args) if (args = ENV.fetch('RUBY_ARGS', args))
444
+ op.extras << args if (args = ENV.fetch('RUBY_ARGS', args))
466
445
  op.append(delim: true, escape: false, quote: false) unless op.empty?
467
446
  when :version
468
447
  pwd_set do
@@ -485,8 +464,9 @@ module Squared
485
464
  when 'rvm'
486
465
  `rvm current`[/^\S+/, 0]
487
466
  when 'rbenv'
488
- name = `rbenv version-name`
489
- name =~ SEM_VER ? "ruby #{name}" : name
467
+ `rbenv version-name`.yield_self do |name|
468
+ name.match?(SEM_VER) ? "ruby #{name}" : name
469
+ end
490
470
  when 'chruby.sh'
491
471
  chruby = session_output 'source', val
492
472
  `#{chruby.with('ruby --version')}`
@@ -497,14 +477,12 @@ module Squared
497
477
  ver = nil
498
478
  `ruby --version`
499
479
  end)
500
- break if workspace.windows?
501
-
502
480
  unless val.empty?
503
481
  out << trim.call(case cmd
504
482
  when 'chruby.sh'
505
483
  `#{chruby.with('chruby --version')}`.sub(':', '')
506
484
  when 'install'
507
- "asdf #{`asdf version`.sub(/^v/, '')}"
485
+ "asdf #{`asdf version`.delete_prefix('v')}"
508
486
  else
509
487
  `#{cmd} --version`
510
488
  end)
@@ -547,6 +525,8 @@ module Squared
547
525
  case flag
548
526
  when :outdated
549
527
  cmd << gempwd << 'outdated'
528
+ when :push
529
+ cmd << 'push' << project
550
530
  else
551
531
  cmd << flag
552
532
  end
@@ -555,9 +535,12 @@ module Squared
555
535
  case flag
556
536
  when :install, :update
557
537
  list.concat(OPT_GEM[:install_base])
538
+ first = ['=']
539
+ when :uninstall, :pristine
540
+ first = ['=']
558
541
  end
559
542
  cmd.merge(preopts)
560
- op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag])
543
+ op = OptionPartition.new(opts, list, cmd, project: self, no: OPT_GEM[:no][flag], first: first)
561
544
  op.each do |opt|
562
545
  if opt =~ op.values
563
546
  case $1
@@ -581,7 +564,7 @@ module Squared
581
564
  minor = 0
582
565
  patch = 0
583
566
  update = []
584
- pwd_set(pass: !gempwd.nil?, from: from) do
567
+ pwd_set(pass: !pwd.nil?, from: from) do
585
568
  items = [[%w[Gem Current Latest], nil]]
586
569
  IO.popen(cmd.done).each do |line|
587
570
  if line =~ /^(\S+) \((\S+) < ([^)]+)\)$/
@@ -658,8 +641,7 @@ module Squared
658
641
  styles = %i[yellow]
659
642
  pat = pat.last
660
643
  end
661
- b = b.rjust(e)
662
- b = sub_style(b, *colormap(styles), pat: pat, index: 2)
644
+ b = sub_style(b.rjust(e), *colormap(styles), pat: pat, index: 2)
663
645
  h = sub_style(c.rjust(f), styles: latest.flatten.compact, pat: pat, index: 2)
664
646
  j += 1
665
647
  if queue
@@ -677,15 +659,15 @@ module Squared
677
659
  else
678
660
  unless update.empty?
679
661
  cmd = gem_output 'update', '-f'
680
- if (val = option('document', prefix: 'gem', ignore: false))
662
+ option('document', prefix: 'gem', ignore: false) do |val|
681
663
  cmd << case val
682
664
  when '0', 'false'
683
665
  '--no-document'
684
666
  else
685
- basic_option('document', val)
667
+ basic_option 'document', val
686
668
  end
687
669
  end
688
- if (val = option('user-install', prefix: 'gem', ignore: false))
670
+ option('user-install', prefix: 'gem', ignore: false) do |val|
689
671
  cmd << case val
690
672
  when '0', 'false'
691
673
  '--no-user-install'
@@ -696,83 +678,58 @@ module Squared
696
678
  cmd.merge(update)
697
679
  run(cmd, banner: false, from: :'gem:update')
698
680
  end
699
- print_status(major, minor, patch, from: :outdated)
681
+ unless stdin?
682
+ status = print_footer("major #{major} / minor #{minor} / patch #{patch}", right: true).split("\n")
683
+ status[1] = status[1]
684
+ .yield_self do |s|
685
+ sub_style(s, pat: /^( +major )(\d+)(.+)$/, styles: theme[:major], index: 2)
686
+ end
687
+ .yield_self do |s|
688
+ sub_style(s, pat: /^(.+)(minor )(\d+)(.+)$/, styles: theme[:active], index: 3)
689
+ end
690
+ puts status
691
+ end
700
692
  end
701
693
  on :last, from
702
694
  return
703
- when :build
704
- if op.empty?
705
- op.add_path(gemfile)
706
- else
707
- op.add_path(op.shift)
708
- .clear(pass: false)
709
- end
710
- when :push
711
- if op.empty?
712
- file = path + (if (spec = gemspec)
713
- "#{spec.name}-#{spec.version}.gem"
714
- else
715
- choice_index('Select a file', Dir.glob('*.gem', base: path), force: true)
716
- end)
717
- else
718
- file = path + op.shift
719
- raise_error('gem not found', hint: file) unless file.exist?
720
- raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
695
+ when :build, :push
696
+ if !op.empty?
697
+ if flag == :build && op.size == 1
698
+ op << shell_quote(path + op.first)
699
+ else
700
+ raise_error("unknown args: #{op.join(', ')}", hint: flag)
701
+ end
702
+ elsif flag == :build
703
+ spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
704
+ op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
721
705
  end
722
- op.add_path(file)
723
- run_rb(from: from, interactive: "Push #{sub_style(gemname, styles: theme[:active])}")
724
- return
725
706
  when :exec
726
- min = if op.arg?('g', 'gem')
727
- 1
728
- elsif op.empty?
729
- op << basic_option('gem', gemname)
730
- 1
731
- else
732
- op << op.shift
733
- 0
734
- end
735
- if (args = command_args(op.extras, min: min, force: min == 1 && op.empty?))
707
+ raise_error('missing command', hint: flag) if op.empty?
708
+ op << basic_option('gem', project) unless op.arg?('g', 'gem')
709
+ if (args = command_args(op.extras))
736
710
  op.push(args)
737
711
  end
738
- op.append(quote: false)
739
- when :update
740
- unless op.arg?('system')
741
- op.push(gemname) if op.empty?
742
- op.adjoin
743
- end
744
- op.clear(errors: true)
712
+ op.append(delim: true, quote: false)
745
713
  else
746
- raise_error('missing gemname', hint: flag) if op.empty?
747
- case flag
748
- when :install, :uninstall, :pristine
749
- post = readline('Enter command [args]', force: true) if flag == :install && op.remove(':')
714
+ raise_error('missing gemname', hint: flag) if op.empty? && !op.arg?('system')
715
+ if flag == :pristine
750
716
  if op.arg?('all')
751
- if flag == :pristine
752
- append_repeat 'skip', op.extras
753
- op.reset
754
- else
755
- op.clear
756
- end
757
- elsif (n = op.extras.find_index { |val| val.match?(/(\A|[a-z])@\d/) })
758
- items = op.extras.to_a
759
- name = items.delete_at(n)
760
- if (n = name.index('@')) == 0
761
- pre = gemname
717
+ append_repeat 'skip', op.extras
718
+ op.extras.clear
719
+ elsif (n = op.first.index('@'))
720
+ name = op.shift
721
+ if n == 0
722
+ op << project
762
723
  ver = name[1..-1]
763
724
  else
764
- pre = name[0, n]
765
- ver = name[(n + 1)..-1]
725
+ op << shell_escape(name[0, n])
726
+ ver = name[n + 1..-1]
766
727
  end
767
- op.adjoin(pre, shell_option('version', ver))
768
- .clear(items)
769
- .reset
770
- elsif flag != :install
771
- op.adjoin
728
+ op << shell_option('version', ver)
729
+ op.clear
772
730
  end
773
731
  end
774
732
  op.append.clear(errors: true)
775
- op << '--' << post if post
776
733
  end
777
734
  run_rb(from: from)
778
735
  end
@@ -813,14 +770,14 @@ module Squared
813
770
  run_s(args, banner: false, from: :rake)
814
771
  end
815
772
 
816
- def irb(name = nil, opts = [], path: gemlib, args: nil)
773
+ def irb(name, opts = [], path: @path + 'lib', load: nil)
817
774
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
818
- r = args ? [] : ['bundler/setup']
819
- r << name if name
775
+ r = as_a name
776
+ r.prepend('bundler/setup') unless load
820
777
  r.each { |val| op << shell_option('r', val, merge: true) }
821
- Array(path).each { |val| op << quote_option('I', val, merge: true) }
822
- if args
823
- op << '--' << args
778
+ as_a(path).each { |val| op << quote_option('I', val, merge: true) }
779
+ if load
780
+ op << '--' << load
824
781
  op.clear
825
782
  else
826
783
  op.append(delim: true)
@@ -828,20 +785,6 @@ module Squared
828
785
  run(banner: false)
829
786
  end
830
787
 
831
- def gemspec
832
- return @gemspec unless @gemspec.nil?
833
-
834
- @gemspec = if (file = gemfile)
835
- Gem::Specification.load(file.to_s) rescue false
836
- else
837
- false
838
- end
839
- end
840
-
841
- def gemname
842
- @gemname ||= ((spec = gemspec) ? spec.name : project)
843
- end
844
-
845
788
  def depend?
846
789
  @depend != false && (!@depend.nil? || outdated?)
847
790
  end
@@ -850,7 +793,7 @@ module Squared
850
793
  return true if super || (@copy.is_a?(Hash) && copy.fetch(:into, nil))
851
794
  return gemdir? if @gemdir
852
795
 
853
- if version
796
+ if @version
854
797
  begin
855
798
  case @autodetect
856
799
  when 'rvm'
@@ -875,46 +818,43 @@ module Squared
875
818
  return false unless @autodetect
876
819
 
877
820
  set = lambda do |val, path|
878
- if (ver = version) && ver != val
879
- log.warn "using version #{val} (given #{ver})"
880
- end
881
- self.version = val
821
+ log.warn "using version #{val} (given #{@version})" if @version && @version != val
822
+ @version = val
882
823
  @gemdir = Pathname.new(path.strip) + gempath
883
824
  end
884
- if version
885
- opt = gempwd
886
- pwd_set(pass: !opt.nil?) do
887
- out = `#{gem_output(opt, 'list --local -d', gemname)}`
888
- if out =~ /#{Regexp.escape(gemname)} \(([^)]+)\)/
825
+ if @version
826
+ pwd = gempwd
827
+ pwd_set(pass: !pwd.nil?) do
828
+ out = `#{gem_output(pwd, 'list --local -d', project)}`
829
+ if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
889
830
  $1.split(/\s*,\s*/)
890
- .unshift(@version)
831
+ .prepend(@version)
891
832
  .uniq
892
833
  .each do |val|
893
834
  next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
894
835
 
895
836
  set.call(val, $1)
896
- return gemdir? if @gemdir
837
+ break
897
838
  end
898
839
  end
899
840
  end
900
- @gemdir = Pathname.new(Gem.dir) + gempath
901
- else
841
+ end
842
+ unless @gemdir
902
843
  parse = lambda do |path|
903
844
  next unless path
904
845
 
905
- lib = Regexp.new(['', 'gems', "#{gemname}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
846
+ lib = Regexp.new(['', 'gems', "#{project}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
906
847
  if (ver = path[lib, 1]) && (val = path[/\A(.+)#{gempath(ver[1])}/, 1])
907
848
  set.call(ver, val)
908
849
  end
909
850
  end
910
851
  if RUBY_VERSION >= '2.6'
911
852
  target = RUBY_VERSION.start_with?('2.6') ? RubyVM : $LOAD_PATH
912
- parse.call(target.resolve_feature_path(gemname)&.last)
913
- end
914
- if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', gemname)}`) }
915
- raise_error 'gems directory not found'
853
+ parse.call(target.resolve_feature_path(project)&.last)
916
854
  end
855
+ pwd_set { parse.call(`#{bundle_output('show', project)}`) } unless @gemdir
917
856
  end
857
+ raise_error('parse failed', hint: @version || 'path') unless @gemdir
918
858
  rescue StandardError => e
919
859
  log.error e
920
860
  @version = nil
@@ -931,7 +871,7 @@ module Squared
931
871
  private
932
872
 
933
873
  def run_rb(**kwargs)
934
- run(banner: !@session&.include?('--quiet'), **kwargs)
874
+ run(banner: !@session.include?('--quiet'), **kwargs)
935
875
  end
936
876
 
937
877
  def append_bundle(opts, list, target: @session, append: nil)
@@ -951,7 +891,6 @@ module Squared
951
891
  else
952
892
  op.clear
953
893
  end
954
- op
955
894
  end
956
895
 
957
896
  def ruby_session(*cmd, **kwargs)
@@ -993,73 +932,54 @@ module Squared
993
932
  session_output('rake', *cmd, **kwargs)
994
933
  end
995
934
 
935
+ def read_rakefile
936
+ return @rakelist if @rakelist
937
+
938
+ ret = []
939
+ pwd = rakepwd
940
+ pwd_set(pass: !pwd.nil?) do
941
+ IO.popen(rake_output(pwd, '-AT').to_s).each do |line|
942
+ next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
943
+
944
+ ret << [$1, $2]
945
+ end
946
+ end
947
+ @rakelist = ret
948
+ end
949
+
996
950
  def preopts
997
951
  verbosetype > 1 && !session_arg?('quiet') ? ['--verbose'] : []
998
952
  end
999
953
 
954
+ def gemdir?
955
+ !@gemdir.nil? && @gemdir.exist? && !@gemdir.empty?
956
+ end
957
+
1000
958
  def variables
1001
959
  (super + %i[version autodetect]).freeze
1002
960
  end
1003
961
 
1004
962
  def rakefile
1005
- return @rakefile unless @rakefile.nil?
963
+ return unless (file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? })
1006
964
 
1007
- file = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }
1008
- @rakefile = file ? path + file : false
965
+ path + file
1009
966
  end
1010
967
 
1011
968
  def rakepwd
1012
- return unless !pwd? && semgte?(Rake::VERSION, '13.0.4')
969
+ return unless Rake::VERSION >= '13.0.4'
1013
970
 
1014
971
  quote_option 'C', path
1015
972
  end
1016
973
 
1017
- def raketasks
1018
- @raketasks ||= [].tap do |ret|
1019
- opt = rakepwd
1020
- pwd_set(pass: !opt.nil?) do
1021
- IO.popen(rake_output(opt, '-AT').to_s).each do |line|
1022
- next unless line =~ /^rake ((?:[^\[: ]+:?)+)(\[[^\]]+\])?/
1023
-
1024
- ret << [$1, $2]
1025
- end
1026
- end
1027
- end
1028
- end
1029
-
1030
974
  def gempwd
1031
- return unless !pwd? && semgte?(Gem::VERSION, '3.4.2')
975
+ return unless Gem::VERSION >= '3.4.2'
1032
976
 
1033
977
  quote_option 'C', path
1034
978
  end
1035
979
 
1036
- def gemfile
1037
- return @gemfile unless @gemfile.nil?
1038
-
1039
- @gemfile = [project, name].map! { |val| path + "#{val}.gemspec" }
1040
- .concat(path.glob('*.gemspec'))
1041
- .find { |file| File.exist?(file) } || false
1042
- end
1043
-
1044
- def gemlib
1045
- @gemlib ||= begin
1046
- lib = Set.new(['lib'])
1047
- if (spec = gemspec)
1048
- lib.merge(spec.require_paths || [])
1049
- end
1050
- lib.select { |file| basepath(file).exist? }
1051
- end
1052
- end
1053
-
1054
- def gempath(val = version)
1055
- File.join('gems', "#{gemname}-#{val}")
1056
- end
1057
-
1058
- def gemdir?
1059
- !@gemdir.nil? && @gemdir.exist? && !@gemdir.empty?
980
+ def gempath(val = @version)
981
+ File.join('gems', "#{project}-#{val}")
1060
982
  end
1061
-
1062
- alias read_rakefile raketasks
1063
983
  end
1064
984
 
1065
985
  Application.implement Ruby