Class: LaunchdTools::LaunchdPlist

Inherits:
Object
  • Object
show all
Defined in:
lib/launchd_tools/launchd_plist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLaunchdPlist

Returns a new instance of LaunchdPlist.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/launchd_tools/launchd_plist.rb', line 7

def initialize
  base = %q[<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">]
  @doc = Document.new(base)
  plist_element = Element.new('plist')
  doc.add_element(plist_element, {"version" => "1.0"})
  base_dictionary = Element.new('dict')
  plist_element.add_element(base_dictionary)
  program_args_key_element = Element.new('key')
  program_args_key_element.text = 'ProgramArguments'
  base_dictionary.add_element(program_args_key_element)
  @program_args_array_element = Element.new "array"
  base_dictionary.add_element(program_args_array_element)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



5
6
7
# File 'lib/launchd_tools/launchd_plist.rb', line 5

def doc
  @doc
end

#program_args_array_elementObject (readonly)

Returns the value of attribute program_args_array_element.



5
6
7
# File 'lib/launchd_tools/launchd_plist.rb', line 5

def program_args_array_element
  @program_args_array_element
end

Instance Method Details

#add_program_arg(arg) ⇒ Object



23
24
25
26
27
# File 'lib/launchd_tools/launchd_plist.rb', line 23

def add_program_arg(arg)
  string_element = Element.new "string"
  string_element.text = arg
  program_args_array_element << string_element
end

#add_program_args(args) ⇒ Object



29
30
31
32
33
# File 'lib/launchd_tools/launchd_plist.rb', line 29

def add_program_args(args)
  args.each do |arg|
    add_program_arg(arg)
  end
end

#to_sObject



35
36
37
38
39
40
41
# File 'lib/launchd_tools/launchd_plist.rb', line 35

def to_s
  formatter = REXML::Formatters::Pretty.new # (2)
  formatter.compact = true
  xml_string = String.new
  formatter.write(doc, xml_string)
  xml_string
end