Class: Spitball

Inherits:
Object
  • Object
show all
Includes:
ClientCommon, Digest
Defined in:
lib/spitball.rb,
lib/spitball/version.rb

Defined Under Namespace

Modules: ClientCommon, Digest, Repo Classes: BundleCreationFailure, ClientError, FileLock, Remote, ServerFailure

Constant Summary collapse

PROTOCOL_VERSION =
'1'
PROTOCOL_HEADER =
"X-Spitball-Protocol"
WITHOUT_HEADER =
"X-Spitball-Without"
VERSION =
'0.7.3'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClientCommon

#copy_to

Methods included from Digest

#digest, #hash

Constructor Details

#initialize(gemfile, gemfile_lock, options = {}) ⇒ Spitball

Returns a new instance of Spitball.



34
35
36
37
38
39
40
41
42
43
# File 'lib/spitball.rb', line 34

def initialize(gemfile, gemfile_lock, options = {})
  Spitball::Repo.make_cache_dirs
  @gemfile      = gemfile
  @gemfile_lock = gemfile_lock
  @options      = options
  @without      = options[:without].is_a?(Enumerable) ? options[:without].map(&:to_sym) : (options[:without] ? [options[:without].to_sym] : [])
  @parsed_lockfile, @dsl = Bundler::FakeLockfileParser.new(gemfile_lock), Bundler::FakeDsl.new(gemfile)
  raise "You need to run bundle install before you can use spitball" unless (@parsed_lockfile.dependencies.map{|d| d.name}.uniq.sort == @dsl.__gem_names.uniq.sort)
  @groups_to_install = @dsl.__groups.keys - @without
end

Instance Attribute Details

#gemfileObject (readonly)

Returns the value of attribute gemfile.



32
33
34
# File 'lib/spitball.rb', line 32

def gemfile
  @gemfile
end

#gemfile_lockObject (readonly)

Returns the value of attribute gemfile_lock.



32
33
34
# File 'lib/spitball.rb', line 32

def gemfile_lock
  @gemfile_lock
end

#optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'lib/spitball.rb', line 32

def options
  @options
end

#withoutObject (readonly)

Returns the value of attribute without.



32
33
34
# File 'lib/spitball.rb', line 32

def without
  @without
end

Class Method Details

.gem_cmdObject



21
22
23
# File 'lib/spitball.rb', line 21

def self.gem_cmd
  ENV['GEM_CMD'] || 'gem'
end

Instance Method Details

#cache!(sync = true) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/spitball.rb', line 49

def cache!(sync = true)
  return if cached?
  lock = Spitball::FileLock.new(bundle_path('lock'))
  if lock.acquire_lock
    begin
     create_bundle
    ensure
      lock.release_lock
    end
  elsif sync
    sleep 0.1 until cached?
  end
end

#cached?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/spitball.rb', line 45

def cached?
  File.exist? tarball_path
end