Class: Appraisal::BundlerDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/appraisal/bundler_dsl.rb

Direct Known Subclasses

Conditional, Gemfile, Git, Group, Path, Platform, Source

Constant Summary collapse

PARTS =
%w(source ruby_version gits paths dependencies groups
platforms source_blocks install_if gemspec)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBundlerDSL

Returns a new instance of BundlerDSL.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/appraisal/bundler_dsl.rb', line 10

def initialize
  @sources = []
  @ruby_version = nil
  @dependencies = DependencyList.new
  @gemspecs = []
  @groups = Hash.new
  @platforms = Hash.new
  @gits = Hash.new
  @paths = Hash.new
  @source_blocks = Hash.new
  @git_sources = {}
  @install_if = {}
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



5
6
7
# File 'lib/appraisal/bundler_dsl.rb', line 5

def dependencies
  @dependencies
end

Instance Method Details

#for_dupObject



86
87
88
# File 'lib/appraisal/bundler_dsl.rb', line 86

def for_dup
  Utils.join_parts PARTS.map { |part| send("#{part}_entry_for_dup") }
end

#gem(name, *requirements) ⇒ Object



28
29
30
# File 'lib/appraisal/bundler_dsl.rb', line 28

def gem(name, *requirements)
  @dependencies.add(name, substitute_git_source(requirements))
end

#gemspec(options = {}) ⇒ Object



90
91
92
# File 'lib/appraisal/bundler_dsl.rb', line 90

def gemspec(options = {})
  @gemspecs << Gemspec.new(options)
end

#git(source, options = {}, &block) ⇒ Object



70
71
72
73
74
# File 'lib/appraisal/bundler_dsl.rb', line 70

def git(source, options = {}, &block)
  @gits[source] ||=
    Git.new(source, options).tap { |g| g.git_sources = @git_sources.dup }
  @gits[source].run(&block)
end

#git_source(source, &block) ⇒ Object



94
95
96
# File 'lib/appraisal/bundler_dsl.rb', line 94

def git_source(source, &block)
  @git_sources[source] = block
end

#group(*names, &block) ⇒ Object



36
37
38
39
40
# File 'lib/appraisal/bundler_dsl.rb', line 36

def group(*names, &block)
  @groups[names] ||=
    Group.new(names).tap { |g| g.git_sources = @git_sources.dup }
  @groups[names].run(&block)
end

#install_if(condition, &block) ⇒ Object



42
43
44
45
46
# File 'lib/appraisal/bundler_dsl.rb', line 42

def install_if(condition, &block)
  @install_if[condition] ||=
    Conditional.new(condition).tap { |g| g.git_sources = @git_sources.dup }
  @install_if[condition].run(&block)
end

#path(source, options = {}, &block) ⇒ Object



76
77
78
79
80
# File 'lib/appraisal/bundler_dsl.rb', line 76

def path(source, options = {}, &block)
  @paths[source] ||=
    Path.new(source, options).tap { |g| g.git_sources = @git_sources.dup }
  @paths[source].run(&block)
end

#platforms(*names, &block) ⇒ Object Also known as: platform



48
49
50
51
52
# File 'lib/appraisal/bundler_dsl.rb', line 48

def platforms(*names, &block)
  @platforms[names] ||=
    Platform.new(names).tap { |g| g.git_sources = @git_sources.dup }
  @platforms[names].run(&block)
end

#remove_gem(name) ⇒ Object



32
33
34
# File 'lib/appraisal/bundler_dsl.rb', line 32

def remove_gem(name)
  @dependencies.remove(name)
end

#ruby(ruby_version) ⇒ Object



66
67
68
# File 'lib/appraisal/bundler_dsl.rb', line 66

def ruby(ruby_version)
  @ruby_version = ruby_version
end

#run(&block) ⇒ Object



24
25
26
# File 'lib/appraisal/bundler_dsl.rb', line 24

def run(&block)
  instance_exec(&block)
end

#source(source, &block) ⇒ Object



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

def source(source, &block)
  if block_given?
    @source_blocks[source] ||=
      Source.new(source).tap { |g| g.git_sources = @git_sources.dup }
    @source_blocks[source].run(&block)
  else
    @sources << source
  end
end

#to_sObject



82
83
84
# File 'lib/appraisal/bundler_dsl.rb', line 82

def to_s
  Utils.join_parts PARTS.map { |part| send("#{part}_entry") }
end