Class: Appraisal::Appraisal

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

Overview

Represents one appraisal and its dependencies

Constant Summary collapse

DEFAULT_INSTALL_OPTIONS =
{ "jobs" => 1 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, source_gemfile) ⇒ Appraisal

Returns a new instance of Appraisal.



15
16
17
18
# File 'lib/appraisal/appraisal.rb', line 15

def initialize(name, source_gemfile)
  @name = name
  @gemfile = source_gemfile.dup
end

Instance Attribute Details

#gemfileObject (readonly)

Returns the value of attribute gemfile.



13
14
15
# File 'lib/appraisal/appraisal.rb', line 13

def gemfile
  @gemfile
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/appraisal/appraisal.rb', line 13

def name
  @name
end

Instance Method Details

#gem(*args) ⇒ Object



20
21
22
# File 'lib/appraisal/appraisal.rb', line 20

def gem(*args)
  gemfile.gem(*args)
end

#gemfile_pathObject



92
93
94
95
96
97
98
# File 'lib/appraisal/appraisal.rb', line 92

def gemfile_path
  unless gemfile_root.exist?
    gemfile_root.mkdir
  end

  gemfile_root.join(gemfile_name).to_s
end

#gemspec(options = {}) ⇒ Object



56
57
58
# File 'lib/appraisal/appraisal.rb', line 56

def gemspec(options = {})
  gemfile.gemspec(options)
end

#git(*args, &block) ⇒ Object



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

def git(*args, &block)
  gemfile.git(*args, &block)
end

#git_source(*args, &block) ⇒ Object



60
61
62
# File 'lib/appraisal/appraisal.rb', line 60

def git_source(*args, &block)
  gemfile.git_source(*args, &block)
end

#group(*args, &block) ⇒ Object



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

def group(*args, &block)
  gemfile.group(*args, &block)
end

#install(options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/appraisal/appraisal.rb', line 71

def install(options = {})
  commands = [install_command(options).join(" ")]

  if options["without"].nil? || options["without"].empty?
    commands.unshift(check_command.join(" "))
  end

  command = commands.join(" || ")

  if Bundler.settings[:path]
    env = { 'BUNDLE_DISABLE_SHARED_GEMS' => '1' }
    Command.new(command, :env => env).run
  else
    Command.new(command).run
  end
end

#install_if(*args, &block) ⇒ Object



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

def install_if(*args, &block)
  gemfile.install_if(*args, &block)
end

#path(*args, &block) ⇒ Object



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

def path(*args, &block)
  gemfile.path(*args, &block)
end

#platforms(*args, &block) ⇒ Object



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

def platforms(*args, &block)
  gemfile.platforms(*args, &block)
end

#relative_gemfile_pathObject



100
101
102
# File 'lib/appraisal/appraisal.rb', line 100

def relative_gemfile_path
  File.join("gemfiles", gemfile_name)
end

#relativizeObject



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/appraisal/appraisal.rb', line 104

def relativize
  current_directory = Pathname.new(Dir.pwd)
  relative_path = current_directory.relative_path_from(gemfile_root).cleanpath
  lockfile_content = File.read(lockfile_path)

  File.open(lockfile_path, 'w') do |file|
    file.write lockfile_content.gsub(
      / #{current_directory}/,
      " #{relative_path}",
    )
  end
end

#remove_gem(*args) ⇒ Object



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

def remove_gem(*args)
  gemfile.remove_gem(*args)
end

#ruby(*args) ⇒ Object



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

def ruby(*args)
  gemfile.ruby(*args)
end

#source(*args, &block) ⇒ Object



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

def source(*args, &block)
  gemfile.source(*args, &block)
end

#update(gems = []) ⇒ Object



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

def update(gems = [])
  Command.new(update_command(gems), :gemfile => gemfile_path).run
end

#write_gemfileObject



64
65
66
67
68
69
# File 'lib/appraisal/appraisal.rb', line 64

def write_gemfile
  File.open(gemfile_path, "w") do |file|
    signature = Customize.heading || "This file was generated by Appraisal"
    file.puts([comment_lines(signature), quoted_gemfile].join("\n\n"))
  end
end