Sha256: cb532c9ba8c00eadde39aff6f384989994edead4c798688c9e6585e1a880620a

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

module GemManager
  def self.installed?(gemname, version)
    gem_path = File.join(Conf.gem_dir, "gems", "#{gemname}-#{version}")
    exists = File.exist?(gem_path)
    Ramaze::Log.info "checking existance of #{gem_path}.. #{exists}"
    
    exists
  end

  def self.install_file(path)
    begin
      # make symlink
      newpath = "/tmp/#{File.basename(path, ".gem")}.gem"
      File.symlink(path, newpath)

      # install
      cmd = [
        Conf.gem_command, "install", newpath,
        "-i", Conf.gem_dir,
        "-n", Conf.gem_bin_dir,
        Conf.gem_install_option
      ].join(" ")
      Ramaze::Log.info cmd

      # execute
      result = `#{cmd}`

      # make data dir
      spec = YAML.load(`gem spec #{path}`)
      data_dir = File.join(Conf.data_dir, "#{spec.name}-#{spec.version}")
      unless File.directory?(data_dir)
        Dir.mkdir(data_dir)
        Ramaze::Log.info "made data dir for the gem: #{data_dir}"
      end

      [result, spec.name, spec.version.to_s]
    ensure
      File.unlink(newpath)
    end
  end

  def self.install_gem(name)
    # install
    cmd = [
      Conf.gem_command, "install", name,
      "-i", Conf.gem_dir,
      "-n", Conf.gem_bin_dir,
      Conf.gem_install_option
    ].join(" ")
    Ramaze::Log.info cmd
    
    # execute
    result = `#{cmd}`

    # make data dir
    raise unless result =~ /installed #{name}-(.*)/
    version = $1
    data_dir = File.join(Conf.data_dir, "#{name}-#{version}")
    unless File.directory?(data_dir)
      Dir.mkdir(data_dir)
      Ramaze::Log.info "made data dir for the gem: #{data_dir}"
    end

    [result, name, version]
  end

  def self.uninstall(name, version)
    cmd = [
      Conf.gem_command, "uninstall", name,
      "-v", version,
      "-i", Conf.gem_dir,
      "-n", Conf.gem_bin_dir
    ].join(" ")
    Ramaze::Log.info cmd

    `#{cmd}`
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby-station-0.0.4 util/gem-manager.rb