ext 1.1.3 → 2.1.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.
@@ -2,13 +2,13 @@ require 'fileutils'
2
2
 
3
3
  FileUtils.class_eval do
4
4
  # simulates cp -a
5
- def cp_a source, dest, options = {}
6
- cp_r source, dest, options.merge(:preserve => true)
5
+ def cp_a source, dest, **options
6
+ cp_r source, dest, **options, :preserve => true
7
7
  end
8
8
 
9
9
  # calls rm_rf if the file exists
10
- def rm_rf_ie file, options = {}
11
- rm_rf file, options if File.exist?(file)
10
+ def rm_rf_ie file, **options
11
+ rm_rf(file, **options) if File.exist?(file)
12
12
  end
13
13
 
14
14
  # calls rmdir if the file exists and is empty
@@ -21,39 +21,39 @@ FileUtils.class_eval do
21
21
  rmdir path if File.exist?(path)
22
22
  end
23
23
 
24
- alias rm_rf_old rm_rf
24
+ alias_method :rm_rf_old, :rm_rf
25
25
  #going to try to give a delay after calling rm if necessary...
26
- def rm_rf *args
26
+ def rm_rf(filename, *args, **opts)
27
27
  tries = 0
28
28
 
29
29
  rm = proc do
30
- rm_rf_old(*args)
30
+ rm_rf_old(filename, *args, **opts)
31
31
 
32
- while File.exist?(args[0]) && tries < 10
33
- # :nocov:
32
+ while File.exist?(filename) && tries < 10
33
+ # simplecov:disable
34
34
  sleep 1
35
35
  tries += 1
36
- # :nocov:
36
+ # simplecov:enable
37
37
  end
38
38
  end
39
39
 
40
40
  rm.call
41
41
  if tries >= 10
42
- # :nocov:
43
- puts "WARNING: deleted #{args[0]} didn't work, trying again"
42
+ # simplecov:disable
43
+ puts "WARNING: deleted #{filename} didn't work, trying again"
44
44
  tries = 0
45
45
  rm.call
46
46
 
47
47
  if tries >= 10
48
- raise "Could not delete #{args[0]}"
48
+ raise "Could not delete #{filename}"
49
49
  end
50
- # :nocov:
50
+ # simplecov:enable
51
51
  end
52
52
  end
53
53
 
54
54
  def dir_empty? path
55
55
  File.directory?(path) &&
56
56
  File.exist?(path) &&
57
- !Dir.entries(path).detect{|entry| !["..","."].include?(entry)}
57
+ !Dir.entries(path).detect{|entry| !["..", "."].include?(entry)}
58
58
  end
59
59
  end
@@ -1,6 +1,6 @@
1
1
  String.class_eval do
2
2
  def cap_first
3
- "#{self[0].chr.upcase}#{self[1..(self.length - 1)]}"
3
+ "#{self[0].chr.upcase}#{self[1..]}"
4
4
  end
5
5
 
6
6
  def classify
@@ -8,24 +8,22 @@ String.class_eval do
8
8
  end
9
9
 
10
10
  #avoid collision
11
- raise if instance_methods.include?("lines_by_width")
11
+ raise if method_defined?("lines_by_width")
12
+
12
13
  def lines_by_width(width = 32)
13
14
  width ||= 32
14
15
  lines = []
15
16
  string = gsub(/\s+/, ' ')
16
- while string.size > 0
17
+ until string.empty?
17
18
  if string.size <= width
18
19
  lines << string
19
20
  string = ""
20
21
  else
21
22
  index = string[0, width + 1].rindex(/\s/)
22
- unless index
23
- # let's find the first space we can.
24
- index = string.index(/\s/)
25
- end
23
+ index ||= string.index(/\s/)
26
24
  if index
27
25
  lines << string[0, index]
28
- string = string[(index + 1)..-1]
26
+ string = string[(index + 1)..]
29
27
  else
30
28
  lines << string
31
29
  string = ""
@@ -35,5 +33,4 @@ String.class_eval do
35
33
 
36
34
  lines
37
35
  end
38
-
39
- end
36
+ end
@@ -1,15 +1,16 @@
1
- require 'externals/extensions/symbol'
2
1
  require 'fileutils'
3
2
 
4
3
  module Externals
5
- OPTS_SUFFIXES = ["co", "up", "st", "ex"] unless const_defined?('OPTS_SUFFIXES')
6
- VALID_ATTRIB = ([
7
- :name, :path, :repository, :branch, :type, :scm, :revision
8
- ]
9
- ).map(&:to_s) unless const_defined?('VALID_ATTRIB')
4
+ OPTS_SUFFIXES = ["co", "up", "st", "ex"].freeze unless const_defined?('OPTS_SUFFIXES')
5
+ unless const_defined?('VALID_ATTRIB')
6
+ VALID_ATTRIB = [
7
+ :name, :path, :repository, :branch, :scm, :revision
8
+ ].map(&:to_s)
9
+ end
10
10
 
11
11
  class Project
12
12
  attr_accessor :parent
13
+
13
14
  include FileUtils
14
15
  extend FileUtils
15
16
 
@@ -20,20 +21,22 @@ module Externals
20
21
  attributes[name.to_sym] = value
21
22
  end
22
23
  next if name == "name" || name == "scm"
24
+
23
25
  define_method name do
24
26
  attributes[name.to_sym]
25
27
  end
26
28
  end
27
29
  end
28
30
 
29
-
30
31
  attr_attr_accessor Externals::VALID_ATTRIB
31
32
  def attributes
32
33
  @attributes ||= {}
33
34
  end
35
+
34
36
  def name
35
37
  attributes[:name] || extract_name(repository)
36
38
  end
39
+
37
40
  def main_project?
38
41
  path == '.'
39
42
  end
@@ -48,25 +51,18 @@ module Externals
48
51
  self.class.scm
49
52
  end
50
53
 
51
- def self.default_branch
52
- raise "subclass responsibility"
53
- end
54
-
55
- def default_branch
56
- self.class.default_branch
57
- end
58
-
59
- def switch branch_name, options = {}
54
+ def switch _branch_name, _options = {}
55
+ # simplecov:disable
60
56
  raise "subclass responsibility"
57
+ # simplecov:enable
61
58
  end
62
59
 
63
60
  def initialize hash
64
61
  raise "Abstract class" if self.class == Project
65
62
  raise "expected hash" unless hash.is_a? Hash
66
63
 
67
- hash = hash.keys.inject({}) do |new_hash, key|
68
- new_hash[key.to_s] = hash[key]
69
- new_hash
64
+ hash = hash.keys.to_h do |key|
65
+ [key.to_s, hash[key]]
70
66
  end
71
67
 
72
68
  invalid_attrib = hash.keys - Externals::VALID_ATTRIB
