class Serverkit::Resources::RbenvRuby

Constants

DEFAULT_GLOBAL
DEFAULT_RBENV_EXECUTABLE_PATH

Public Instance Methods

apply() click to toggle source

Install the specified version of Ruby with rbenv if rbenv is executable @note Override

# File lib/serverkit/resources/rbenv_ruby.rb, line 17
def apply
  if dependencies
    install_dependencies
  end
  if has_rbenv?
    install_specified_ruby_version unless has_specified_ruby_version?
    set_specified_global_version if has_invalid_global_version?
  end
end
check() click to toggle source

Check if rbenv is executable and the specified version of Ruby is installed @note Override @return [true, false] True if the specified version of Ruby is installed

# File lib/serverkit/resources/rbenv_ruby.rb, line 30
def check
  has_correct_dependencies? && has_rbenv? && has_specified_ruby_version? && !has_invalid_global_version?
end

Private Instance Methods

build_dependent_resources() click to toggle source

@return [Array<Serverkit::Resources::Base>]

# File lib/serverkit/resources/rbenv_ruby.rb, line 37
def build_dependent_resources
  [
    Serverkit::Resources::RbenvDependentPackages.new(@recipe, {}),
    Serverkit::Resources::RbenvRbenv.new(@recipe, "user" => user),
    Serverkit::Resources::RbenvRubyBuild.new(@recipe, "user" => user),
    Serverkit::Resources::RbenvProfile.new(@recipe, "user" => user, "profile_path" => profile_path),
  ].map do |resource|
    resource.backend = backend
    resource
  end
end
default_id() click to toggle source

@note Override

# File lib/serverkit/resources/rbenv_ruby.rb, line 50
def default_id
  version
end
get_user_home_directory() click to toggle source

@return [String]

# File lib/serverkit/resources/rbenv_ruby.rb, line 55
def get_user_home_directory
  run_command_from_identifier(:get_user_home_directory, user).stdout.rstrip
end
global_version() click to toggle source
# File lib/serverkit/resources/rbenv_ruby.rb, line 59
def global_version
  run_command("#{proper_rbenv_executable_path} global").stdout.rstrip
end
has_correct_dependencies?() click to toggle source
# File lib/serverkit/resources/rbenv_ruby.rb, line 63
def has_correct_dependencies?
  !dependencies || build_dependent_resources.all?(&:check)
end
has_invalid_global_version?() click to toggle source

@return [true, false] True if global attribute is specified and it differs from current global

# File lib/serverkit/resources/rbenv_ruby.rb, line 68
def has_invalid_global_version?
  !global.nil? && global_version != version
end
has_rbenv?() click to toggle source

@return [true, false] True if rbenv command is executable

# File lib/serverkit/resources/rbenv_ruby.rb, line 73
def has_rbenv?
  check_command("which #{proper_rbenv_executable_path}")
end
has_specified_ruby_version?() click to toggle source

@return [true, false] True if the specified version of Ruby is installed

# File lib/serverkit/resources/rbenv_ruby.rb, line 78
def has_specified_ruby_version?
  check_command("#{proper_rbenv_executable_path} prefix #{version}")
end
install_dependencies() click to toggle source
# File lib/serverkit/resources/rbenv_ruby.rb, line 82
def install_dependencies
  build_dependent_resources.each(&:run_apply)
end
install_specified_ruby_version() click to toggle source
# File lib/serverkit/resources/rbenv_ruby.rb, line 86
def install_specified_ruby_version
  run_command("#{proper_rbenv_executable_path} install #{version}")
end
proper_rbenv_executable_path() click to toggle source

@return [String]

# File lib/serverkit/resources/rbenv_ruby.rb, line 91
def proper_rbenv_executable_path
  case
  when rbenv_executable_path
    rbenv_executable_path
  when user
    "#{get_user_home_directory}/.rbenv/bin/rbenv"
  else
    DEFAULT_RBENV_EXECUTABLE_PATH
  end
end
set_specified_global_version() click to toggle source
# File lib/serverkit/resources/rbenv_ruby.rb, line 102
def set_specified_global_version
  run_command("#{proper_rbenv_executable_path} global #{version}")
end