Class: Bundler::Dsl

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Dsl

Returns a new instance of Dsl.



10
11
12
13
14
15
# File 'lib/bundler/dsl.rb', line 10

def initialize(environment)
  @environment = environment
  @directory_sources = []
  @git_sources = {}
  @only, @except, @directory, @git = nil, nil, nil, nil
end

Class Method Details

.evaluate(environment, file) ⇒ Object



5
6
7
8
# File 'lib/bundler/dsl.rb', line 5

def self.evaluate(environment, file)
  builder = new(environment)
  builder.instance_eval(File.read(file.to_s), file.to_s, 1)
end

Instance Method Details

#bin_path(path) ⇒ Object



23
24
25
26
27
# File 'lib/bundler/dsl.rb', line 23

def bin_path(path)
  path = Pathname.new(path)
  @environment.bindir = (path.relative? ?
    @environment.root.join(path) : path).expand_path
end

#bundle_path(path) ⇒ Object



17
18
19
20
21
# File 'lib/bundler/dsl.rb', line 17

def bundle_path(path)
  path = Pathname.new(path)
  @environment.gem_path = (path.relative? ?
    @environment.root.join(path) : path).expand_path
end

#clear_sourcesObject



76
77
78
# File 'lib/bundler/dsl.rb', line 76

def clear_sources
  @environment.clear_sources
end

#directory(path, options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/bundler/dsl.rb', line 56

def directory(path, options = {})
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
  @directory = DirectorySource.new(options.merge(:location => path))
  @directory_sources << @directory
  @environment.add_priority_source(@directory)
  retval = yield if block_given?
  @directory = nil
  retval
end

#disable_rubygemsObject



29
30
31
# File 'lib/bundler/dsl.rb', line 29

def disable_rubygems
  @environment.rubygems = false
end

#disable_system_gemsObject



33
34
35
# File 'lib/bundler/dsl.rb', line 33

def disable_system_gems
  @environment.system_gems = false
end

#except(*env) ⇒ Object



50
51
52
53
54
# File 'lib/bundler/dsl.rb', line 50

def except(*env)
  old, @except = @except, _combine_except(env)
  yield
  @except = old
end

#gem(name, *args) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bundler/dsl.rb', line 80

def gem(name, *args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  version = args.last

  if path = options.delete(:vendored_at)
    options[:path] = path
    warn "The :vendored_at option is deprecated. Use :path instead.\nFrom #{caller[0]}"
  end

  options[:only] = _combine_only(options[:only] || options["only"])
  options[:except] = _combine_except(options[:except] || options["except"])

  dep = Dependency.new(name, options.merge(:version => version))

  if options.key?(:bundle) && !options[:bundle]
    dep.source = SystemGemSource.instance
  elsif @git || options[:git]
    dep.source = _handle_git_option(name, version, options)
  elsif @directory || options[:path]
    dep.source = _handle_vendored_option(name, version, options)
  end

  @environment.dependencies << dep
end

#git(uri, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/bundler/dsl.rb', line 66

def git(uri, options = {})
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
  @git = GitSource.new(options.merge(:uri => uri))
  @git_sources[uri] = @git
  @environment.add_priority_source(@git)
  retval = yield if block_given?
  @git = nil
  retval
end

#only(*env) ⇒ Object



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

def only(*env)
  old, @only = @only, _combine_only(env)
  yield
  @only = old
end

#source(source) ⇒ Object



37
38
39
40
41
42
# File 'lib/bundler/dsl.rb', line 37

def source(source)
  source = GemSource.new(:uri => source)
  unless @environment.sources.include?(source)
    @environment.add_source(source)
  end
end