squared 0.0.1 → 0.0.2

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,57 +4,46 @@ module Squared
4
4
  module Repo
5
5
  module Project
6
6
  class Ruby < Git
7
+ REF = :ruby
7
8
  GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
8
9
  OPT_INSTALL = %w[no-cache force quiet verbose].freeze
9
10
  OPT_UPDATE = %w[redownload local strict conservative quiet verbose].freeze
10
- private_constant :GEMFILE, :OPT_INSTALL, :OPT_UPDATE
11
+ private_constant :REF, :GEMFILE, :OPT_INSTALL, :OPT_UPDATE
11
12
 
12
13
  class << self
14
+ def populate(*); end
15
+
13
16
  def tasks
14
17
  nil
15
18
  end
16
19
 
17
- def to_sym
18
- :ruby
19
- end
20
-
21
- def is_a?(path)
22
- if path.is_a?(::String) || path.is_a?(::Pathname)
23
- base = Pathname.new(path)
24
- [*GEMFILE, 'Rakefile', 'README.rdoc'].any? { |file| base.join(file).exist? }
20
+ def is_a?(val)
21
+ if val.is_a?(::Pathname) || (val.is_a?(::String) && (val = Pathname.new(val)))
22
+ [*GEMFILE, *::Rake::Application::DEFAULT_RAKEFILES, 'README.rdoc'].any? { |file| val.join(file).exist? }
25
23
  else
26
24
  super
27
25
  end
28
26
  end
29
27
  end
30
28
 
