Class: Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/testing/systemctl.rb

Direct Known Subclasses

Service

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, spec) ⇒ Unit

Returns a new instance of Unit.



72
73
74
75
# File 'lib/tomo/testing/systemctl.rb', line 72

def initialize(name, spec)
  @name = name
  @spec = spec
end

Class Method Details

.find(name) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/tomo/testing/systemctl.rb', line 64

def self.find(name)
  path = File.join(File.expand_path("~/.config/systemd/user/"), name)
  raise "Unknown unit: #{name}" unless File.file?(path)
  return Service.new(name, File.read(path)) if name.end_with?(".service")

  new(name, File.read(path))
end

Instance Method Details

#enableObject



77
78
79
# File 'lib/tomo/testing/systemctl.rb', line 77

def enable
  with_persistent_state { |state| state[:enabled] = true }
end

#restartObject



94
95
96
# File 'lib/tomo/testing/systemctl.rb', line 94

def restart
  must_be_enabled!
end

#startObject



86
87
88
# File 'lib/tomo/testing/systemctl.rb', line 86

def start
  must_be_enabled!
end

#statusObject



81
82
83
84
# File 'lib/tomo/testing/systemctl.rb', line 81

def status
  puts "#{name}"
  puts "   Loaded: loaded (enabled; vendor preset: enabled)" if enabled?
end

#stopObject



90
91
92
# File 'lib/tomo/testing/systemctl.rb', line 90

def stop
  must_be_enabled!
end