Sha256: ae4cda07e338d0516173d5219568d067205a053677f92ce09e140f9031537009

Contents?: true

Size: 923 Bytes

Versions: 2

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

module Pbmenv
  class UseVersionService
    class VersionNotFoundError < StandardError; end

    attr_accessor :version

    def initialize(version: )
      self.version = version
    end

    def execute!
      throw_error_if_has_not_version
      relink_current_path
    end

    private

    def throw_error_if_has_not_version
      version_pathname = VersionPathname.new(version)

      if !File.exist?(version_pathname.version_path_without_v) && !File.exist?(version_pathname.version_path)
        raise UseVersionService::VersionNotFoundError
      end
    end

    def relink_current_path
      version_pathname = VersionPathname.new(version)

      if File.symlink?(VersionPathname.current)
        Helper.system_and_puts "unlink #{VersionPathname.current}"
      end

      Helper.system_and_puts "ln -s #{version_pathname.version_path} #{VersionPathname.current}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pbmenv-0.1.13 lib/pbmenv/services/use_version_service.rb
pbmenv-0.1.12 lib/pbmenv/services/use_version_service.rb