31
- @@tasks[:ruby] = {
29
+ @@tasks[REF] = {
32
30
  install: %i[redownload local prefer-local with-g without-g],
33
31
  update: %i[all patch minor major],
34
- pristine: %i[version extensions]
32
+ pristine: %i[version extensions],
33
+ rake: nil
35
34
  }.freeze
36
35
 
37
36
  def initialize(name, project, workspace, **kwargs)
38
37
  super
39
- if env('BUILD', suffix: 'DEV', equals: '0')
40
- @dev = false
41
- else
42
- @dev = kwargs.delete(:dev)
43
- if env('BUILD', suffix: 'DEV')
44
- @dev = true
45
- elsif @dev.nil?
46
- @dev = @workspace.dev?
47
- end
48
- end
38
+ initialize_build(REF, **kwargs)
49
39
  @version = env('BUILD', suffix: 'VERSION', strict: true) || kwargs.delete(:version)
50
40
  @autodetect = kwargs.key?(:autodetect) ? kwargs.delete(:autodetect) : false
51
- @gemdir = nil
52
- return unless @output[0].nil? && @copy.nil? && !@version && !@autodetect && !doc? && (file = rakefile)
41
+ return if !@output[0].nil? || !@copy.nil? || @version || @autodetect || (file = rakefile).nil?
53
42
 
54
43
  begin
55
44
  pat = %r{\brequire\s+(["'])bundler/gem_tasks\1}
56
45
  File.foreach(file) do |line|
57
- next unless pat.match?(line)
46
+ next unless line.match?(pat)
58
47
 
59
48
  @output[0] = 'bundle exec rake build'
60
49
  @copy = 'bundle exec rake install'
@@ -70,33 +59,45 @@ module Squared
70
59
  super
71
60
  return unless outdated?
72
61
 
73
- namespace @name do
74
- @@tasks[:ruby].each do |action, flags|
75
- namespace action do
76
- flags.each do |flag|
77
- case action
78
- when :install
79
- case flag
80
- when :'with-g', :'without-g'
81
- desc format_desc(action, flag, 'group+')
82
- task flag, [:group] do |_, args|
83
- install(flag, group: collect_args(args, :group))
62
+ namespace name do
63
+ @@tasks[REF].each do |action, flags|
64
+ if flags.nil?
65
+ case action
66
+ when :rake
67
+ next unless rakefile
68
+
69
+ desc format_desc(action, nil, 'command*')
70
+ task action, [:command] do |_, args|
71
+ rake collect_args(args, :command)
72
+ end
73
+ end
74
+ else
75
+ namespace action do
76
+ flags.each do |flag|
77
+ case action
78
+ when :install
79
+ case flag
80
+ when :'with-g', :'without-g'
81
+ desc format_desc(action, flag, 'group+')
82
+ task flag, [:group] do |_, args|
83
+ install(flag, group: collect_args(args, :group))
84
+ end
85
+ else
86
+ desc format_desc(action, flag, OPT_INSTALL)
87
+ task flag, [:opts] do |_, args|
88
+ install(flag, opts: collect_args(args, :opts))
89
+ end
84
90
  end
85
- else
86
- desc format_desc(action, flag, OPT_INSTALL)
91
+ when :update
92
+ desc format_desc(action, flag, OPT_UPDATE)
87
93
  task flag, [:opts] do |_, args|
88
- install(flag, opts: collect_args(args, :opts))
94
+ update(flag, opts: collect_args(args, :opts))
95
+ end
96
+ when :pristine
97
+ desc format_desc(action, flag, 'version?')
98
+ task flag, [:version] do |_, args|
99
+ pristine(flag, version: args.version)
89
100
  end
90
- end
91
- when :update
92
- desc format_desc(action, flag, OPT_UPDATE)
93
- task flag, [:opts] do |_, args|
94
- update(flag, opts: collect_args(args, :opts))
95
- end
96
- when :pristine
97
- desc format_desc(action, flag, 'version?')
98
- task flag, [:version] do |_, args|
99
- pristine(flag, version: args.version)
100
101
  end
101
102
  end
102
103
  end
@@ -138,21 +139,21 @@ module Squared
138
139
  else
139
140
  cmd = bundle_session 'install'
140
141
  end
141
- run(banner: banner?, exception: @workspace.exception)
142
+ run(banner: banner?, exception: workspace.exception)
142
143
  end
143
144
  end
144
145
 
145
- def copy(from: 'lib', glob: '**/*', basedir: @gemdir, override: false)
146
+ def copy(from: 'lib', glob: '**/*', gemdir: @gemdir, override: false)
146
147
  if @copy && !override
147
148
  return super if @copy.is_a?(::String)
148
149
 
149
150
  from = @copy[:from] if @copy.key?(:from)
150
151
  glob = @copy[:glob] if @copy.key?(:glob)
151
- basedir = @copy[:basedir] if @copy.key?(:basedir)
152
+ gemdir = @copy[:gemdir] if @copy.key?(:gemdir)
152
153
  end
153
- return unless basedir
154
+ return unless gemdir
154
155
 
155
- dest = Pathname.new(basedir).realpath
156
+ dest = Pathname.new(gemdir).realpath
156
157
  print_item unless @output[0]
157
158
  glob = as_a(glob)
158
159
  as_a(from).each_with_index do |val, i|
@@ -173,11 +174,11 @@ module Squared
173
174
  cmd << "--#{flag}"
174
175
  end
175
176
  append_opts opts, OPT_UPDATE
176
- run(banner: banner?, exception: @workspace.exception)
177
+ run(banner: banner?, exception: workspace.exception)
177
178
  end
178
179
 
179
180
  def pristine(flag, version: nil)
180
- cmd = gem_session 'pristine', @project
181
+ cmd = gem_session 'pristine', project
181
182
  case flag
182
183
  when :extensions
183
184
  cmd << '--extensions'
@@ -185,7 +186,15 @@ module Squared
185
186
  guard_params version, 'version'
186
187
  end
187
188
  cmd << "--version=#{version}" if version
188
- run(banner: banner?, exception: @workspace.exception)
189
+ run(banner: banner?, exception: workspace.exception)
190
+ end
191
+
192
+ def rake(cmd)
193
+ if cmd.empty?
194
+ run_s 'rake'
195
+ else
196
+ cmd.each { |val| run_s "rake #{val}" }
197
+ end
189
198
  end
190
199
 
191
200
  def rakefile
@@ -197,17 +206,17 @@ module Squared
197
206
  return true if @copy && (@copy.is_a?(::String) || @copy.fetch(:gemdir, nil))
198
207
  return gemdir? if @gemdir
199
208
 
200
- gem_path = -> { "gems#{::File::SEPARATOR}#{@project}-#{@version}" }
209
+ gempath = -> { "gems#{::File::SEPARATOR}#{project}-#{@version}" }
201
210
  if @version && (val = ENV['GEM_HOME'])
202
- @gemdir = Pathname.new(val).join(gem_path.())
211
+ @gemdir = Pathname.new(val).join(gempath.())
203
212
  return true if gemdir?
204
213
  end
205
214
  return false unless @autodetect
206
215
 
207
216
  error = ->(hint) { raise ArgumentError, message('failed to parse', hint: hint) }
208
217
  begin
209
- out = `gem -C #{shell_quote(@path)} list --local -d #{@project}`
210
- data = /#{Regexp.escape(@project)} \(([^)]+)\)/.match(out)
218
+ out = `gem -C #{shell_quote(path)} list --local -d #{project}`
219
+ data = /#{Regexp.escape(project)} \(([^)]+)\)/.match(out)
211
220
  error.('version') unless data
212
221
  ver = data[1].split(/\s*,\s*/)
213
222
  if @version
@@ -223,7 +232,7 @@ module Squared
223
232
  break
224
233
  end
225
234
  error.('path') unless data
226
- @gemdir = Pathname.new(data[1].strip).join(gem_path.())
235
+ @gemdir = Pathname.new(data[1].strip).join(gempath.())
227
236
  rescue StandardError => e
228
237
  warn e
229
238
  @version = nil
@@ -235,7 +244,7 @@ module Squared
235
244
  end
236
245
 
237
246
  def depend?
238
- !@depend.nil? || outdated?
247
+ !!@depend || outdated?
239
248
  end
240
249
 
241
250
  def outdated?
@@ -4,37 +4,7 @@ module Squared
4
4
  module Repo
5
5
  module Project
6
6
  class << self
7
- include Common::Format
8
-
9
7
  attr_accessor :line_width
10
-
11
- def banner(*lines, styles: nil, pad: 0, first: false)
12
- n = max_width(lines)
13
- ch = ' ' * pad
14
- index = -1
15
- out = lines.map do |val|
16
- index += 1
17
- val = ch + val.ljust(n - (pad * 2)) + ch
18
- if styles && (!first || index == 0)
19
- sub_style(val, *styles)
20
- else
21
- val
22
- end
23
- end
24
- out << ('-' * n)
25
- out.join("\n")
26
- end
27
-
28
- def footer(*lines)
29
- n = max_width(lines)
30
- ['-' * n, *lines.map { |val| val.ljust(n) }].join("\n")
31
- end
32
-
33
- private
34
-
35
- def max_width(lines)
36
- [lines.max_by(&:size).size, line_width].max
37
- end
38
8
  end
39
9
 
40
10
  @line_width = ENV.fetch('LOG_COLUMNS', 80).to_i