drg 0.4.1 → 0.4.2

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: fefdf1d9cd212f2ee36433f9c2d259612dd53d03
4
- data.tar.gz: 9b53797151e4207130e5c5bbadebd06f086c6025
3
+ metadata.gz: 64ddf75e8d9ec68fcf629d3bee1e94873ccf539f
4
+ data.tar.gz: b65f8d6a1ef6d3ade552f130173eb1b75a4c17cc
5
5
  SHA512:
6
- metadata.gz: 68179fa7f8061ff784872e30e0c77a46bdb4546cda7749f7cafed1da4bbcb56da35cc491789e1ee3f235b69ff79e81e9a0d3c6d3e95e2fc6ee82f11b7265da69
7
- data.tar.gz: 174250acc39178991ba52476660d5fbabafbc44f156070e138a0763fd8d05fd9a67b5bb84fc6bf80927b2c3feee3be91099e039f5e7ce8f5bffb3be2abe5210e
6
+ metadata.gz: e72440e44018c17ce53ef2ac829a6cbfc078be2571116bc0ea1375fb1003e73527b3ab4b3b5b46d597a222960c03f2284f3d77a675e2e803a9b0da43c2171adb
7
+ data.tar.gz: ebe2053f8c02d35a5d54e6eb704545cb890a27ed99c648a1b5da2f9b4873259d6406715aa9b0a99c7c87fc9a99997525a6c781adbb14020d90589babfbf01dbf
data/README.md CHANGED
@@ -10,14 +10,6 @@ Add this line to your application's Gemfile:
10
10
  gem 'drg'
11
11
  ```
12
12
 
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install drg
20
-
21
13
  ## Usage
22
14
 
23
15
  ### Pinning Gems
@@ -40,7 +32,7 @@ gem 'therubyracer', '~> 0.12', platforms: :ruby
40
32
  gem 'drg'
41
33
  ```
42
34
 
43
- to
35
+ it'll get changed to
44
36
 
45
37
  ```ruby
46
38
  gem 'rails', '4.2.3'
@@ -48,10 +40,10 @@ gem 'byebug', '5.0.0', require: false
48
40
  gem 'therubyracer', '0.12.2', platforms: :ruby
49
41
 
50
42
  # gotta include ourselves
51
- gem 'drg', '0.3.1'
43
+ gem 'drg', '0.4.1'
52
44
  ```
53
45
 
54
- Although, you may want to pin gems with their _minor_ version (which allows updating patches). To do this, just run:
46
+ Although, you may want to pin gems with their _minor_ version (which allows updating patches). Run:
55
47
 
