drg 0.4.2 → 0.5.0

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: 64ddf75e8d9ec68fcf629d3bee1e94873ccf539f
4
- data.tar.gz: b65f8d6a1ef6d3ade552f130173eb1b75a4c17cc
3
+ metadata.gz: 9abe1205b4fdd0cf60c4a18a0e0820ecffd553be
4
+ data.tar.gz: ea1df095df062541a1f4dbb617b855f08e838125
5
5
  SHA512:
6
- metadata.gz: e72440e44018c17ce53ef2ac829a6cbfc078be2571116bc0ea1375fb1003e73527b3ab4b3b5b46d597a222960c03f2284f3d77a675e2e803a9b0da43c2171adb
7
- data.tar.gz: ebe2053f8c02d35a5d54e6eb704545cb890a27ed99c648a1b5da2f9b4873259d6406715aa9b0a99c7c87fc9a99997525a6c781adbb14020d90589babfbf01dbf
6
+ metadata.gz: f4bd3bf791edcc37126ceed1e832e4ebe6377c35db197fce3e13591923861183a4894c3ce3c8836789a46b53948e123d272c207ed77575f3fdba709aa04c7b98
7
+ data.tar.gz: be7a521bdacf28560799780803083ac5f019e29aeac50903fda4290110668d08fe183424030f17f635800c656e94d2c22112e8511936942f59e426ba36fa63d8
data/drg.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'drg/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "drg"
8
- spec.version = Drg::VERSION
8
+ spec.version = DRG::VERSION
9
9
  spec.authors = ["Ryan Buckley"]
10
10
  spec.email = ["arebuckley@gmail.com"]
11
11
  spec.summary = %q{DRG automation}
@@ -19,6 +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
23
 
23
24
  spec.add_development_dependency 'rake', '~> 10.0'
24
25
  spec.add_development_dependency 'rspec', '>= 3.2', '< 4'
@@ -3,8 +3,8 @@ module DRG
3
3
  class Gemfile
4
4
  attr_accessor :file
5
5
 
6
- def initialize
7
- @file = ::Bundler.default_gemfile
6
+ def initialize(file = ::Bundler.default_gemfile)
7
+ @file = file
8
8
  end
9
9
 
10
10
  # Saves a copy of @lines before changing it (note that #dup and #clone weren't working)
@@ -12,8 +12,13 @@ module DRG
12
12
  # @param [GemfileLine] gem
13
13
  # @param [String] version to update the gem line with
14
14
  def update(gem, version)
15
- @saved_lines = Marshal.load Marshal.dump(lines)
16
15
  lines[gem] = gem.update version
16
+ write
17
+ end
18
+
19
+ def remove_version(gem)
20
+ lines[gem] = gem.remove_version
21
+ write
17
22
  end
18
23
 
19
24
  def find_by_name(name)
@@ -25,14 +30,6 @@ module DRG
25
30
  nil
26
31
  end
27
32
 
28
- def lines
29
- @lines ||= File.readlines file
30
- end
31
-
32
- def saved_lines
33
- @saved_lines ||= lines
34
- end
35
-
36
33
  def write
37
34
  File.open file, 'wb' do |f|
38
35
  lines.each do |line|
@@ -41,9 +38,8 @@ module DRG
41
38
  end
42
39
  end
43
40
 
44
- def rollback
45
- @lines = saved_lines
46
- write
41
+ def lines
42
+ @lines ||= File.readlines file
47
43
  end
48
44
  end
49
45
  end
@@ -9,17 +9,30 @@ module DRG
9
9
  end
10
10
 
11
11
  # @param [String] version is the new value for the gem (add/replace)
12
+ # @return [String] line
12
13
  def update(version)
14
+ swap_version(", '#{version.to_s}'")
15
+ end
16
+
17
+ # @return [String] line
18
+ def remove_version
19
+ swap_version('')
20
+ end
21
+
22
+ # @return [String] line
23
+ def swap_version(full_version)
24
+ comment = line =~ /#/ ? " #{line.slice!(/#.*/).strip}" : ''
13
25
  if line =~ /,.+\n?/
