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 +4 -4
- data/README.md +7 -16
- data/bin/console +2 -2
- data/lib/drg/tasks/gemfile.rb +12 -1
- data/lib/drg/tasks/gemfile_line.rb +1 -1
- data/lib/drg/tasks/updater.rb +36 -25
- data/lib/drg/version.rb +1 -1
- data/lib/drg.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64ddf75e8d9ec68fcf629d3bee1e94873ccf539f
|
4
|
+
data.tar.gz: b65f8d6a1ef6d3ade552f130173eb1b75a4c17cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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).
|
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`
|
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
|
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
data/lib/drg/tasks/gemfile.rb
CHANGED
@@ -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
|
data/lib/drg/tasks/updater.rb
CHANGED
@@ -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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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 [
|
20
|
-
def try_update(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
data/lib/drg.rb
CHANGED