56
48
  ```bash
57
49
  rake drg:pin:minor
@@ -72,9 +64,9 @@ gem 'rails', '~> 4.2'
72
64
  Pinning ignores gems that are fetched from somewhere other than rubygems. For example, gems listed with `:git`, `:github`,
73
65
  or `:path` will be ignored.
74
66
 
75
- There is also a `rake drg:pin:major` that does what you think.
67
+ There is also a `rake drg:pin:major` which does what you think.
76
68
 
77
- This can be combined with `bundle update` to quickly update all gems to the latest patch level.
69
+ This can be combined with `bundle update` to quickly update all gems to the latest patch or minor level.
78
70
 
79
71
  ### Updating Gems
80
72
 
@@ -87,9 +79,8 @@ rake drg:update
87
79
 
88
80
  ## Development
89
81
 
90
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
91
-
92
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
82
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests.
83
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
93
84
 
94
85
  ## Contributing
95
86
 
data/bin/console CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'bundler/setup'
4
4
  require 'pp'
5
5
 
6
- require 'ruby2ruby'
7
- require 'ruby_parser'
6
+ # require 'ruby2ruby'
7
+ # require 'ruby_parser'
8
8
 
9
9
  require 'rspec'
10
10
  require 'object_tracker'
@@ -7,9 +7,12 @@ module DRG
7
7
  @file = ::Bundler.default_gemfile
8
8
  end
9
9
 
10
+ # Saves a copy of @lines before changing it (note that #dup and #clone weren't working)
11
+ #
10
12
  # @param [GemfileLine] gem
11
13
  # @param [String] version to update the gem line with
12
14
  def update(gem, version)
15
+ @saved_lines = Marshal.load Marshal.dump(lines)
13
16
  lines[gem] = gem.update version
14
17
  end
15
18
 
@@ -17,7 +20,7 @@ module DRG
17
20
  lines.each_with_index.each do |line, index|
18
21
  next if line =~ /:?path:?\s*(=>)?\s*/
19
22
  next if line =~ /:?git(hub)?:?\s*(=>)?\s*/
20
- return GemfileLine.new line, index if line =~ /gem\s*['"]#{name}["']/
23
+ return GemfileLine.new line, index, name if line =~ /gem\s*['"]#{name}["']/
21
24
  end
22
25
  nil
23
26
  end
@@ -26,6 +29,10 @@ module DRG
26
29
  @lines ||= File.readlines file
27
30
  end
28
31
 
32
+ def saved_lines
33
+ @saved_lines ||= lines
34
+ end
35
+
29
36
  def write
30
37
  File.open file, 'wb' do |f|
31
38
  lines.each do |line|
@@ -34,6 +41,10 @@ module DRG
34
41
  end
35
42
  end
36
43
 
44
+ def rollback
45
+ @lines = saved_lines
46
+ write
47
+ end
37
48
  end
38
49
  end
39
50
  end
@@ -1,6 +1,6 @@
1
1
  module DRG
2
2
  module Tasks
3
- class GemfileLine < Struct.new(:line, :index)
3
+ class GemfileLine < Struct.new(:line, :index, :name)
4
4
  alias to_s line
5
5
  alias to_int index
6
6
 
@@ -1,39 +1,50 @@
1
1
  module DRG
2
2
  module Tasks
3
3
  class Updater
4
- attr_reader :gemfile
4
+ attr_reader :gemfile, :failures, :bundler
5
5
 
6
6
  def initialize
7
7
  @gemfile = Gemfile.new
8
- @versions = {}
9
8
  @failures = Set.new
9
+ @bundler = Bundler::CLI.new [], debug: true, current_command: OpenStruct.new
10
+ @versions = {}
10
11
  end
11
12
 
12
- def perform(tries = 2)
13
- `bundle outdated`.scan(/\s\*\s(.+)\s/).flatten.each &method(:try_update)
14
- perform(tries -= 1) if @failures.any? && tries > 1
15
- gemfile.write
16
- `bundle` # Install all new dependencies for updated gems
13
+ # Updates the projects outdated gems listed in the Gemfile
14
+ #
15
+ # @todo Incrementally update the gem using +versions+
16
+ # @todo Cleanup old gems when finished
17
+ # @note `bundle outdated` returns lines that look like 'slop (newest 4.2.0, installed 3.6.0) in group "default"'
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
17
28
  end
18
29
 
19
- # @param [Item] item from the `bundle outdated` command (e.g. 'slop (newest 4.2.0, installed 3.6.0) in group "default"')
20
- def try_update(item)
21
- name = item[/([\-\w0-9]+)\s/, 1]
22
- gem = gemfile.find_by_name(name)
23
- return unless gem
24
- `bundle` # make sure current list is up-to-date
25
- latest_version = item[/newest\s([\d.]+)/, 1]
26
- log(%Q(Trying to update gem "#{name}" to #{latest_version}))
27
- if system("bundle update #{name}")
28
- log(%Q[Succeeded in installing "#{name}" (#{latest_version})])
29
- if system('rake')
30
- log(%Q(Tests passed after updating "#{name}" to version #{latest_version}))
31
- gemfile.update(gem, latest_version)
32
- else
33
- @failures << name
34
- end
35
- else
36
- @failures << name
30
+ # @param [GemfileLine] gem
31
+ def try_update(gem, latest_version)
32
+ gemfile.update(gem, latest_version)
33
+ gemfile.write
34
+ bundler.update(gem.name)
35
+ rescue Bundler::GemNotFound, Bundler::InstallError
36
+ log %Q[Failed to find "#{gem.name}" (#{latest_version})]
37
+ gemfile.rollback
38
+ rescue Bundler::VersionConflict
39
+ # @todo retry it later
40
+ failures << gem.name
41
+ gemfile.rollback
42
+ log %Q(Failed to find a compatible version of "#{gem.name}")
43
+ else
44
+ log(%Q[Succeeded in installing "#{gem.name}" (#{latest_version})])
45
+ unless system('rake')
46
+ failures << gem.name
47
+ gemfile.rollback
37
48
  end
38
49
  end
39
50
 
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Drg
2
- VERSION = '0.4.1'.freeze
2
+ VERSION = '0.4.2'.freeze
3
3
  end
data/lib/drg.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'set'
3
3
  require 'bundler'
4
+ require 'bundler/cli'
4
5
  require 'drg/version'
5
6
 
6
7
  module DRG
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley