safe_update 0.3.2 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/safe_update/bundle_outdated_parser.rb +60 -0
- data/lib/safe_update/outdated_gem.rb +13 -42
- data/lib/safe_update/updater.rb +1 -20
- data/lib/safe_update/version.rb +1 -1
- data/lib/safe_update.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a34ecfbe5b686673a2abc202136461330aaa4f2f
|
4
|
+
data.tar.gz: ebea4606b6853cf0f3e27747eb3eebea8b7fd574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7aa962362fc264c326369a662f2e5e2a75bae8b6c5b196c4747cf48e9f0c49e7f73cf90eabc8bf3ee29bef75dd6e5d49b65446d4a5e5ff2fa4deb365d01724
|
7
|
+
data.tar.gz: 172d61cd95fcd536f9494ba89887e8d10f1fd94a00cd90826b04afcd250925a68860ebd62a0d4970e7152f39ebab454ec7a21c4c0d629e45f558ebf248b6f28e
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# This class runs `bundle outdated` and parses the output
|
2
|
+
# into a workable data structure in Ruby.
|
3
|
+
module SafeUpdate
|
4
|
+
class BundleOutdatedParser
|
5
|
+
def call
|
6
|
+
@outdated_gems = []
|
7
|
+
# Yes, I know about `bundle outdated --parseable` but old versions
|
8
|
+
# don't support it and it's really not THAT much more parseable anyway
|
9
|
+
# and parseable still sometimes has lines that aren't relevant
|
10
|
+
@output = `bundle outdated`
|
11
|
+
@output.split(/\n+/).each do |line|
|
12
|
+
process_single_line(line)
|
13
|
+
end
|
14
|
+
return @outdated_gems
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def process_single_line(line)
|
20
|
+
# guard clause for output that's not an outdated gem
|
21
|
+
return if !line.include?(' (newest')
|
22
|
+
# get rid of leading *, eg in ' * poltergeist (newest 1.9.0, installed 1.8.1)'
|
23
|
+
line.strip!
|
24
|
+
line.gsub!(/^\*/, '')
|
25
|
+
line.strip!
|
26
|
+
|
27
|
+
@outdated_gems << OutdatedGem.new(
|
28
|
+
gem_name: gem_name(line),
|
29
|
+
newest: newest(line),
|
30
|
+
installed: installed(line),
|
31
|
+
requested: requested(line)
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def gem_name(line)
|
36
|
+
string_between(line, '', ' (newest')
|
37
|
+
end
|
38
|
+
|
39
|
+
def newest(line)
|
40
|
+
string_between(line, ' (newest ', ', installed')
|
41
|
+
end
|
42
|
+
|
43
|
+
def requested(line)
|
44
|
+
string_between(line, ', requested ', ')')
|
45
|
+
end
|
46
|
+
|
47
|
+
def installed(line)
|
48
|
+
if line.index('requested')
|
49
|
+
string_between(line, ', installed ', ', requested')
|
50
|
+
else
|
51
|
+
string_between(line, ', installed ', ')')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# returns the section of string that resides between marker1 and marker2
|
56
|
+
def string_between(string, marker1, marker2)
|
57
|
+
string[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,26 +1,22 @@
|
|
1
1
|
module SafeUpdate
|
2
2
|
class OutdatedGem
|
3
|
-
attr_reader :newest, :installed, :requested
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
@git_repo = git_repo || GitRepo.new
|
11
|
-
if name.to_s.empty?
|
12
|
-
fail "Unexpected output from `bundle outdated --parseable`: #{@line}"
|
13
|
-
end
|
3
|
+
attr_reader :gem_name, :newest, :installed, :requested
|
4
|
+
def initialize(opts = {})
|
5
|
+
@gem_name = opts[:gem_name]
|
6
|
+
@newest = opts[:newest]
|
7
|
+
@installed = opts[:installed]
|
8
|
+
@requested = opts[:requested]
|
9
|
+
@git_repo = opts[:git_repo] || GitRepo.new
|
14
10
|
end
|
15
11
|
|
16
12
|
def attempt_update(test_command = nil)
|
17
13
|
puts '-------------'
|
18
|
-
puts "OUTDATED GEM: #{
|
19
|
-
puts " Newest: #{newest}. "
|
20
|
-
puts "Installed: #{installed}."
|
21
|
-
puts "Running `bundle update #{
|
14
|
+
puts "OUTDATED GEM: #{@gem_name}"
|
15
|
+
puts " Newest: #{@newest}. "
|
16
|
+
puts "Installed: #{@installed}."
|
17
|
+
puts "Running `bundle update #{@gem_name}`..."
|
22
18
|
|
23
|
-
`bundle update #{
|
19
|
+
`bundle update #{@gem_name}`
|
24
20
|
|
25
21
|
# sometimes the gem may be outdated, but it's matching the
|
26
22
|
# version required by the gemfile, so bundle update does nothing
|
@@ -43,35 +39,10 @@ module SafeUpdate
|
|
43
39
|
@git_repo.commit_gemfile_lock(commit_message)
|
44
40
|
end
|
45
41
|
|
46
|
-
def name
|
47
|
-
string_between(@line, '', ' (newest')
|
48
|
-
end
|
49
|
-
|
50
|
-
def newest
|
51
|
-
string_between(@line, ' (newest ', ', installed')
|
52
|
-
end
|
53
|
-
|
54
|
-
def requested
|
55
|
-
string_between(@line, ', requested ', ')')
|
56
|
-
end
|
57
|
-
|
58
|
-
def installed
|
59
|
-
if @line.index('requested')
|
60
|
-
string_between(@line, ', installed ', ', requested')
|
61
|
-
else
|
62
|
-
string_between(@line, ', installed ', ')')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
42
|
private
|
67
43
|
|
68
44
|
def commit_message
|
69
|
-
"update gem: #{
|
70
|
-
end
|
71
|
-
|
72
|
-
# returns the section of string that resides between marker1 and marker2
|
73
|
-
def string_between(string, marker1, marker2)
|
74
|
-
string[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
|
45
|
+
"update gem: #{@gem_name}"
|
75
46
|
end
|
76
47
|
end
|
77
48
|
end
|
data/lib/safe_update/updater.rb
CHANGED
@@ -29,26 +29,7 @@ module SafeUpdate
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def outdated_gems
|
32
|
-
|
33
|
-
|
34
|
-
@outdated_gems = []
|
35
|
-
bundle_outdated_parseable.split(/\n+/).each do |line|
|
36
|
-
@outdated_gems << OutdatedGem.new(line, @git_repo)
|
37
|
-
end
|
38
|
-
return @outdated_gems
|
39
|
-
end
|
40
|
-
|
41
|
-
def bundle_outdated_parseable
|
42
|
-
output = `bundle outdated --parseable`
|
43
|
-
if output.strip == "Unknown switches '--parseable'"
|
44
|
-
# pre-1.12.0 version of bundler
|
45
|
-
output = `bundle outdated`
|
46
|
-
output.gsub!(/(\n|.)*Outdated gems included in the bundle:/, '')
|
47
|
-
output.gsub!(/ \* /, '')
|
48
|
-
output.gsub!(/ in group.*/, '')
|
49
|
-
end
|
50
|
-
|
51
|
-
output.strip
|
32
|
+
BundleOutdatedParser.new.call
|
52
33
|
end
|
53
34
|
|
54
35
|
def display_finished_message
|
data/lib/safe_update/version.rb
CHANGED
data/lib/safe_update.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safe_update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Paling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- bin/setup
|
73
73
|
- exe/safe_update
|
74
74
|
- lib/safe_update.rb
|
75
|
+
- lib/safe_update/bundle_outdated_parser.rb
|
75
76
|
- lib/safe_update/git_repo.rb
|
76
77
|
- lib/safe_update/outdated_gem.rb
|
77
78
|
- lib/safe_update/updater.rb
|