Class: Plat4m::System::OS

Inherits:
Object
  • Object
show all
Defined in:
lib/plat4m/system.rb

Overview

Provides information about the operating system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, distro: nil, variant: nil, release: nil, pkgman: nil, **other) ⇒ OS

Returns a new instance of OS.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/plat4m/system.rb', line 38

def initialize(id: nil, distro: nil, variant: nil, release: nil, pkgman: nil, **other)
  @id = id
  @distro = distro
  @variant = variant
  @release = release
  @pkgman = pkgman
  @other = other
  @other.each_key do |key|
    unless self.respond_to?(key.to_sym)
      singleton_class.class_eval <<~__CODE
        define_method(:#{key}) do
          @other['#{key}']
        end
      __CODE
    end
  end
end

Instance Attribute Details

#distroObject (readonly) Also known as: distribution

Returns the value of attribute distro.



56
57
58
# File 'lib/plat4m/system.rb', line 56

def distro
  @distro
end

#idObject (readonly)

Returns the value of attribute id.



56
57
58
# File 'lib/plat4m/system.rb', line 56

def id
  @id
end

#pkgmanObject (readonly)

Returns the value of attribute pkgman.



56
57
58
# File 'lib/plat4m/system.rb', line 56

def pkgman
  @pkgman
end

#releaseObject (readonly)

Returns the value of attribute release.



56
57
58
# File 'lib/plat4m/system.rb', line 56

def release
  @release
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
# File 'lib/plat4m/system.rb', line 64

def complete?
  ::Symbol === @id &&
    ::String === @distro && !@distro.empty?
    ::String === @release && !@release.empty?
end

#has_sudo?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/plat4m/system.rb', line 74

def has_sudo?
  @pkgman ? @pkgman.has_sudo? : false
end

#is_root?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/plat4m/system.rb', line 70

def is_root?
  @pkgman ? @pkgman.is_root? : false
end

#to_sObject



78
79
80
# File 'lib/plat4m/system.rb', line 78

def to_s
  "#{@distro}-#{@release}[#{@id}#{@variant ? " #{@variant}" : ''}]"
end

#variantObject



58
59
60
# File 'lib/plat4m/system.rb', line 58

def variant
  @variant || @distro
end