lockfile_preserver 1.0.2 → 1.0.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: ddb4c0329e70fd936e7eb4fa7957cc3f33e06780
4
- data.tar.gz: ed55e9704d554d5aa2e9d74cdbfc8a9f8670f35b
3
+ metadata.gz: e7cd849b404a20fa5b1040277e98a07c354ae5ff
4
+ data.tar.gz: acf5f053116123e815ad200ecdc9417a60f87e78
5
5
  SHA512:
6
- metadata.gz: bb27c3f6afb95d6ca3c866accbe5c7d61359e0c70d89dd679005f5b1270ffbccb2c98bc20afbc6e6421437ca0c1a3ee8bc0af3bb87504fdc543b50942f72e39b
7
- data.tar.gz: c64ed4c48a2a0ed6c1e8da3eb52c1d16b77bc224a2e8f53c4d95245f306cd5561dbca39282fe66c47cf0d107df46259ce0ca009358b4120b1b83800a25fcfc82
6
+ metadata.gz: c068d2018a97a01a8f102e60081d90e07c136bc108fb2fe56db0b6c43eafe16b837cec3faafef44b69a20622b73f6658df21c50510bb2a3d78422a6d54128590
7
+ data.tar.gz: dab6b1930fae53c1850a69f0e64e497846766f20ca506b41da675283f67d8c62d9cab353fe07d7b70b34507ca926d98953ace11667df87e4fa371790f00ae783
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 1.0.3 - 2017.04.24
6
+
7
+ - Preserve Platform section in Gemfile.lock [#4](https://github.com/jollygoodcode/lockfile_preserver/pull/4)
8
+
5
9
  ## 1.0.2 - 2016.06.14
6
10
 
7
11
  - Fix `LockfilePreserver::RubyVersion` does not add `RUBY VERSION` section back to lockfile bug [#3](https://github.com/jollygoodcode/lockfile_preserver/pull/3)
@@ -2,6 +2,7 @@ require "lockfile_preserver/version"
2
2
  require "lockfile_preserver/pipeline"
3
3
  require "lockfile_preserver/bundled_with"
4
4
  require "lockfile_preserver/ruby_version"
5
+ require "lockfile_preserver/platforms"
5
6
 
6
7
  module LockfilePreserver
7
8
  def self.keep(original, updated, section = :bundled_with)
@@ -9,6 +10,8 @@ module LockfilePreserver
9
10
  LockfilePreserver::BundledWith.new(original, updated).keep
10
11
  elsif section == :ruby_version
11
12
  LockfilePreserver::RubyVersion.new(original, updated).keep
13
+ elsif section == :platforms
14
+ LockfilePreserver::Platforms.new(original, updated).keep
12
15
  elsif
13
16
  abort %(We currently only support preserve "BUNDLED WITH" & "RUBY VERSION" section of lockfile.)
14
17
  end
@@ -17,7 +20,8 @@ module LockfilePreserver
17
20
  def self.keep_all(original, updated)
18
21
  pipeline = Pipeline.new [
19
22
  LockfilePreserver::BundledWith,
20
- LockfilePreserver::RubyVersion
23
+ LockfilePreserver::RubyVersion,
24
+ LockfilePreserver::Platforms,
21
25
  ]
22
26
 
23
27
  pipeline.call(original, updated)
@@ -0,0 +1,74 @@
1
+ module LockfilePreserver
2
+ class Platforms
3
+ def initialize(original, updated)
4
+ @original = original
5
+ @updated = updated
6
+ end
7
+
8
+ def keep
9
+ if original.include? PLATFORMS
10
+ keep_platforms
11
+ else
12
+ remove_platforms
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :original, :updated
19
+
20
+ PLATFORMS = "PLATFORMS".freeze
21
+ RUBY_PATTERN = %r{.+}
22
+ REGEXP = %r{\n\nPLATFORMS\n\s+(?<ruby>#{RUBY_PATTERN})\n*}
23
+ NEW_LINE = "\n".freeze
24
+
25
+ private_constant :PLATFORMS
26
+ private_constant :RUBY_PATTERN
27
+ private_constant :REGEXP
28
+ private_constant :NEW_LINE
29
+
30
+ def keep_platforms
31
+ if updated.include? PLATFORMS
32
+ retains_platforms
33
+ else
34
+ add_platforms
35
+ end
36
+ end
37
+
38
+ def retains_platforms
39
+ updated.sub(REGEXP, platforms_section)
40
+ end
41
+
42
+ def platforms_section
43
+ "\n\nPLATFORMS\n" \
44
+ " #{platform_ruby}\n\n"
45
+ end
46
+
47
+ # How PLATFORMS added to lockfile: https://git.io/vSda6
48
+ def add_platforms
49
+ updated_lines = updated.lines
50
+
51
+ # Find last line of GEM
52
+ last_section_of_gem_index = updated.lines.index { |line| line != "G" && line.chr == "\n" }
53
+
54
+ # PLATFORMS should be added after GEM section
55
+ add_platforms_index = last_section_of_gem_index + 1
56
+
57
+ # Add PLATFORMS section
58
+ updated_lines.insert(
59
+ add_platforms_index, "\nPLATFORMS\n", " #{platform_ruby}\n"
60
+ )
61
+
62
+ # Reconstruct lockfile
63
+ updated_lines.join
64
+ end
65
+
66
+ def remove_platforms
67
+ updated.sub(REGEXP, NEW_LINE)
68
+ end
69
+
70
+ def platform_ruby
71
+ @_platform_ruby ||= original.match(REGEXP)[:ruby]
72
+ end
73
+ end
74
+ end
@@ -1,3 +1,3 @@
1
1
  module LockfilePreserver
2
- VERSION = "1.0.2".freeze
2
+ VERSION = "1.0.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockfile_preserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JuanitoFatas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2017-04-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: LockfilePreserver preserves section you don't want to update.
14
14
  email:
@@ -31,6 +31,7 @@ files:
31
31
  - lib/lockfile_preserver.rb
32
32
  - lib/lockfile_preserver/bundled_with.rb
33
33
  - lib/lockfile_preserver/pipeline.rb
34
+ - lib/lockfile_preserver/platforms.rb
34
35
  - lib/lockfile_preserver/ruby_version.rb
35
36
  - lib/lockfile_preserver/version.rb
36
37
  - lockfile_preserver.gemspec
@@ -54,9 +55,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  requirements: []
56
57
  rubyforge_project:
57
- rubygems_version: 2.4.5.1
58
+ rubygems_version: 2.6.11
58
59
  signing_key:
59
60
  specification_version: 4
60
61
  summary: LockfilePreserver preserves section you don't want to update.
61
62
  test_files: []
62
- has_rdoc: