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"
BUNDLE_CONFIG_ENV =
'BUNDLE_CONFIG'
VERSION =
'0.8.2'

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.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spitball.rb', line 36

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)

  use_bundle_config(options[:bundle_config]) if options[:bundle_config]

  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.



34
35
36
# File 'lib/spitball.rb', line 34

def gemfile
  @gemfile
end

#gemfile_lockObject (readonly)

Returns the value of attribute gemfile_lock.



34
35
36
# File 'lib/spitball.rb', line 34

def gemfile_lock
  @gemfile_lock
end

#optionsObject (readonly)

Returns the value of attribute options.



34
35
36
# File 'lib/spitball.rb', line 34

def options
  @options
end

#withoutObject (readonly)

Returns the value of attribute without.



34
35
36
# File 'lib/spitball.rb', line 34

def without
  @without
end

Class Method Details

.gem_cmdObject



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

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

Instance Method Details

#cache!(sync = true) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/spitball.rb', line 64

def cache!(sync = true)
  return if cached?
  lock = Spitball::FileLock.new(bundle_path('lock'))

  # We check cached again to avoid falling into a race condition
  if lock.acquire_lock && !cached?
    begin
      create_bundle
    ensure
      lock.release_lock
    end
  elsif sync
    sleep 0.5
    cache!
  end
end

#cached?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/spitball.rb', line 60

def cached?
  File.exist? tarball_path
end

#use_bundle_config(bundle_config) ⇒ Object



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

def use_bundle_config(bundle_config)
  tempfile = Tempfile.new('bundle_config')
  File.open(tempfile.path, 'w') { |f| f.write options[:bundle_config] }
  original_config_path = ENV[BUNDLE_CONFIG_ENV]
  ENV[BUNDLE_CONFIG_ENV] = tempfile.path
  @bundle_config = Bundler::Settings.new
  tempfile.close
  ENV[BUNDLE_CONFIG_ENV] = original_config_path
end