Module: MacAdmin::MCX

Included in:
DSLocalRecord
Defined in:
lib/macadmin/mcx.rb

Overview

MCX

  • methods and classes mixed into MacAdmin::DSLocalRecord for managing MCX policy

Defined Under Namespace

Classes: EmbeddedDocument, Policy, Settings

Instance Method Summary collapse

Instance Method Details

#has_mcx?Boolean

Does the object have any MCX policy?

Returns:

  • (Boolean)


214
215
216
# File 'lib/macadmin/mcx.rb', line 214

def has_mcx?
  self.has_key? 'mcx_settings' and self['mcx_settings'].is_a? Array and not self['mcx_settings'].empty?
end

#mcx_deleteObject Also known as: mcxdelete

Remove all MCX policy from the object



219
220
221
222
# File 'lib/macadmin/mcx.rb', line 219

def mcx_delete
  self.delete('mcx_flags')
  self.delete('mcx_settings')
end

#mcx_exportObject Also known as: mcxexport

Export the MCX preferences for the record



202
203
204
205
# File 'lib/macadmin/mcx.rb', line 202

def mcx_export
  doc = Policy.new self['mcx_settings']
  doc.to_plist
end

#mcx_import(content, append = false) ⇒ Object Also known as: mcximport

Import MCX Content and apply it to the current object

  • accepts a single parameter: path to Plist file containing exported MCX policy or a string of XML content representing the MCX policy

  • re-formats the imported MCX for storage on the record and adds the two require attributes: mcx_flags and mcx_settings

  • current implmentation replaces policy wholesale (no append)



192
193
194
195
196
197
198
# File 'lib/macadmin/mcx.rb', line 192

def mcx_import(content, append=false)
  settings = Settings.new content
  mcx_flags = { 'has_mcx_settings' => true }
  mcx_flags = mcx_flags.to_plist({:plist_format => CFPropertyList::List::FORMAT_XML, :formatted => true})
  self['mcx_flags'] = [CFPropertyList::Blob.new(mcx_flags)]
  self['mcx_settings'] = settings.domains
end

#pretty_mcxObject

Pretty print the contents of the record’s mcx_settings array



209
210
211
# File 'lib/macadmin/mcx.rb', line 209

def pretty_mcx
  self['mcx_settings'].collect { |doc| CGI.unescapeHTML doc }
end