Class: Repository

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

Overview

Bundler gemfile support for local/remote workspaces/repositories for work in development teams.

Usage:

 # define paths to be searched for repositories:
 workspace '~/.projects ~/Development/{projects,work}'

 # define developer preferences for using local or remote repositories (uses ENV['user']):
 developer :sven, :prefer => :local

 # define repositories to be used for particular gems:
 adva_cms  = repository('adva-cms2', :git => '[email protected]:svenfuchs/adva-cms2.git', :ref => 'c2af0de')
 adva_shop = repository('adva-shop', :source => :local)

 # now use repositories to define gems:
 adva_cms.gem  'adva-core'
 adva_shop.gem 'adva-catalog'

 # The gem definition will now be proxied to Bundler with arguments according
 # to the setup defined earlier. E.g. as:

 gem 'adva-core', :path => 'Development/projects/adva-cms2'                           # for developer 'sven'
 gem 'adva-core', :git => '[email protected]:svenfuchs/adva-cms2.git', :ref => 'c2af0de' # for other developers
 gem 'adva-catalog', :path => 'Development/projects/adva-shop'                        # for all developers

One can also set an environment variable FORCE_REMOTE which will force remote
repositories to be used *except* when a repository was defined with :source => :local
which always forces the local repository to be used.

Defined Under Namespace

Classes: Gem

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundler, name, options) ⇒ Repository

Returns a new instance of Repository.



71
72
73
74
75
76
# File 'lib/bundler/repository.rb', line 71

def initialize(bundler, name, options)
  @bundler = bundler
  @name    = name
  @source  = options.delete(:source)
  @options = options
end

Instance Attribute Details

#bundlerObject (readonly)

Returns the value of attribute bundler.



69
70
71
# File 'lib/bundler/repository.rb', line 69

def bundler
  @bundler
end

#nameObject (readonly)

Returns the value of attribute name.



69
70
71
# File 'lib/bundler/repository.rb', line 69

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



69
70
71
# File 'lib/bundler/repository.rb', line 69

def options
  @options
end

#sourceObject (readonly)

Returns the value of attribute source.



69
70
71
# File 'lib/bundler/repository.rb', line 69

def source
  @source
end

Class Method Details

.current_developerObject



50
51
52
# File 'lib/bundler/repository.rb', line 50

def current_developer
  developers[ENV['USER'].to_sym] || {}
end

.developer(name, preferences) ⇒ Object



45
46
47
48
# File 'lib/bundler/repository.rb', line 45

def developer(name, preferences)
  developers[name] = preferences
  workspaces(preferences[:workspace])
end

.developers(developers = nil) ⇒ Object



54
55
56
# File 'lib/bundler/repository.rb', line 54

def developers(developers = nil)
  @developers ||= {}
end

.path(*paths) ⇒ Object



39
40
41
42
43
# File 'lib/bundler/repository.rb', line 39

def path(*paths)
  paths.join(' ').split(' ').each do |path|
    self.paths.concat(Pathname.glob(File.expand_path(path)))
  end
end

.pathsObject



35
36
37
# File 'lib/bundler/repository.rb', line 35

def paths
  @paths ||= []
end

Instance Method Details

#forced_sourceObject



90
91
92
# File 'lib/bundler/repository.rb', line 90

def forced_source
  :remote if ENV['FORCE_REMOTE']
end

#gem(name) ⇒ Object



78
79
80
# File 'lib/bundler/repository.rb', line 78

def gem(name)
  bundler.gem(*Gem.new(name, self))
end

#local?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/bundler/repository.rb', line 82

def local?
  source == :local # && path
end

#pathObject



98
99
100
101
102
103
# File 'lib/bundler/repository.rb', line 98

def path
  @path ||= begin
    path = self.class.paths.detect { |path| path.join(name).exist? }
    path ? path.join(name) : Pathname.new('.')
  end
end

#preferred_sourceObject



94
95
96
# File 'lib/bundler/repository.rb', line 94

def preferred_source
  self.class.current_developer[:prefer] || self.class.current_developer[name.to_sym]
end