squared 0.5.2 → 0.5.3

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.
@@ -91,7 +91,7 @@ module Squared
91
91
  'irb' => nil
92
92
  })
93
93
 
94
- def initialize(*, autodetect: false, **kwargs)
94
+ def initialize(*, autodetect: false, gemspec: nil, **kwargs)
95
95
  super
96
96
  if @pass.include?(Ruby.ref)
97
97
  initialize_ref Ruby.ref
@@ -102,7 +102,8 @@ module Squared
102
102
  end
103
103
  dependfile_set GEMFILE
104
104
  @autodetect = autodetect
105
- return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || rakefile.empty?
105
+ @gemfile = path + gemspec if gemspec
106
+ return if !@output[0].nil? || !@copy.nil? || version || @autodetect || !rakefile
106
107
 
107
108
  begin
108
109
  File.foreach(rakefile) do |line|
@@ -129,12 +130,12 @@ module Squared
129
130
 
130
131
  namespace name do
131
132
  Ruby.subtasks do |action, flags|
132
- next if @pass.include?(action)
133
+ next if task_pass?(action)
133
134
 
134
135
  if flags.nil?
135
136
  case action
136
137
  when 'rake'
137
- next if rakefile.empty?
138
+ next unless rakefile
138
139
 
139
140
  format_desc action, nil, "task+,opts*|#{indexchar}index+|#,pattern*"
140
141
  task action, [:command] do |_, args|
@@ -167,13 +168,11 @@ module Squared
167
168
  end
168
169
  end
169
170
  when 'irb'
170
- next unless (spec = basepath("#{project}.gemspec") || basepath("#{name}.gemspec"))
171
- next unless basepath('lib').join("#{gemname = stripext(spec)}.rb").exist?
172
-
173
171
  format_desc action, nil, 'opts*,args*|:'
174
172
  task action do |_, args|
175
173
  args = args.to_a
