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.



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

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

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



7
8
9
# File 'lib/appraisal/bundler_dsl.rb', line 7

def dependencies
  @dependencies
end

Instance Method Details

#for_dupObject



88
89
90
# File 'lib/appraisal/bundler_dsl.rb', line 88

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

#gem(name, *requirements) ⇒ Object



30
31
32
# File 'lib/appraisal/bundler_dsl.rb', line 30

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

#gemspec(options = {}) ⇒ Object



92
93
94
# File 'lib/appraisal/bundler_dsl.rb', line 92

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

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



72
73
74
75
76
# File 'lib/appraisal/bundler_dsl.rb', line 72

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



96
97
98
# File 'lib/appraisal/bundler_dsl.rb', line 96

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

#group(*names, &block) ⇒ Object



38
39
40
41
42
# File 'lib/appraisal/bundler_dsl.rb', line 38

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



44
45
46
47
48
# File 'lib/appraisal/bundler_dsl.rb', line 44

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



78
79
80
81
82
# File 'lib/appraisal/bundler_dsl.rb', line 78

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



50
51
52
53
54
# File 'lib/appraisal/bundler_dsl.rb', line 50

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



34
35
36
# File 'lib/appraisal/bundler_dsl.rb', line 34

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

#ruby(ruby_version) ⇒ Object



68
69
70
# File 'lib/appraisal/bundler_dsl.rb', line 68

def ruby(ruby_version)
  @ruby_version = ruby_version
end

#run(&block) ⇒ Object



26
27
28
# File 'lib/appraisal/bundler_dsl.rb', line 26

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

#source(source, &block) ⇒ Object



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

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



84
85
86
# File 'lib/appraisal/bundler_dsl.rb', line 84

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