Class: Boxen::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/boxen/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Service

Returns a new instance of Service.



20
21
22
# File 'lib/boxen/service.rb', line 20

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/boxen/service.rb', line 5

def name
  @name
end

Class Method Details

.listObject



7
8
9
10
11
# File 'lib/boxen/service.rb', line 7

def self.list
  files.collect do |service|
    new(human_name(service))
  end
end

.list_enabledObject



13
14
15
16
17
18
# File 'lib/boxen/service.rb', line 13

def self.list_enabled
  prefix = /^dev\./
  enabled = capture_output("sudo /bin/launchctl list").split("\n").map { |l| l.split(/\s/) }.map(&:last)
  names = enabled.grep(prefix).map { |name| name.sub(prefix, "") }.compact
  names.map { |name| new(name) }
end

Instance Method Details

#disableObject



32
33
34
# File 'lib/boxen/service.rb', line 32

def disable
  Boxen::Util.sudo('/bin/launchctl', 'unload', '-w', location)
end

#enableObject



28
29
30
# File 'lib/boxen/service.rb', line 28

def enable
  Boxen::Util.sudo('/bin/launchctl', 'load', '-w', location)
end

#to_sObject



24
25
26
# File 'lib/boxen/service.rb', line 24

def to_s
  name
end