176
- irb(gemname, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
174
+ name = basepath('lib').join("#{gemname}.rb").exist? ? gemname : nil
175
+ irb(name, args, args: (readline('Enter file [arguments]', force: false) if args.delete(':')))
177
176
  end
178
177
  else
179
178
  format_desc(action, nil, 'opts*', before: case action
@@ -303,9 +302,7 @@ module Squared
303
302
  begin
304
303
  copy_dir(a, b, c, pass: pass, verbose: verbose)
305
304
  rescue StandardError => e
306
- log.error e
307
- ret = on :error, :copy, e
308
- raise if exception && ret != true
305
+ on_error e, :copy
309
306
  end
310
307
  end
311
308
  on :last, :copy
@@ -445,11 +442,11 @@ module Squared
445
442
  when :file, :script
446
443
  op = OptionPartition.new(opts, OPT_RUBY[:ruby], ruby_session, project: self, args: true)
447
444
  if file
448
- op.extras.prepend(shell_quote(path + file))
445
+ op.unshift(shell_quote(path + file))
449
446
  elsif command
450
447
  op << quote_option('e', command, option: false)
451
448
  end
452
- op.extras << args if (args = ENV.fetch('RUBY_ARGS', args))
449
+ op.push(args) if (args = ENV.fetch('RUBY_ARGS', args))
453
450
  op.append(delim: true, escape: false, quote: false) unless op.empty?
454
451
  when :version
455
452
  pwd_set do
@@ -688,37 +685,44 @@ module Squared
688
685
  on :last, from
689
686
  return
690
687
  when :build
691
- if op.empty?
692
- spec = [path + "#{project}.gemspec", path + "#{name}.gemspec", *path.glob('*.gemspec')]
693
- op << File.basename(spec) if (spec = spec.find { |file| File.exist?(file) })
694
- else
688
+ if !op.empty?
695
689
  op << shell_quote(path + op.shift)
696
690
  op.clear(pass: false)
691
+ elsif (file = gemfile)
692
+ op << shell_quote(file)
697
693
  end
698
694
  when :push
699
695
  if op.empty?
700
- op << shell_quote(path + choice_index('Select a file', Dir.glob('*.gem', base: path), force: true))
696
+ file = path + (if (spec = gemspec)
697
+ "#{spec.name}-#{spec.version}.gem"
698
+ else
699
+ choice_index('Select a file', Dir.glob('*.gem', base: path), force: true)
700
+ end)
701
701
  else
702
702
  file = path + op.shift
703
+ raise_error('gem not found', hint: file) unless file.exist?
703
704
  raise_error("unknown args: #{op.join(', ')}", hint: flag) unless op.empty?
704
- if file.exist?
705
- op << shell_quote(file)
706
- else
707
- raise_error('gem not found', hint: file)
708
- end
709
705
  end
710
- run_rb(from: from, interactive: "Push #{sub_style(project, styles: theme[:active])}")
706
+ op << shell_quote(file)
707
+ run_rb(from: from, interactive: "Push #{sub_style(gemname, styles: theme[:active])}")
711
708
  return
712
709
  when :exec
713
- raise_error('missing command', hint: flag) if op.empty?
714
- op << basic_option('gem', project) unless op.arg?('g', 'gem')
715
- if (args = command_args(op.extras))
710
+ min = if op.arg?('g', 'gem')
711
+ 1
712
+ elsif op.empty?
713
+ op << basic_option('gem', gemname)
714
+ 1
715
+ else
716
+ op << op.shift
717
+ 0
718
+ end
719
+ if (args = command_args(op.extras, min: min, force: min == 1 && op.empty?))
716
720
  op.push(args)
717
721
  end
718
- op.append(delim: true, quote: false)
722
+ op.append(quote: false)
719
723
  when :update
720
724
  unless op.arg?('system')
721
- op.push(project) if op.empty?
725
+ op.push(gemname) if op.empty?
722
726
  op.adjoin
723
727
  end
724
728
  op.clear(errors: true)
@@ -738,7 +742,7 @@ module Squared
738
742
  items = op.extras.to_a
739
743
  name = items.delete_at(n)
740
744
  if (n = name.index('@')) == 0
741
- pre = project
745
+ pre = gemname
742
746
  ver = name[1..-1]
743
747
  else
744
748
  pre = name[0, n]
@@ -793,10 +797,11 @@ module Squared
793
797
  run_s(args, banner: false, from: :rake)
794
798
  end
795
799
 
796
- def irb(name, opts = [], path: @path + 'lib', args: nil)
800
+ def irb(name = nil, opts = [], path: basepath('lib'), args: nil)
797
801
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
798
802
  r = args ? [] : ['bundler/setup']
799
- (r << name).each { |val| op << shell_option('r', val, merge: true) }
803
+ r << name if name
804
+ r.each { |val| op << shell_option('r', val, merge: true) }
800
805
  Array(path).each { |val| op << quote_option('I', val, merge: true) }
801
806
  if args
802
807
  op << '--' << args
@@ -807,6 +812,24 @@ module Squared
807
812
  run(banner: false)
808
813
  end
809
814
 
815
+ def gemspec
816
+ return @gemspec unless @gemspec.nil?
817
+
818
+ begin
819
+ if (file = gemfile)
820
+ require 'rubygems'
821
+ @gemspec = Gem::Specification.load(file.to_s)
822
+ end
823
+ rescue StandardError => e
824
+ log.debug e
825
+ end
826
+ @gemspec ||= false
827
+ end
828
+
829
+ def gemname
830
+ @gemname ||= ((spec = gemspec) ? spec.name : project)
831
+ end
832
+
810
833
  def depend?
811
834
  @depend != false && (!@depend.nil? || outdated?)
812
835
  end
@@ -815,7 +838,7 @@ module Squared
815
838
  return true if super || (@copy.is_a?(Hash) && copy.fetch(:into, nil))
816
839
  return gemdir? if @gemdir
817
840
 
818
- if @version
841
+ if version
819
842
  begin
820
843
  case @autodetect
821
844
  when 'rvm'
@@ -840,17 +863,19 @@ module Squared
840
863
  return false unless @autodetect
841
864
 
842
865
  set = lambda do |val, path|
843
- log.warn "using version #{val} (given #{@version})" if @version && @version != val
844
- @version = val
866
+ if (ver = version) && ver != val
867
+ log.warn "using version #{val} (given #{ver})"
868
+ end
869
+ self.version = val
845
870
  @gemdir = Pathname.new(path.strip) + gempath
846
871
  end
847
- if @version
848
- pwd = gempwd
849
- pwd_set(pass: !pwd.nil?) do
850
- out = `#{gem_output(pwd, 'list --local -d', project)}`
851
- if out =~ /#{Regexp.escape(project)} \(([^)]+)\)/
872
+ if version
873
+ opt = gempwd
874
+ pwd_set(pass: !opt.nil?) do
875
+ out = `#{gem_output(opt, 'list --local -d', gemname)}`
876
+ if out =~ /#{Regexp.escape(gemname)} \(([^)]+)\)/
852
877
  $1.split(/\s*,\s*/)
853
- .prepend(@version)
878
+ .prepend(version)
854
879
  .uniq
855
880
  .each do |val|
856
881
  next unless out =~ /\(#{Regexp.escape(val)}(?:,[^)]+|\b)\):([^\n]+)/
@@ -866,16 +891,16 @@ module Squared
866
891
  parse = lambda do |path|
867
892
  next unless path
868
893
 
869
- lib = Regexp.new(['', 'gems', "#{project}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
894
+ lib = Regexp.new(['', 'gems', "#{gemname}-([^#{File::SEPARATOR}]+)", ''].join(File::SEPARATOR))
870
895
  if (ver = path[lib, 1]) && (val = path[/\A(.+)#{gempath(ver[1])}/, 1])
871
896
  set.call(ver, val)
872
897
  end
873
898
  end
874
899
  if RUBY_VERSION >= '2.6'
875
900
  target = RUBY_VERSION.start_with?('2.6') ? RubyVM : $LOAD_PATH
876
- parse.call(target.resolve_feature_path(project)&.last)
901
+ parse.call(target.resolve_feature_path(gemname)&.last)
877
902
  end
878
- if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', project)}`) }
903
+ if !@gemdir && !pwd_set { parse.call(`#{bundle_output('show', gemname)}`) }
879
904
  raise_error 'gems directory not found'
880
905
  end
881
906
  end
@@ -982,8 +1007,10 @@ module Squared
982
1007
  end
983
1008
 
984
1009
  def rakefile
985
- @rakefile ||= Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }.yield_self do |file|
986
- file ? path + file : ''
1010
+ return @rakefile unless @rakefile.nil?
1011
+
1012
+ @rakefile = Rake::Application::DEFAULT_RAKEFILES.find { |val| basepath(val).exist? }.yield_self do |file|
1013
+ file ? path + file : false
987
1014
  end
988
1015
  end
989
1016
 
@@ -999,8 +1026,16 @@ module Squared
999
1026
  quote_option 'C', path
1000
1027
  end
1001
1028
 
1002
- def gempath(val = @version)
1003
- File.join('gems', "#{project}-#{val}")
1029
+ def gemfile
1030
+ return @gemfile unless @gemfile.nil?
1031
+
1032
+ @gemfile = [project, name].map! { |val| path + "#{val}.gemspec" }
1033
+ .concat(path.glob('*.gemspec'))
1034
+ .find { |file| File.exist?(file) } || false
1035
+ end
1036
+
1037
+ def gempath(val = version)
1038
+ File.join('gems', "#{gemname}-#{val}")
1004
1039
  end
1005
1040
  end
1006
1041
 
@@ -35,9 +35,7 @@ module Squared
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)}]", 'N')
39
-
40
- raise_error 'user cancelled'
38
+ exit 1 unless pass || confirm("Run? [#{sub_style(target, styles: styles)}]", 'N')
41
39
  end
42
40
 
43
41
  def strip(val)
@@ -63,7 +61,7 @@ module Squared
63
61
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
64
62
  :merge, :delete, :delete?, :delete_if, :grep, :inspect, :to_a, :to_s
65
63
  def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
66
- :pop, :push, :join, :map, :map!, :select, :reject, :size
64
+ :pop, :push, :index, :delete_at, :join, :map, :map!, :select, :reject, :size
67
65
 
68
66
  def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
69
67
  @target = target.is_a?(Set) ? target : target.to_set
@@ -10,9 +10,9 @@ module Squared
10
10
 
11
11
  TASK_BASE = []
12
12
  TASK_BATCH = {}
13
- TASK_EXTEND = Workspace.hashlist
13
+ TASK_EXTEND = Support.hashlist
14
14
  TASK_KEYS = []
15
- TASK_ALIAS = Workspace.hashobj
15
+ TASK_ALIAS = Support.hashobj
16
16
  TASK_NAME = {}
17
17
  private_constant :TASK_BASE, :TASK_BATCH, :TASK_EXTEND, :TASK_KEYS, :TASK_ALIAS, :TASK_NAME
18
18
 
@@ -79,8 +79,8 @@ module Squared
79
79
  @chain = {}
80
80
  @exclude = exclude.freeze
81
81
  @session = {
82
- group: Workspace.hashlist,
83
- parent: Workspace.hashlist,
82
+ group: Support.hashlist,
83
+ parent: Support.hashlist,
84
84
  id: []
85
85
  }
86
86
  @data = {}
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Squared
4
+ module Workspace
5
+ module Support
6
+ class << self
7
+ def hashobj
8
+ Hash.new { |data, key| data[key] = {} }
9
+ end
10
+
11
+ def hashlist
12
+ Hash.new { |data, key| data[key] = [] }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'support/base'
3
4
  require_relative 'support/data'
@@ -27,14 +27,6 @@ module Squared
27
27
  !!project(name)&.enabled?
28
28
  end
29
29
 
30
- def hashobj
31
- Hash.new { |data, key| data[key] = {} }
32
- end
33
-
34
- def hashlist
35
- Hash.new { |data, key| data[key] = [] }
36
- end
37
-
38
30
  private
39
31
 
40
32
  def project(name)
data/squared.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/squared/version"
3
+ version = File.read(File.join(__dir__, "lib/squared/version.rb"))[/\bVERSION = '(.+)'$/, 1]
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "squared"
7
- spec.version = Squared::VERSION
7
+ spec.version = version
8
8
  spec.authors = ["An Pham"]
9
9
  spec.email = ["anpham6@gmail.com"]
10
10
 
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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -101,6 +101,7 @@ files:
101
101
  - lib/squared/workspace/repo.rb
102
102
  - lib/squared/workspace/series.rb
103
103
  - lib/squared/workspace/support.rb
104
+ - lib/squared/workspace/support/base.rb
104
105
  - lib/squared/workspace/support/data.rb
105
106
  - squared.gemspec
106
107
  homepage: https://github.com/anpham6/squared
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  - !ruby/object:Gem::Version
125
126
  version: '0'
126
127
  requirements: []
127
- rubygems_version: 3.6.7
128
+ rubygems_version: 3.6.9
128
129
  specification_version: 4
129
130
  summary: Rake task generator for managing multi-language workspaces.
130
131
  test_files: []