@@ -76,25 +72,26 @@ module Externals
76
72
  attribute =~ /^\w+_opts(_(#{OPTS_SUFFIXES.join("|")}))?/
77
73
  end
78
74
  if !invalid_attrib.empty?
75
+ # simplecov:disable
79
76
  raise "invalid attribute(s): #{invalid_attrib.join(', ')}"
77
+ # simplecov:enable
80
78
  end
81
79
  end
82
80
 
83
81
  path = hash.delete('path')
84
82
 
85
- hash.keys.each do |key|
86
- send("#{key}=", hash[key])
83
+ hash.each_pair do |key, value|
84
+ send("#{key}=", value)
87
85
  end
88
86
 
89
- if path && !path.is_a?(String)
90
- path = path.default_path(name)
91
- end
92
87
  self.path = path
93
88
  end
94
89
 
95
90
  [:co, :ex].each do |method_name|
96
- define_method method_name do |args|
91
+ define_method method_name do
92
+ # simplecov:disable
97
93
  raise "subclass responsibility"
94
+ # simplecov:enable
98
95
  end
99
96
  end
100
97
 
@@ -173,8 +170,9 @@ module Externals
173
170
  end
174
171
  end
175
172
 
176
-
177
173
  def self.inherited child
174
+ super
175
+
178
176
  child.class_eval do
179
177
  def self.scm
180
178
  @scm ||= /^([^:]*::)*([^:]+)Project$/.match(name)[2].downcase
@@ -190,19 +188,16 @@ module Externals
190
188
  #of the suffixed versions (<scm_name>_opts_co) as well as the project
191
189
  #specific ones. (scm_opts, scm_opts_co, etc)
192
190
  scm_name = scm
193
- Project.__send__(:define_method, "#{scm_name}_opts_raw") do
194
- attributes[name.to_sym]
195
- end
196
191
  #global settings are fetched from the parent project.
197
192
  Project.__send__(:define_method, "#{scm_name}_opts") do
198
193
  if parent
199
194
  parent.__send__("#{scm_name}_opts")
200
195
  else
201
- attributes["#{scm_name}_opts".to_sym]
196
+ attributes[:"#{scm_name}_opts"]
202
197
  end
203
198
  end
204
199
  Project.__send__(:define_method, "#{scm_name}_opts=") do |value|
205
- attributes["#{scm_name}_opts".to_sym] = value
200
+ attributes[:"#{scm_name}_opts"] = value
206
201
  end
207
202
 
208
203
  #now we create the suffixed version of the global settings.
@@ -216,7 +211,7 @@ module Externals
216
211
  else
217
212
  values = [
218
213
  attributes[name.to_sym],
219
- self.send("#{scm_name}_opts")
214
+ send("#{scm_name}_opts")
220
215
  ].compact
221
216
 
222
217
  if !values.empty?
@@ -232,15 +227,6 @@ module Externals
232
227
  end
233
228
 
234
229
  protected
235
- def trim_quotes value
236
- if value
237
- if [value[0].chr, value[-1].chr] == ['"', '"']
238
- value[1..-2]
239
- else
240
- value
241
- end
242
- end
243
- end
244
230
 
245
231
  #helper method for converting "co" into "scm_opts_co" and "" into "scm_opts"
246
232
  def resolve_opts command = ""
@@ -2,11 +2,8 @@ require File.join(File.dirname(__FILE__), '..', 'project')
2
2
 
3
3
  module Externals
4
4
  class GitProject < Project
5
- def default_branch
6
- 'master'
7
- end
8
-
9
5
  private
6
+
10
7
  def do_clone command, extra_opts = ""
11
8
  opts = resolve_opts(command)
12
9
 
@@ -22,25 +19,30 @@ module Externals
22
19
  puts(gitclonecmd = "git #{opts} clone #{extra_opts} \"#{repository}\" #{dest}")
23
20
  puts `#{gitclonecmd}`
24
21
  unless $? == 0
22
+ # simplecov:disable
25
23
  raise "git clone of #{repository} failed."
24
+ # simplecov:enable
26
25
  end
27
26
  end
28
27
 
29
28
  public
30
- def co *args
29
+
30
+ def co *_args
31
31
  do_up "co"
32
32
  end
33
33
 
34
34
  private
35
+
35
36
  # make sure you have already entered Dir.chdir(path) in your calling code!
36
37
  def branch_exists branch_name
37
38
  opts = resolve_opts
38
- `git #{opts} branch -a` =~ /^\s*#{branch_name}\s*$/
39
+ `git #{opts} branch -a` =~ /^[\s*]*#{branch_name}\s*$/
39
40
  end
40
41
 
41
42
  # make sure you have already entered Dir.chdir(path) in your calling code!
42
43
 
43
44
  public
45
+
44
46
  # this method fetches/pulls/changes branches/changes revisions/changes the oil in your geo metro/brings world peace
45
47
  def change_to_branch_revision command = ""
46
48
  opts = resolve_opts(command)
@@ -48,16 +50,15 @@ module Externals
48
50
  pulled = false
49
51
 
50
52
  project_path = if path == "."
51
- name || "."
52
- else
53
- path
54
- end
53
+ name || "."
54
+ else
55
+ path
56
+ end
55
57
 
56
58
  Dir.chdir project_path do
57
59
  do_fetch command
58
60
  end
59
61
 
60
-
61
62
  if branch
62
63
  cb = current_branch
63
64
 
@@ -78,7 +79,9 @@ module Externals
78
79
  puts `git #{opts} checkout --track -b #{branch} origin/#{branch}`
79
80
  end
80
81
  unless $? == 0
82
+ # simplecov:disable
81
83
  raise "Could not checkout origin/#{branch}"
84
+ # simplecov:enable
82
85
  end
83
86
  end
84
87
  end
@@ -87,6 +90,7 @@ module Externals
87
90
  Dir.chdir project_path do
88
91
  `git #{opts} pull`
89
92
  raise unless $? == 0
93
+
90
94
  pulled = true
91
95
  end
92
96
  end
@@ -95,7 +99,9 @@ module Externals
95
99
  Dir.chdir project_path do
96
100
  puts `git #{opts} checkout #{revision}`
97
101
  unless $? == 0
102
+ # simplecov:disable
98
103
  raise "Could not checkout #{revision}"
104
+ # simplecov:enable
99
105
  end
100
106
  end
101
107
  else
@@ -108,29 +114,25 @@ module Externals
108
114
  end
109
115
  end
110
116
 
111
- def switch branch_name, options = {}
112
- cb = current_branch
113
- if cb == branch_name
114
- puts "Already on branch #{branch_name}"
115
- else
116
- # This allows the main project to be checked out to a directory
117
- # that doesn't match it's name.
118
- Dir.chdir path do
119
- # let's see if the branch exists in the remote repository
120
- # and if not, fetch it.
121
- if !branch_exists("origin/#{branch_name}")
122
- puts `git #{scm_opts} fetch`
123
- end
117
+ def switch branch_name, _options = {}
118
+ # This allows the main project to be checked out to a directory
119
+ # that doesn't match it's name.
120
+ Dir.chdir path do
121
+ # let's see if the branch exists in the remote repository
122
+ # and if not, fetch it.
123
+ if !branch_exists("origin/#{branch_name}")
124
+ puts `git #{scm_opts} fetch`
125
+ end
124
126
 
125
- # if the local branch doens't exist, add --track -b
126
- if branch_exists(branch_name)
127
- puts `git #{scm_opts} checkout #{branch_name}`
128
- else
129
- puts `git #{resolve_opts("co")} checkout --track -b #{branch_name} origin/#{branch_name}`
130
- end
131
- unless $? == 0
132
- raise "Could not checkout origin/#{branch_name}"
133
- end
127
+ if branch_exists(branch_name)
128
+ puts `git #{scm_opts} checkout #{branch_name}`
129
+ else
130
+ puts `git #{resolve_opts("co")} checkout --track -b #{branch_name}`
131
+ end
132
+ unless $? == 0
133
+ # simplecov:disable
134
+ raise "Could not checkout origin/#{branch_name}"
135
+ # simplecov:enable
134
136
  end
135
137
  end
136
138
  end
@@ -142,18 +144,21 @@ module Externals
142
144
  up(*args)
143
145
  else
144
146
  clone_opts = "--depth 1"
147
+
145
148
  if branch
146
- clone_opts << " -b #{branch}"
149
+ clone_opts = "#{clone_opts} -b #{branch}"
147
150
  end
151
+
148
152
  do_clone "ex", clone_opts
149
153
  end
150
154
  end
151
155
 
152
- def up *args
156
+ def up *_args
153
157
  do_up "up"
154
158
  end
155
159
 
156
160
  private
161
+
157
162
  def do_fetch command
158
163
  opts = resolve_opts(command)
159
164
  `git #{opts} fetch`
@@ -162,15 +167,15 @@ module Externals
162
167
 
163
168
  def do_up command
164
169
  project_path = if path == "."
165
- name || "." # if no name is specified then we are expected to already be in the right path.
166
- # this is a little confusing and should be cleaned up.
167
- # When we are doing a checkout, the name is set manually in Ext.checkout.
168
- # we are then in the parent directory.
169
- # When we are doing an update, the main project has no name.
170
- # we are then in the correct directory.
171
- else
172
- path
173
- end
170
+ name || "." # if no name is specified then we are expected to already be in the right path.
171
+ # this is a little confusing and should be cleaned up.
172
+ # When we are doing a checkout, the name is set manually in Ext.checkout.
173
+ # we are then in the parent directory.
174
+ # When we are doing an update, the main project has no name.
175
+ # we are then in the correct directory.
176
+ else
177
+ path
178
+ end
174
179
 
175
180
  puts "Updating #{path}..."
176
181
 
@@ -181,7 +186,8 @@ module Externals
181
186
  end
182
187
 
183
188
  public
184
- def st *args
189
+
190
+ def st *_args
185
191
  puts "\nstatus for #{path}:"
186
192
  Dir.chdir path do
187
193
  puts `git #{scm_opts_st} status`
@@ -194,8 +200,8 @@ module Externals
194
200
 
195
201
  def self.fill_in_opts opts, main_options, sub_options, options
196
202
  opts.on("--git", "-g",
197
- Integer,
198
- *"same as '--scm git' Uses git to
203
+ Integer,
204
+ *"same as '--scm git' Uses git to
199
205
  checkout/export the main project".lines_by_width(options[:summary_width])
200
206
  ) {sub_options[:scm] = main_options[:scm] = 'git'}
201
207
  end
@@ -205,18 +211,22 @@ module Externals
205
211
  end
206
212
 
207
213
  #this is a test helper method
214
+ # TODO: can we move it to the test suite, then?
208
215
  def self.add_all
216
+ # simplecov:disable
209
217
  puts `git add .`
210
218
  raise unless $? == 0
219
+ # simplecov:enable
211
220
  end
212
221
 
213
222
  def ignore_contains? path
214
223
  text = ignore_text(path)
215
- text.split(/\n/).detect {|r| r.strip == path.strip}
224
+ text.split("\n").detect {|r| r.strip == path.strip}
216
225
  end
217
226
 
218
- def ignore_text(path = nil)
227
+ def ignore_text(_path = nil)
219
228
  return '' unless File.exist?('.gitignore')
229
+
220
230
  retval = ''
221
231
  open('.gitignore') do |f|
222
232
  retval = f.read
@@ -227,7 +237,7 @@ module Externals
227
237
  def ignore_rows(path)
228
238
  rows = ignore_text(path) || ''
229
239
 
230
- rows = rows.split(/\n/)
240
+ rows = rows.split("\n")
231
241
 
232
242
  rows.delete_if {|row| row =~ /^\s*$/}
233
243
 
@@ -248,14 +258,18 @@ module Externals
248
258
 
249
259
  def drop_from_ignore path
250
260
  ir = ignore_rows(path)
251
- rows = ir.select {|row| row.strip != path.strip}
261
+ rows = ir.reject {|row| row.strip == path.strip}
252
262
 
253
263
  if rows.size == ir.size
264
+ # simplecov:disable
254
265
  raise "row not found matching #{path} in .gitignore"
266
+ # simplecov:enable
255
267
  end
256
268
 
257
269
  if ir.size - rows.size != 1
270
+ # simplecov:disable
258
271
  raise "More than one row found matching #{path} in .gitignore"
272
+ # simplecov:enable
259
273
  end
260
274
 
261
275
  open('.gitignore', 'w') do |f|
@@ -279,11 +293,10 @@ module Externals
279
293
  end
280
294
  end
281
295
 
282
- def extract_name s
283
- if s =~ /([^\/:]+?)(?:\.git|\.bundle)?$/
296
+ def extract_name string
297
+ if string =~ /([^\/:]+?)(?:\.git|\.bundle)?$/
284
298
  $1
285
299
  end
286
300
  end
287
-
288
301
  end
289
302
  end