Class: OpenDirectory::Dscl
- Inherits:
-
Object
- Object
- OpenDirectory::Dscl
- Defined in:
- lib/open_directory/dscl.rb
Constant Summary collapse
- @@commands =
[]
Class Method Summary collapse
Class Method Details
.generate(command, path, params = "") ⇒ Object
7 8 9 10 11 12 |
# File 'lib/open_directory/dscl.rb', line 7 def self.generate(command, path, params="") datasource ||= OpenDirectory.od_datasource params = params.join(" ") unless params.empty? @@commands << "dscl -plist -u #{OpenDirectory.od_username} -P #{OpenDirectory.od_password} #{datasource} -#{command} #{path} #{params}" end |
.parse_output(string) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/open_directory/dscl.rb', line 14 def self.parse_output(string) begin parsed_xml = Plist::parse_xml( string ) if parsed_xml.nil? string.split("\n") else parsed_xml end rescue RuntimeError => e string.split("\n") rescue TypeError => e if e.nil? "" else e.to_s end end end |
.run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/open_directory/dscl.rb', line 33 def self.run response = [] $ssh ||= Net::SSH.start(OpenDirectory.host_name, OpenDirectory.host_username, :password => OpenDirectory.host_password) @@commands.each do |command| output = $ssh.exec!(command) response << {:parsed_out => parse_output(output), :output => output, :command => command} unless output.nil? end @@commands.clear if response.size == 1 response[0][:parsed_out] else response end end |