drg 0.5.0 → 0.5.1

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: 9abe1205b4fdd0cf60c4a18a0e0820ecffd553be
4
- data.tar.gz: ea1df095df062541a1f4dbb617b855f08e838125
3
+ metadata.gz: 64ab93e66f0e85ab52aad6415ff9742dc974eff3
4
+ data.tar.gz: cd44e409518042394da5dd01f18833cb51b37c2b
5
5
  SHA512:
6
- metadata.gz: f4bd3bf791edcc37126ceed1e832e4ebe6377c35db197fce3e13591923861183a4894c3ce3c8836789a46b53948e123d272c207ed77575f3fdba709aa04c7b98
7
- data.tar.gz: be7a521bdacf28560799780803083ac5f019e29aeac50903fda4290110668d08fe183424030f17f635800c656e94d2c22112e8511936942f59e426ba36fa63d8
6
+ metadata.gz: 34adbd98f8df9b92863b0b4349895e9241853070c24f99c333f309cbea81a3fd130b49712f73c513073aa521ac59c9f1cca02e4ae60a14bf37cafe215498bf27
7
+ data.tar.gz: bd191ee0cba818a2be8e1074bac1e512bed7a42b266542953f66d83e9b5f88aeab9b1d7b5681a9e649fe5574d7ef35cb761c59b8b58ef48f51bb0729339aa526
data/README.md CHANGED
@@ -10,12 +10,30 @@ Add this line to your application's Gemfile:
10
10
  gem 'drg'
11
11
  ```
12
12
 
13
- ## Usage
13
+ ## Tasks
14
14
 
15
- ### Pinning Gems
15
+ ```bash
16
+ rake drg:update
17
+ rake drg:pin
18
+ rake drg:pin:minor
19
+ rake drg:pin:major
20
+ rake drg:unpin
21
+ ```
22
+
23
+ ### drg:update
24
+
25
+ DRG can update your outdated gems, one-by-one, to the latest version. It'll update the gem and then run your tests.
26
+ If your tests pass, then the new version will be written to your Gemfile (similar to Gemnasium).
27
+
28
+ ```bash
29
+ rake drg:update
30
+ ```
31
+
32
+ ### pin
16
33
 
17
34
  DRG really wants to help you manage your project's gems. But DRG doesn't want to replace Bundler. Instead we want to build on
18
- it. You can "pin" all your versions to the current version listed in the Gemfile.lock:
35
+ it. Pinning ignores gems that are fetched from somewhere other than rubygems. For example, gems listed with `:git`, `:github`,
36
+ or `:path` will be ignored. You can "pin" all your versions to the current version listed in the Gemfile.lock:
19
37
 
20
38
  ```bash
21
39
  rake drg:pin
@@ -27,8 +45,6 @@ Which will change gems list in your Gemfile to their full version. So if you hav
27
45
  gem 'rails'
28
46
  gem 'byebug', require: false
29
47
  gem 'therubyracer', '~> 0.12', platforms: :ruby
30
-
31
- # gotta include ourselves
32
48
  gem 'drg'
33
49
  ```
34
50
 
@@ -38,18 +54,18 @@ it'll get changed to
38
54
  gem 'rails', '4.2.3'
39
55
  gem 'byebug', '5.0.0', require: false
40
56
  gem 'therubyracer', '0.12.2', platforms: :ruby
41
-
42
- # gotta include ourselves
43
57
  gem 'drg', '0.4.1'
44
58
  ```
45
59
 
60
+ ### pin:minor
61
+
46
62
  Although, you may want to pin gems with their _minor_ version (which allows updating patches). Run:
47
63
 
48
64
  ```bash
49
65
  rake drg:pin:minor
50
66
  ```
51
67
 
52
- This will change a gem listed like
68
+ Which will update your Gemfile from
53
69
 
54
70
  ```ruby
55
71
  gem 'rails', '4.2.3'
@@ -61,20 +77,22 @@ to
61
77
  gem 'rails', '~> 4.2'
62
78
  ```
63
79
 
64
- Pinning ignores gems that are fetched from somewhere other than rubygems. For example, gems listed with `:git`, `:github`,
65
- or `:path` will be ignored.
80
+ This can be combined with `bundle update` to quickly update all gems to the latest patch or minor level.
66
81
 
67
- There is also a `rake drg:pin:major` which does what you think.
82
+ ### pin:major
68
83
 
69
- This can be combined with `bundle update` to quickly update all gems to the latest patch or minor level.
84
+ There is also a
70
85
 
71
- ### Updating Gems
86
+ ```bash
87
+ rake drg:pin:major
88
+ ```
72
89
 
73
- DRG can also try to update all outdated gems to the most recent version. It'll update the gem and run your tests. If your
74
- tests pass, then it'll update your gemfile with the current version. Similar to what Gemnasium offers (experience may vary).
90
+ ### drg:unpin
91
+
92
+ Remove the versions from your Gemfile. Start fresh!
75
93
 
76
94
  ```bash
77
- rake drg:update
95
+ rake drg:unpin
78
96
  ```
79
97
 
80
98
  ## Development
data/drg.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  # spec.add_dependency 'ruby_parser', '>= 3.7.0', '< 4.0.0'
20
20
  # spec.add_dependency 'ruby2ruby', '>= 2.2.0', '< 3.0.0'
21
21
  spec.add_dependency 'bundler', '~> 1.10'
22
- # spec.add_dependency 'duck_puncher', '1.0.0'
22
+ spec.add_dependency 'duck_puncher', '1.0.0'
23
23
 
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
25
  spec.add_development_dependency 'rspec', '>= 3.2', '< 4'
@@ -17,6 +17,7 @@ module DRG
17
17
  end
18
18
 
19
19
  def remove_version(gem)
20
+ saved_lines << lines.clone!
20
21
  lines[gem] = gem.remove_version
21
22
  write
22
23
  end
@@ -38,6 +39,16 @@ module DRG
38
39
  end
39
40
  end
40
41
 
42
+ def rollback
43
+ return if saved_lines.empty?
44
+ lines.replace saved_lines.pop
45
+ write
46
+ end
47
+
48
+ def saved_lines
49
+ @saved_lines ||= []
50
+ end
51
+
41
52
  def lines
42
53
  @lines ||= File.readlines file
43
54
  end
@@ -16,41 +16,48 @@ module DRG
16
16
  # @todo Cleanup old gems when finished
17
17
  # @note `bundle outdated` returns lines that look like 'slop (newest 4.2.0, installed 3.6.0) in group "default"'
18
18
  def perform
19
- `bundle outdated`.scan(/\s\*\s(.+)\s/).flatten.each do |item|
20
- name = item[/([\-\w0-9]+)\s/, 1]
21
- gem = gemfile.find_by_name(name)
22
- next unless gem
23
- latest_version = item[/newest\s([\d.\w]+)/, 1]
24
- current_version = item[/installed\s([\d.\w]+)/, 1]
25
- log(%Q[Trying to update gem "#{gem.name}" from #{current_version} to #{latest_version}])
26
- try_update(gem, latest_version)
27
- end
28
- if $?.to_i.nonzero?
29
- fail Bundler::GemNotFound, "Failed to load the environment. Maybe do `bundle` and try again"
19
+ log 'Searching for outdated gems ....'
20
+ outdated = `bundle outdated`.scan(/\s\*\s(.+)\s/).flatten
21
+ gems = outdated.map do |item|
22
+ gem = OpenStruct.new
23
+ gem.name = item[/([\-\w0-9]+)\s/, 1]
24
+ gem.entry = gemfile.find_by_name(gem.name)
25
+ next unless gem.entry
26
+ gem.latest_version = item[/newest\s([\d.\w]+)/, 1]
27
+ gem.current_version = item[/installed\s([\d.\w]+)/, 1]
28
+ gem
29
+ end.compact
30
+ if gems.any?
31
+ gems.each &method(:try_update)
32
+ else
33
+ log 'All gems up to date!'
30
34
  end
31
35
  end
32
36
 
33
- # @param [GemfileLine] gem
34
- def try_update(gem, latest_version)
35
- gemfile.remove_version gem
37
+ # @param [OpenStruct] gem
38
+ def try_update(gem)
39
+ log(%Q[Updating "#{gem.name}" from #{gem.current_version} to #{gem.latest_version}])
40
+ gemfile.remove_version gem.entry
36
41
  bundler.update(gem.name)
37
42
  if $0.to_i.zero?
38
- log(%Q[Succeeded in installing "#{gem.name}" (#{latest_version})])
43
+ log(%Q[Succeeded in installing "#{gem.name}" (#{gem.latest_version})])
39
44
  if system('rake')
40
- log(%Q[Tests passed! Updating Gemfile with ... "#{gem.name}" (#{latest_version})])
41
- gemfile.update(gem, latest_version)
45
+ log(%Q[Tests passed! Updating Gemfile entry for "#{gem.name}" to #{gem.latest_version}])
46
+ gemfile.update(gem.entry, gem.latest_version)
42
47
  else
43
48
  failures << gem.name
44
49
  end
45
50
  else
46
51
  fail StandardError, %Q[Failed to update "#{gem.name}"]
47
52
  end
48
- rescue Bundler::GemNotFound, Bundler::InstallError
49
- log %Q[Failed to find "#{gem.name}" (#{latest_version})]
50
- rescue Bundler::VersionConflict
51
- # @todo retry it later
53
+ rescue Bundler::GemNotFound, Bundler::InstallError, Bundler::VersionConflict => e
54
+ log %Q[Failed to find a compatible of "#{gem.name}" (#{gem.latest_version}): #{e.class} #{e.message}]
55
+ gemfile.rollback
52
56
  failures << gem.name
53
- log %Q(Failed to find a compatible version of "#{gem.name}")
57
+ # @todo retry it later
58
+ rescue => e
59
+ puts "#{e.class}: #{e.message} #{e.backtrace}"
60
+ gemfile.rollback
54
61
  end
55
62
 
56
63
  # @note not used
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DRG
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.5.1'.freeze
3
3
  end
data/lib/drg.rb CHANGED
@@ -3,9 +3,10 @@ require 'set'
3
3
  require 'bundler'
4
4
  require 'bundler/cli'
5
5
  require 'drg/version'
6
+ require 'duck_puncher'
6
7
 
7
8
  # defines #clone!
8
- # DuckPuncher.load! :Object
9
+ DuckPuncher.load! :Object
9
10
 
10
11
  module DRG
11
12
  autoload :FileReader, 'drg/file_reader'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: duck_puncher
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement