gemfile_lock_to_gemfile 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 81acead7290ddc24c76539b667915d207118b575
4
+ data.tar.gz: c716367b418100376a16a5dd3b15f6eedec74a66
5
+ SHA512:
6
+ metadata.gz: 9e974d0cab4ec7748e9320111582556556b3357e1b7465d7590c0cdb7f59624057976e4ca4ff4f5be365e364a472e07a0c06743e35755cddce56d4016f5cfe65
7
+ data.tar.gz: d24426b3486287d7c3ff10417d97a096a63d08c49e5582f638bd3744cd46f46f3183c05280a0c870fce0c4486b45fadb284e21c2c80f0ceb13a8c4bd14549db3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Hao Hong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Gemfile Lock To Gemfile
2
+
3
+ > A tool for reversing `Gemfile.lock` -> `Gemfile`
4
+
5
+ ## Why I have to develop this tool
6
+
7
+ One of my ruby project is using bundler to manage gem dependencies. But the `Gemfile` is very complicate. It requires external `Gemfile` by using ruby `eval`. Because I have lots of similar projects that will use same piece of gems. So I decide to abstract these gems into a standalone `Gemfile`. And let those projects’ `Gemfile` loads it.
8
+
9
+ The problem I met is when I building my docker image. I hope that image can pre-install all the ruby gems in that `Gemfile.lock`. Unluckily, `bundle install` require you must have the `Gemfile`. So I have to find out a way to revert `Gemfile.lock` to a usable `Gemfile`.
10
+
11
+ So here we are!
12
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ ($LOAD_PATH << File.expand_path("../lib", __FILE__)).uniq!
2
+
3
+ require 'gemfile_lock_to_gemfile'
4
+
5
+ namespace :readme do
6
+ task :generate do
7
+ content = <<END
8
+ # #{GemfileLockToGemfile::SPEC.name.split("_").map(&:capitalize).join(' ')}
9
+
10
+ > #{GemfileLockToGemfile::SPEC.summary}
11
+
12
+ #{GemfileLockToGemfile::SPEC.description}
13
+ END
14
+ File.write(File.expand_path('../README.md', __FILE__), content)
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ($LOAD_PATH << File.expand_path("../../lib", __FILE__)).uniq!
4
+ require 'gemfile_lock_to_gemfile'
5
+
6
+ options = { custom_sources: {} }
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: gemfile_lock_to_gemfile [options]"
9
+
10
+ opts.on("-fGemfile.lock", "--file=Gemfile.lock", "Provide Gemfile.lock") do |f|
11
+ options[:file] = f
12
+ end
13
+
14
+ opts.on("-sSOURCE", "--source=SOURCE", "Provide default source for Gemfile") do |s|
15
+ options[:source] = s
16
+ end
17
+
18
+ opts.on("-c", "--custom-source=GEM:SOURCE", "Provide a custom source for a specific gem") do |s|
19
+ parsed = s.match(/([^:]+):(.*)/)
20
+ if parsed[2]
21
+ options[:custom_sources][parsed[1]] = parsed[2]
22
+ else
23
+ $stderr.puts "[WARNING] #{s} is invalid."
24
+ end
25
+ end
26
+
27
+ opts.on("-h", "--help", "Prints this help") do
28
+ puts opts
29
+ exit
30
+ end
31
+ end.parse!
32
+
33
+ lock_content = File.read(ARGV[0])
34
+
35
+ puts GemfileLockToGemfile::Converter.convert(lock_content, options)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+ require 'rubygems'
3
+
4
+ module GemfileLockToGemfile
5
+ SPEC = Gem::Specification::load(File.expand_path("../../gemfile_lock_to_gemfile.gemspec", __FILE__))
6
+ VERSION = SPEC.version
7
+ end
8
+
9
+ require 'gemfile_lock_to_gemfile/converter'
@@ -0,0 +1,96 @@
1
+ require 'optparse'
2
+
3
+ module GemfileLockToGemfile
4
+ class Converter
5
+ class << self
6
+ def convert(content, opts={})
7
+ git_refs = {}
8
+ current_git_ref = nil
9
+ scope = nil
10
+ sources = []
11
+ gems = []
12
+
13
+ content.split("\n").each do |line|
14
+ if scope
15
+ if scope == 'GIT'
16
+ if match = line.match(/^ ([^ :]+): (.*)/)
17
+ current_git_ref[match[1]] = match[2]
18
+ elsif match = line.match(/^ ([^ ]+) (.*)/)
19
+ current_git_ref['name'] = match[1]
20
+ elsif line.strip.empty?
21
+ git_refs[current_git_ref['name']] = current_git_ref
22
+ current_git_ref = nil
23
+ scope = nil
24
+ else
25
+ # ignore
26
+ end
27
+ elsif scope == 'GEM'
28
+ if match = line.match(/^ remote: (.*)/)
29
+ sources << match[1]
30
+ elsif line.strip.empty?
31
+ scope = nil
32
+ else
33
+ end
34
+ elsif scope == 'PLATFORMS'
35
+ if line.strip.empty?
36
+ scope = nil
37
+ end
38
+ elsif scope == 'DEPENDENCIES'
39
+ if match = line.match(/^ ([^ !]+)(!?)(?: \((.*)\))?/)
40
+ gems << {
41
+ 'name' => match[1],
42
+ 'git' => match[2].nil?,
43
+ 'version' => match[3]
44
+ }
45
+ elsif line.strip.empty?
46
+ scope = nil
47
+ end
48
+ elsif scope == 'BUNDLED_WITH'
49
+ if line.strip.empty?
50
+ scope = nil
51
+ end
52
+ end
53
+ else
54
+ if line =~ /^GIT/
55
+ scope = 'GIT'
56
+ current_git_ref = {}
57
+ elsif line =~ /^GEM/
58
+ scope = 'GEM'
59
+ elsif line =~ /^DEPENDENCIES/
60
+ scope = 'DEPENDENCIES'
61
+ end
62
+ end
63
+ end
64
+
65
+ output = []
66
+
67
+ if opts[:source]
68
+ output << "source #{opts[:source].inspect}"
69
+ else
70
+ sources.each do |s|
71
+ output << "source #{s.inspect}"
72
+ end
73
+ end
74
+
75
+ output << ""
76
+
77
+ gems.each do |g|
78
+ line = nil
79
+
80
+ if ref = git_refs[g['name']]
81
+ line = "gem #{g['name'].inspect}, git: #{ref['remote'].inspect}"
82
+ line += ", ref: #{ref['ref'].inspect}" if ref['ref']
83
+ else
84
+ line = "gem #{g['name'].inspect}"
85
+ line += ", #{g['version'].inspect}" if g['version']
86
+ line += ", source: #{opts[:custom_sources][g['name']].inspect}" if opts[:custom_sources][g['name']]
87
+ end
88
+
89
+ output << line
90
+ end
91
+
92
+ return output.join("\n")
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ source 'https://rubygems.org'
3
+
4
+ gem 'rake'
5
+ gem 'json', '~> 1.4'
6
+ gem 'uuid', git: 'https://github.com/assaf/uuid.git'
@@ -0,0 +1,26 @@
1
+ GIT
2
+ remote: https://github.com/assaf/uuid.git
3
+ revision: 81e5e1ef4e9d968aba6ae62f64a5e14ed7f42ce4
4
+ specs:
5
+ uuid (2.3.7)
6
+ macaddr (~> 1.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ json (1.8.3)
12
+ macaddr (1.7.1)
13
+ systemu (~> 2.6.2)
14
+ rake (12.0.0)
15
+ systemu (2.6.5)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ json (~> 1.4)
22
+ rake
23
+ uuid!
24
+
25
+ BUNDLED WITH
26
+ 1.12.5
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemfile_lock_to_gemfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - agate
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ ## Why I have to develop this tool
15
+
16
+ One of my ruby project is using bundler to manage gem dependencies. But the `Gemfile` is very complicate. It requires external `Gemfile` by using ruby `eval`. Because I have lots of similar projects that will use same piece of gems. So I decide to abstract these gems into a standalone `Gemfile`. And let those projects’ `Gemfile` loads it.
17
+
18
+ The problem I met is when I building my docker image. I hope that image can pre-install all the ruby gems in that `Gemfile.lock`. Unluckily, `bundle install` require you must have the `Gemfile`. So I have to find out a way to revert `Gemfile.lock` to a usable `Gemfile`.
19
+
20
+ So here we are!
21
+ email: agate.hao@gmail.com
22
+ executables:
23
+ - gemfile_lock_to_gemfile
24
+ extensions: []
25
+ extra_rdoc_files: []
26
+ files:
27
+ - LICENSE
28
+ - README.md
29
+ - Rakefile
30
+ - bin/gemfile_lock_to_gemfile
31
+ - lib/gemfile_lock_to_gemfile.rb
32
+ - lib/gemfile_lock_to_gemfile/converter.rb
33
+ - test/resources/Gemfile
34
+ - test/resources/Gemfile.lock
35
+ homepage: https://github.com/agate/gemfile_lock_to_gemfile
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.5.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A tool for reversing `Gemfile.lock` -> `Gemfile`
58
+ test_files: []