module CurrentGem

Constants

CURR_DIR
FileUtils
SPEC_DIR
VERSION

Public Instance Methods

[](arg)
Alias for: find
find(arg) click to toggle source
# File lib/current_gem.rb, line 45
def find(arg)
  case arg
    when Gem::Installer, Gem::Uninstaller then find_by_installer(arg)
    when Gem::Specification               then find_by_spec(arg)
    else                                       find_by_name(arg)
  end
end
Also aliased as: []
path_for(arg) click to toggle source
# File lib/current_gem.rb, line 55
def path_for(arg)
  spec = find(arg) if can_symlink?
  current_path_for(spec) if spec
end
update(installer) click to toggle source
# File lib/current_gem.rb, line 65
def update(installer)
  symlink(find(installer)) if can_symlink?
end
update_all(gem_dir = Gem.dir) click to toggle source
# File lib/current_gem.rb, line 69
def update_all(gem_dir = Gem.dir)
  return unless can_symlink?

  path = base_path_for(gem_dir)
  FileUtils.rm_r(path) if File.directory?(path)

  Gem::Specification.latest_specs.each { |spec| symlink(spec, path) }
end
version_for(arg) click to toggle source
# File lib/current_gem.rb, line 60
def version_for(arg)
  spec = find(arg)
  spec.version if spec
end

Private Instance Methods

base_path_for(arg) click to toggle source
# File lib/current_gem.rb, line 129
def base_path_for(arg)
  File.join(arg.is_a?(Gem::Specification) ? arg.base_dir : arg, CURR_DIR)
end
current_path_for(spec, path = base_path_for(spec)) click to toggle source
# File lib/current_gem.rb, line 133
def current_path_for(spec, path = base_path_for(spec))
  File.join(path, spec.name)
end
find_by_installer(installer) click to toggle source
# File lib/current_gem.rb, line 89
def find_by_installer(installer)
  spec, op = installer.spec, installer.is_a?(Gem::Installer) ? '>' : '!='

  curr = find_by_spec(spec, "#{op} #{spec.version}") || spec
  curr.loaded_from ||= File.join(installer.gem_home, SPEC_DIR, curr.spec_name)

  curr
end
find_by_name(name, req = nil) click to toggle source
# File lib/current_gem.rb, line 102
def find_by_name(name, req = nil)
  req ||= Gem::Requirement.default

  prereleases, releases = Gem::Specification.find_all_by_name(
    name.to_s, req).partition { |spec| spec.version.prerelease? }

  releases.last || prereleases.last
end
find_by_spec(spec, req = nil) click to toggle source
# File lib/current_gem.rb, line 98
def find_by_spec(spec, req = nil)
  find_by_name(spec.name, req)
end