14
26
  if line =~ /,\s*['"].+['"]/
15
- line[/,\s*['"].+['"]/] = ", '#{version.to_s}'"
27
+ line[/,\s*['"].+['"]/] = full_version
16
28
  else
17
- line[/,\s*/] = ", '#{version.to_s}', "
29
+ line[/,\s*/] = "#{full_version}, "
30
+ line[/\n/] = "#{comment}\n"
18
31
  end
19
32
  elsif line.end_with?("\n")
20
- line.sub!("\n", ", '#{version.to_s}'\n")
33
+ line.sub!("\n", "#{full_version}#{comment}\n")
21
34
  else
22
- line << ", '#{version.to_s}'\n"
35
+ line << full_version << comment << "\n"
23
36
  end
24
37
  line
25
38
  end
@@ -9,13 +9,21 @@ module DRG
9
9
  end
10
10
 
11
11
  def perform
12
- log %Q(Pinning Gemfile "#{gemfile}")
12
+ log %Q(Pinning Gemfile "#{gemfile.file}")
13
13
  ::Bundler.locked_gems.specs.each do |spec|
14
14
  gem = gemfile.find_by_name spec.name
15
15
  next unless gem
16
16
  gemfile.update gem, public_send(type, spec.version.to_s)
17
17
  end
18
- gemfile.write
18
+ log %Q(Done)
19
+ end
20
+
21
+ def unpin
22
+ log %Q(Unpinning Gemfile "#{gemfile.file}")
23
+ ::Bundler.locked_gems.specs.each do |spec|
24
+ gem = gemfile.find_by_name spec.name
25
+ gemfile.remove_version gem if gem
26
+ end
19
27
  log %Q(Done)
20
28
  end
21
29
 
@@ -25,27 +25,32 @@ module DRG
25
25
  log(%Q[Trying to update gem "#{gem.name}" from #{current_version} to #{latest_version}])
26
26
  try_update(gem, latest_version)
27
27
  end
28
+ if $?.to_i.nonzero?
29
+ fail Bundler::GemNotFound, "Failed to load the environment. Maybe do `bundle` and try again"
30
+ end
28
31
  end
29
32
 
30
33
  # @param [GemfileLine] gem
31
34
  def try_update(gem, latest_version)
32
- gemfile.update(gem, latest_version)
33
- gemfile.write
35
+ gemfile.remove_version gem
34
36
  bundler.update(gem.name)
37
+ if $0.to_i.zero?
38
+ log(%Q[Succeeded in installing "#{gem.name}" (#{latest_version})])
39
+ if system('rake')
40
+ log(%Q[Tests passed! Updating Gemfile with ... "#{gem.name}" (#{latest_version})])
41
+ gemfile.update(gem, latest_version)
42
+ else
43
+ failures << gem.name
44
+ end
45
+ else
46
+ fail StandardError, %Q[Failed to update "#{gem.name}"]
47
+ end
35
48
  rescue Bundler::GemNotFound, Bundler::InstallError
36
49
  log %Q[Failed to find "#{gem.name}" (#{latest_version})]
37
- gemfile.rollback
38
50
  rescue Bundler::VersionConflict
39
51
  # @todo retry it later
40
52
  failures << gem.name
41
- gemfile.rollback
42
53
  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
48
- end
49
54
  end
50
55
 
51
56
  # @note not used
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Drg
2
- VERSION = '0.4.2'.freeze
1
+ module DRG
2
+ VERSION = '0.5.0'.freeze
3
3
  end
data/lib/drg.rb CHANGED
@@ -4,6 +4,9 @@ require 'bundler'
4
4
  require 'bundler/cli'
5
5
  require 'drg/version'
6
6
 
7
+ # defines #clone!
8
+ # DuckPuncher.load! :Object
9
+
7
10
  module DRG
8
11
  autoload :FileReader, 'drg/file_reader'
9
12
  autoload :Scanner, 'drg/scanner'
data/lib/tasks/drg.rake CHANGED
@@ -1,16 +1,23 @@
1
1
  require 'rake'
2
2
 
3
3
  namespace :drg do
4
- desc 'Pins your gems in the Gemfile to the current version (using Gemfile.lock)'
4
+ desc "Pins the gems in your Gemfile to the current version in the Gemfile.lock"
5
5
  task :pin do
6
6
  DRG::Tasks::Pinner.new.perform
7
7
  end
8
8
 
9
+ desc 'Unpins the gems in your the Gemfile'
10
+ task :unpin do
11
+ DRG::Tasks::Pinner.new.unpin
12
+ end
13
+
9
14
  namespace :pin do
15
+ desc 'Adds the fuzzy match operator to the minor version of your gems (e.g. rails, "~> 4.2")'
10
16
  task :minor do
11
17
  DRG::Tasks::Pinner.new(:minor).perform
12
18
  end
13
19
 
20
+ desc 'Adds the fuzzy match operator to the major version of your gems (e.g. rails, "~> 4")'
14
21
  task :major do
15
22
  DRG::Tasks::Pinner.new(:major).perform
16
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-17 00:00:00.000000000 Z
11
+ date: 2015-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler