spitball 0.3.1 → 0.3.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/lib/spitball.rb CHANGED
@@ -4,6 +4,7 @@ require 'ext/bundler_lockfile_parser'
4
4
  require 'ext/bundler_fake_dsl'
5
5
 
6
6
  class Spitball
7
+ require 'spitball/client_common'
7
8
  require 'spitball/digest'
8
9
  require 'spitball/repo'
9
10
  require 'spitball/file_lock'
@@ -16,6 +17,7 @@ class Spitball
16
17
  VERSION = '1.0'
17
18
 
18
19
  include Spitball::Digest
20
+ include Spitball::ClientCommon
19
21
 
20
22
  attr_reader :gemfile, :gemfile_lock, :without, :options
21
23
 
@@ -26,11 +28,6 @@ class Spitball
26
28
  @without = (options[:without] || []).map{|w| w.to_sym}
27
29
  end
28
30
 
29
- def copy_to(dest)
30
- cache!
31
- FileUtils.cp(tarball_path, dest)
32
- end
33
-
34
31
  def cached?
35
32
  File.exist? tarball_path
36
33
  end
@@ -51,6 +48,13 @@ class Spitball
51
48
  end
52
49
  end
53
50
 
51
+ private
52
+
53
+ def copy_tarball_data(dest)
54
+ cache!
55
+ FileUtils.cp(tarball_path, dest)
56
+ end
57
+
54
58
  def create_bundle
55
59
  ENV['BUNDLE_GEMFILE'] = gemfile_path # make bundler happy! :) *cry*
56
60
  Spitball::Repo.make_cache_dirs
@@ -0,0 +1,30 @@
1
+ module Spitball::ClientCommon
2
+ def copy_to(path)
3
+ case path
4
+ when /\.tar\.gz$/, /\.tgz$/
5
+ copy_tarball_data(path)
6
+ else
7
+ tmp_tgz = File.join(path, 'spitball.tgz')
8
+ FileUtils.mkdir_p path
9
+
10
+ copy_tarball_data(tmp_tgz)
11
+ `tar xzf #{tmp_tgz} -C #{path}`
12
+
13
+ FileUtils.rm_rf(tmp_tgz)
14
+ end
15
+ end
16
+
17
+ def cached?
18
+ raise NotImplementedError
19
+ end
20
+
21
+ def cache!
22
+ raise NotImplementedError
23
+ end
24
+
25
+ private
26
+
27
+ def copy_tarball_data(path)
28
+ raise NotImplementedError
29
+ end
30
+ end
@@ -3,6 +3,8 @@ require 'uri'
3
3
 
4
4
  class Spitball::Remote
5
5
 
6
+ include Spitball::ClientCommon
7
+
6
8
  def initialize(gemfile, gemfile_lock, opts = {})
7
9
  @gemfile = gemfile
8
10
  @gemfile_lock = gemfile_lock
@@ -10,25 +12,13 @@ class Spitball::Remote
10
12
  @port = opts[:port]
11
13
  end
12
14
 
13
- def copy_to(path)
14
- case path
15
- when /\.tar\.gz$/, /\.tgz$/
16
- data = generate_remote_tarball
17
- File.open(path, 'w') { |f| f.write data }
18
- else
19
- begin
20
- File.open('tmp.tgz', 'w') { |f| f.write data }
21
- FileUtils.mkdir_p path
22
- `tar xvf tmp.tgz -C #{path}`
23
- ensure
24
- FileUtils.rm_rf('tmp.tgz')
25
- end
26
- end
15
+ def cached?
16
+ !!@tarball_url
27
17
  end
28
18
 
29
- private
19
+ def cache!(sync = true) # ignore sync
20
+ return if cached?
30
21
 
31
- def generate_remote_tarball
32
22
  url = URI.parse("http://#{@host}:#{@port}/create")
33
23
  req = Net::HTTP::Post.new(url.path)
34
24
  req.form_data = {'gemfile' => @gemfile, 'gemfile_lock' => @gemfile_lock}
@@ -37,21 +27,25 @@ class Spitball::Remote
37
27
  http.request(req) {|r| puts r.read_body }
38
28
  end
39
29
 
40
- print "\nDownloading tarball..."; $stdout.flush
30
+ case res.code
31
+ when '201', '202' # Created, Accepted
32
+ @tarball_url = res['Location']
33
+ else
34
+ raise Spitball::ServerFailure, "Expected 2xx response code. Got #{res.code}."
35
+ end
36
+ rescue URI::InvalidURIError => e
37
+ raise Spitball::ClientError, e.message
38
+ end
41
39
 
42
- data =
43
- case res.code
44
- when '201', '202' # Created, Accepted
45
- get_tarball_data res['Location']
46
- else
47
- raise Spitball::ServerFailure, "Expected 2xx response code. Got #{res.code}."
48
- end
40
+ private
49
41
 
42
+ def copy_tarball_data(path)
43
+ cache!
44
+ print "\nDownloading tarball..."; $stdout.flush
45
+ data = get_tarball_data @tarball_url
50
46
  puts "done."
51
47
 
52
- data
53
- rescue URI::InvalidURIError => e
54
- raise Spitball::ClientError, e.message
48
+ File.open(path, 'w') { |f| f.write data }
55
49
  end
56
50
 
57
51
  def get_tarball_data(location)
@@ -62,5 +56,7 @@ class Spitball::Remote
62
56
  else
63
57
  raise Spitball::ServerFailure, "Spitball download failed."
64
58
  end
59
+ rescue URI::InvalidURIError => e
60
+ raise Spitball::ClientError, e.message
65
61
  end
66
62
  end
@@ -83,8 +83,8 @@ describe Spitball do
83
83
  describe "create_bundle" do
84
84
  it "generates a bundle at the bundle_path" do
85
85
  mock(@spitball).install_gem(anything, anything).times(any_times)
86
- capture_stdout { @spitball.create_bundle }
87
- File.exist?(@spitball.tarball_path).should == true
86
+ capture_stdout { @spitball.send :create_bundle }
87
+ File.exist?(@spitball.send(:tarball_path)).should == true
88
88
  end
89
89
  end
90
90
 
@@ -128,10 +128,10 @@ describe Spitball do
128
128
  it "should use without" do
129
129
  @spitball = Spitball.new(@gemfile, @lockfile)
130
130
  mock(@spitball).install_gem(anything, anything).times(7)
131
- @spitball.create_bundle
131
+ @spitball.send :create_bundle
132
132
  @spitball = Spitball.new(@gemfile, @lockfile, :without => 'development')
133
133
  mock(@spitball).install_gem(anything, anything).times(6)
134
- @spitball.create_bundle
134
+ @spitball.send :create_bundle
135
135
  end
136
136
  end
137
137
  end
data/spitball.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{spitball}
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Freels", "Brandon Mitchell", "Joshua Hull"]
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/ext/bundler_fake_dsl.rb",
28
28
  "lib/ext/bundler_lockfile_parser.rb",
29
29
  "lib/spitball.rb",
30
+ "lib/spitball/client_common.rb",
30
31
  "lib/spitball/digest.rb",
31
32
  "lib/spitball/file_lock.rb",
32
33
  "lib/spitball/remote.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spitball
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Freels
@@ -84,6 +84,7 @@ files:
84
84
  - lib/ext/bundler_fake_dsl.rb
85
85
  - lib/ext/bundler_lockfile_parser.rb
86
86
  - lib/spitball.rb
87
+ - lib/spitball/client_common.rb
87
88
  - lib/spitball/digest.rb
88
89
  - lib/spitball/file_lock.rb
89
90
  - lib/spitball/remote.rb