thief 0.0.3 → 0.0.4

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -7
  3. data/lib/thief/version.rb +1 -1
  4. data/lib/thief.rb +15 -34
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 837ee0a4bdf93a3bc8606dcf6624320c6a96220a
4
- data.tar.gz: c1471656f3c9c5be7de1e9e0bff6df7188a467af
3
+ metadata.gz: 3707be4b98fe35a4f8083306437c3eb0ee6cbd23
4
+ data.tar.gz: 8a3e6aba2464701d438157779f3b1b76e41af86d
5
5
  SHA512:
6
- metadata.gz: bdcf9ce7a05db0cbc67735bb8da572ec031df648c4c9915520f93bca5758dcb7164843030ec4690aba9f61ef379766ec3fd6e91132f3ad784515c044d0228b96
7
- data.tar.gz: b47b6ffe319d9598011c6193c916291ccaf6ef444198031c0135c3f0d8733bc3ad8b554897b35dfd06335c3eabc324746f36315b7948cda18f5ec412f060633b
6
+ metadata.gz: 984186af46edb2bf4261b36ec1b72349296bd415594d6f5119c16573c4ad4dbea26d955d8308966166476f1be1b13d994b31c3dbc33af048da66345f328ca849
7
+ data.tar.gz: 7e0dc4816bdecc1262effacc514a8b66cb8f0e55a424a9cba393a83888763adf2c7c717e06d6a6b56b74cccb1bf23d279dc153ab0ee2d6efd93784da5851c4e6
data/README.md CHANGED
@@ -3,23 +3,20 @@
3
3
  Thief is a hack and slash alternative for installing Gemfile contents as fast as possible. It
4
4
  operates in following way:
5
5
 
6
- 1. Parses the `Gemfile`, ignoring `Gemfile.lock`, of course.
7
- 2. Runs `gem install` for each gem using as many parallel processes as you have CPUs.
8
-
9
- It leaves a mess, but does the majority of work that Bundler is notoriously slow at. Run Bundler
10
- afterwards to have a clean finish.
6
+ 1. Runs `bundle check` which usually returns list of missing gems with versions quickly.
7
+ 2. Runs optimized `gem install` for each gem using as many parallel processes as you have CPUs.
11
8
 
12
9
  ## Installation
13
10
 
14
11
  Install using the command line:
15
12
 
16
- $ gem install thief
13
+ $ gem install thief
17
14
 
18
15
  ## Usage
19
16
 
20
17
  Recommended usage for CI builds or production installs is in combination with [Bundler](http://bundler.io/):
21
18
 
22
- $ bundle check || thief; bundle install
19
+ $ thief; bundle check || bundle install
23
20
 
24
21
  Execute somewhere where Gemfile is present
25
22
 
data/lib/thief/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Thief
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/thief.rb CHANGED
@@ -7,8 +7,13 @@ module Thief
7
7
  def install
8
8
  gemfile = resolve_gemfile
9
9
  gems = parse_gemfile(gemfile)
10
- Parallel.map(gems, in_processes: cpu_count, progress: 'Getting gems') do |gem|
11
- install_gem(gem)
10
+ if gems.size > 0
11
+ puts "Getting #{gems.size} missing gems"
12
+ Parallel.map(gems, in_processes: cpu_count, progress: 'Getting missing gems') do |gem|
13
+ install_gem(gem)
14
+ end
15
+ else
16
+ puts 'You have all the gems you need'
12
17
  end
13
18
  end
14
19
 
@@ -22,39 +27,16 @@ module Thief
22
27
  end
23
28
 
24
29
  def parse_gemfile(gemfile)
30
+ missing = `bundle check --gemfile=#{gemfile}`
31
+ gems = missing.split("\n").map(&:strip).select { |l| l.start_with?('*') }
25
32
  result = []
26
- line_num = 0
27
- File.open(gemfile).each do |line|
28
- line_num += 1
29
- parse_line(result, line, line_num)
33
+ gems.map do |gem|
34
+ gem, version = gem.gsub('* ', '').split(' (')
35
+ result << { gem: gem, version: version.gsub(')', '') }
30
36
  end
31
37
  result
32
38
  end
33
39
 
34
- def parse_line(result, line, num)
35
- line = line.strip
36
- if line.include?(':path =>') || line.include?('path: ')
37
- puts "WARNING: Skipping local: #{line}"
38
- return
39
- end
40
- if line.include?('#')
41
- line, _ = line.split('#')
42
- end
43
- if line.start_with?('gem')
44
- gem, version = line.gsub(/['"]/, '').split(',')
45
- gem_def = { gem: gem.gsub(/^gem\s+/, '').strip }
46
- if version && version.include?('require')
47
- version.gsub!(/:?require.+/, '').strip
48
- end
49
- if version && version.strip.length > 0
50
- gem_def[:version] = version.strip
51
- end
52
- result << gem_def
53
- end
54
- rescue => e
55
- puts "WARNING: Could not parse line: #{num}: #{line}: #{e}"
56
- end
57
-
58
40
  def resolve_gemfile
59
41
  gemfile_path = ARGV[0] || 'Gemfile'
60
42
  if gemfile_path.start_with?('~') || gemfile_path.start_with?('/')
@@ -68,10 +50,9 @@ module Thief
68
50
  end
69
51
 
70
52
  def check_gemfile(gemfile)
71
- unless File.exist?(gemfile)
72
- puts 'Run thief in a directory that contains a Gemfile'
73
- exit 1
74
- end
53
+ return if File.exist?(gemfile)
54
+ puts 'Run thief in a directory that contains a Gemfile'
55
+ exit 1
75
56
  end
76
57
 
77
58
  def cpu_count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thief
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Varaneckas