Class: Bundler::Source::Git

Inherits:
Path
  • Object
show all
Defined in:
lib/bundler/source.rb

Constant Summary

Constants inherited from Path

Path::DEFAULT_GLOB

Instance Attribute Summary collapse

Attributes inherited from Path

#version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Path

#cached!, #hash, #local_specs, #remote!

Constructor Details

#initialize(options) ⇒ Git

Returns a new instance of Git.



463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/bundler/source.rb', line 463

def initialize(options)
  super

  # stringify options that could be set as symbols
  %w(ref branch tag revision).each{|k| options[k] = options[k].to_s if options[k] }

  @uri        = options["uri"]
  @ref        = options["ref"] || options["branch"] || options["tag"] || 'master'
  @revision   = options["revision"]
  @submodules = options["submodules"]
  @update     = false
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



461
462
463
# File 'lib/bundler/source.rb', line 461

def options
  @options
end

#refObject (readonly)

Returns the value of attribute ref.



461
462
463
# File 'lib/bundler/source.rb', line 461

def ref
  @ref
end

#submodulesObject (readonly)

Returns the value of attribute submodules.



461
462
463
# File 'lib/bundler/source.rb', line 461

def submodules
  @submodules
end

#uriObject (readonly)

Returns the value of attribute uri.



461
462
463
# File 'lib/bundler/source.rb', line 461

def uri
  @uri
end

Class Method Details

.from_lock(options) ⇒ Object



476
477
478
# File 'lib/bundler/source.rb', line 476

def self.from_lock(options)
  new(options.merge("uri" => options.delete("remote")))
end

Instance Method Details

#eql?(o) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


491
492
493
494
495
496
497
498
# File 'lib/bundler/source.rb', line 491

def eql?(o)
  Git === o            &&
  uri == o.uri         &&
  ref == o.ref         &&
  name == o.name       &&
  version == o.version &&
  submodules == o.submodules
end

#install(spec) ⇒ Object



538
539
540
541
542
543
544
545
546
547
# File 'lib/bundler/source.rb', line 538

def install(spec)
  Bundler.ui.info "Using #{spec.name} (#{spec.version}) from #{to_s} "

  unless @installed
    Bundler.ui.debug "  * Checking out revision: #{ref}"
    checkout if allow_git_ops?
    @installed = true
  end
  generate_bin(spec)
end

#load_spec_filesObject



549
550
551
552
553
# File 'lib/bundler/source.rb', line 549

def load_spec_files
  super
rescue PathError, GitError
  raise GitError, "#{to_s} is not checked out. Please run `bundle install`"
end

#nameObject



507
508
509
# File 'lib/bundler/source.rb', line 507

def name
  File.basename(@uri, '.git')
end

#pathObject



511
512
513
514
515
516
517
518
519
520
521
# File 'lib/bundler/source.rb', line 511

def path
  @install_path ||= begin
    git_scope = "#{base_name}-#{shortref_for_path(revision)}"

    if Bundler.requires_sudo?
      Bundler.user_bundle_path.join(Bundler.ruby_scope).join(git_scope)
    else
      Bundler.install_path.join(git_scope)
    end
  end
end

#specsObject

TODO: actually cache git specs



528
529
530
531
532
533
534
535
536
# File 'lib/bundler/source.rb', line 528

def specs
  if allow_git_ops? && !@update
    # Start by making sure the git cache is up to date
    cache
    checkout
    @update = true
  end
  local_specs
end

#to_lockObject



480
481
482
483
484
485
486
487
488
489
# File 'lib/bundler/source.rb', line 480

def to_lock
  out = "GIT\n"
  out << "  remote: #{@uri}\n"
  out << "  revision: #{revision}\n"
  %w(ref branch tag submodules).each do |opt|
    out << "  #{opt}: #{options[opt]}\n" if options[opt]
  end
  out << "  glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
  out << "  specs:\n"
end

#to_sObject



502
503
504
505
# File 'lib/bundler/source.rb', line 502

def to_s
  sref = options["ref"] ? shortref_for_display(options["ref"]) : ref
  "#{uri} (at #{sref})"
end

#unlock!Object



523
524
525
# File 'lib/bundler/source.rb', line 523

def unlock!
  @revision = nil
end