Class: Bundler::Dsl

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle, environment) ⇒ Dsl

Returns a new instance of Dsl.



13
14
15
16
17
18
19
# File 'lib/bundler08/dsl.rb', line 13

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

Class Method Details

.evaluate(file, bundle, environment) ⇒ Object



7
8
9
10
11
# File 'lib/bundler08/dsl.rb', line 7

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

Instance Method Details

#bin_path(path) ⇒ Object



25
26
27
# File 'lib/bundler08/dsl.rb', line 25

def bin_path(path)
  @bundle.bindir = Pathname.new(path)
end

#bundle_path(path) ⇒ Object



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

def bundle_path(path)
  @bundle.path = Pathname.new(path)
end

#clear_sourcesObject



76
77
78
# File 'lib/bundler08/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/bundler08/dsl.rb', line 56

def directory(path, options = {})
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
  @directory = DirectorySource.new(@bundle, 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/bundler08/dsl.rb', line 29

def disable_rubygems
  @environment.rubygems = false
end

#disable_system_gemsObject



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

def disable_system_gems
  @environment.system_gems = false
end

#except(*env) ⇒ Object



50
51
52
53
54
# File 'lib/bundler08/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
104
105
106
107
108
# File 'lib/bundler08/dsl.rb', line 80

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

  keys = :vendored_at, :path, :only, :except, :git, :path, :bundle, :require_as, :tag, :branch, :ref
  unless (invalid = options.keys - keys).empty?
    raise InvalidKey, "Only #{keys.join(", ")} are valid options to #gem. You used #{invalid.join(", ")}"
  end

  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.new(@bundle)
  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/bundler08/dsl.rb', line 66

def git(uri, options = {})
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
  @git = GitSource.new(@bundle, 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/bundler08/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/bundler08/dsl.rb', line 37

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