Module: Gonzui::AptGet

Extended by:
Util
Defined in:
lib/gonzui/apt.rb

Constant Summary collapse

AptGetRegistry =
{}

Class Method Summary collapse

Methods included from Util

assert, assert_equal, assert_equal_all, assert_non_nil, assert_not_reached, benchmark, command_exist?, commify, eprintf, format_bytes, program_name, protect_from_signals, require_command, set_verbosity, shell_escape, unix?, vprintf, windows?, wprintf

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/gonzui/apt.rb', line 21

def available?
  begin
    require_command("apt-get")
    return true
  rescue CommandNotFoundError
    return false
  end
end

.get_apt_typeObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/gonzui/apt.rb', line 30

def get_apt_type
  require_command("apt-get")
  apt_type = :unknown
  IO.popen("apt-get --version").each {|line|
    if m = /^\*Ver: Standard \.(.*)$/.match(line)
      apt_type = m[1].intern
    end
  }
  return apt_type
end

.new(config, package_name) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/gonzui/apt.rb', line 41

def new(config, package_name)
  apt_type = get_apt_type
  if klass = AptGetRegistry[apt_type]
    return klass.new(config, package_name)
  else
    raise AptGetError.new("#{apt_type}: unsupported apt type")
  end
end

.register(klass) ⇒ Object



50
51
52
53
# File 'lib/gonzui/apt.rb', line 50

def register(klass)
  assert(!AptGetRegistry.include?(klass.apt_type))
  AptGetRegistry[klass.apt_type] = klass
end