Class: LaunchDr::PropertyList

Inherits:
Object
  • Object
show all
Defined in:
lib/launchdr/property_list.rb

Direct Known Subclasses

Launchd

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = nil, elements = {}) ⇒ PropertyList

Returns a new instance of PropertyList.



9
10
11
12
# File 'lib/launchdr/property_list.rb', line 9

def initialize label = nil, elements = {}
  @elements = elements
  @elements['Label'] = label || "rb.launchdr.#{UUID.new.generate}"
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



7
8
9
# File 'lib/launchdr/property_list.rb', line 7

def elements
  @elements
end

Class Method Details

.load(filename) ⇒ Object



32
33
34
35
# File 'lib/launchdr/property_list.rb', line 32

def self.load filename
  elements = OSX::PropertyList.load File.new(File.expand_path filename, 'r')
  new elements[:label], elements
end

Instance Method Details

#[](key) ⇒ Object



14
15
16
# File 'lib/launchdr/property_list.rb', line 14

def [] key
  @elements[key.to_s]
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/launchdr/property_list.rb', line 18

def []= key, value
  @elements[key] = value
end

#dump(path) ⇒ Object



26
27
28
29
30
# File 'lib/launchdr/property_list.rb', line 26

def dump path
  out = File.new(File.expand_path(File.join(path, @elements['Label'] + '.plist')), 'w+')
  OSX::PropertyList.dump out, @elements
  out.close
end

#to_plistObject



22
23
24
# File 'lib/launchdr/property_list.rb', line 22

def to_plist
  @elements.to_plist
end