safe_update 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2691acf87593613225b1c53fc4786d330791082c
4
- data.tar.gz: ed8afd4d7c0508445a1f2f37d847cfac7a647bba
3
+ metadata.gz: a34ecfbe5b686673a2abc202136461330aaa4f2f
4
+ data.tar.gz: ebea4606b6853cf0f3e27747eb3eebea8b7fd574
5
5
  SHA512:
6
- metadata.gz: 76fa5e5858e0a02595dc15f7f459ca310187e05cf73d80a9d452e5aa56a64489b30912dae3e1756f122d0bd2a89bf214640ca2d6f173804e92d4f1183dca0a14
7
- data.tar.gz: 9edfaab5bb002051bc1cc9fa135f930a5585b55de794ec1db7ab35012a58b159a0627eac3ffdf74d38c21a6f1b93b57863b390f0095abe31c2c04ebb71440676
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
- # line is a line from bundle outdated --parseable
6
- # eg. react-rails (newest 1.6.0, installed 1.5.0, requested ~> 1.0)
7
- # or. react-rails (newest 1.6.0, installed 1.5.0)
8
- def initialize(line, git_repo = nil)
9
- @line = line
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: #{name}"
19
- puts " Newest: #{newest}. "
20
- puts "Installed: #{installed}."
21
- puts "Running `bundle update #{name}`..."
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 #{name}`
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: #{name}"
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
@@ -29,26 +29,7 @@ module SafeUpdate
29
29
  private
30
30
 
31
31
  def outdated_gems
32
- return @outdated_gems if @outdated_gems
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
@@ -1,3 +1,3 @@
1
1
  module SafeUpdate
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
data/lib/safe_update.rb CHANGED
@@ -8,6 +8,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
8
8
  require 'safe_update/version'
9
9
  require 'safe_update/updater'
10
10
  require 'safe_update/outdated_gem'
11
+ require 'safe_update/bundle_outdated_parser'
11
12
  require 'safe_update/git_repo'
12
13
 
13
14
  module SafeUpdate
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.2
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-08-05 00:00:00.000000000 Z
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