drg 1.2.2 → 1.2.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: fc8458eead2110fb89a28e5594fce74bd3cecaa2
4
- data.tar.gz: b08d8bbc72aaf3fa8de3b20f5b07a1ffa08deec9
3
+ metadata.gz: 5d977148d147d5723ae15052033d4dcb47c8b61f
4
+ data.tar.gz: e2cab2591d53736ebd56955b776f1d93ed473c36
5
5
  SHA512:
6
- metadata.gz: 45cba115c9a853f42d363f8810f83ee3edb455e0898692a3bd9fb431a3a010e39c771b2b88d2a2d7ed23fb4e96bcf331cbb392b85cbe2e8fd45704d921eb219f
7
- data.tar.gz: a49c11efdf04d9d13909c6c4f3b4fb75e52300c29d1b68bddb380e8673c74247b032b2743b3727ba3a0d2cc51e05ef83e9f7b74c414b1165b26f7dceaead1cf9
6
+ metadata.gz: 7b4aabe2fb664f1c7a7c32c15685c5337da7384a3f1b26cf9c77e487378f47733dee129e03c3ee2840a2f07c668a150583afa88cfeb15c1a505c1bf194fb6f2f
7
+ data.tar.gz: a16ef93951806031a4ddebb84c34741657e5f38cf05c907ac5457d159c1cbf392128f381c0580b1ff25834d87ff50b75a2517f0f57bd5db49da7b9bf325e3df9
data/.travis.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.5
6
+ - 2.2.0
4
7
  - 2.2.1
5
8
  - 2.2.2
6
9
  - 2.2.3
@@ -107,8 +107,18 @@ module DRG
107
107
  # @param [Array] list of a gem version's segments
108
108
  # @param [Array] other_list of another gem version's segments
109
109
  def higher?(list, other_list)
110
- gem_version_segments = (0..2).to_a
111
- gem_version_segments.any? { |i| list[i].to_i > other_list[i].to_i }
110
+ higher = false
111
+ equal = false
112
+ sem_ver_size = [list.size, other_list.size].max
113
+ sem_ver_size.times do |i|
114
+ if list[i].to_i >= other_list[i].to_i
115
+ higher = true
116
+ equal = list[i].to_i == other_list[i].to_i
117
+ else
118
+ break
119
+ end
120
+ end
121
+ higher && !equal
112
122
  end
113
123
  end
114
124
  end
@@ -11,7 +11,7 @@ module DRG
11
11
  # @param [String] version is the new value for the gem (add/replace)
12
12
  # @return [String] line
13
13
  def update(new_version)
14
- swap_version(", '#{new_version.to_s}'")
14
+ swap_version("'#{new_version.to_s}'")
15
15
  end
16
16
 
17
17
  # @return [String] line
@@ -19,27 +19,48 @@ module DRG
19
19
  swap_version('')
20
20
  end
21
21
 
22
+ # @description Replaces the gem version with the given one
23
+ # @example
24
+ #
25
+ # line = "gem 'duck_puncher', '> 1', '< 2', require: false # dude"
26
+ # swap_version('1.5.5')
27
+ # line # => "gem 'duck_puncher', '1.5.5', require: false # dude"
28
+ #
29
+ # @destructive Modifies @line in place
30
+ # @param [String] full_version is the quoted version to update or remove from the gem line
22
31
  # @return [String] line
23
32
  def swap_version(full_version)
24
- comment = line =~ /#/ ? " #{line.slice!(/#.*/).strip}" : ''
25
- if line =~ /,.+\n?/
26
- if line =~ /,.*[\d.]+.*,.*require.+/
27
- line.sub! /,\s*['"].+['"]\s*,\s*/, "#{full_version}, "
28
- elsif line =~ /,\s*['"].+['"]/
29
- line[/,\s*['"].+['"]/] = full_version
33
+ code, *comments = line.split(/#/)
34
+ parts = code.split(',')
35
+ if parts.size == 1
36
+ parts[0].chomp!
37
+ parts << " #{full_version}" unless full_version.empty?
38
+ else
39
+ # ignore the first part, which is the gem name
40
+ parts_without_gem = parts.drop(1)
41
+ # reject options hash
42
+ version_parts = parts_without_gem.reject { |x| x.include?(':') }
43
+ # remove all but the first version part from the original parts array
44
+ version_parts.drop(1).each { |version_part| parts.delete(version_part) }
45
+ # find the index of it
46
+ if index = parts.index(version_parts.first)
47
+ # replace the current gem version (inside quotes)
48
+ parts[index].sub! /['"].+['"]/, full_version
49
+ # remove white spaces from this item if we're removing the version
50
+ parts[index].strip! if full_version.empty?
30
51
  else
31
- line[/,\s*/] = "#{full_version}, "
32
- line[/\n/] = "#{comment}\n"
52
+ parts.insert 1, " #{full_version}"
33
53
  end
34
- elsif line.end_with?("\n")
35
- line.sub!("\n", "#{full_version}#{comment}\n")
36
- else
37
- line << full_version << comment << "\n"
54
+ parts.reject!(&:empty?)
38
55
  end
56
+ line.replace parts.join(',')
57
+ line << "#" << comments.join if comments.any?
58
+ line << "\n" unless line.end_with?("\n")
39
59
  line
40
60
  end
41
61
 
42
62
  # @note not used
63
+ # @deprecated
43
64
  def version
44
65
  line[/, (.+)\n?/, 1]
45
66
  end
data/lib/drg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DRG
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.2.3'.freeze
3
3
  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: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Buckley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler