Class: Fission::Metadata

Inherits:
Object show all
Defined in:
lib/fission/metadata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/fission/metadata.rb', line 6

def content
  @content
end

Class Method Details

.delete_vm_info(vm_path) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/fission/metadata.rb', line 8

def self.delete_vm_info(vm_path)
   = new
  .load
  .delete_vm_restart_document(vm_path)
  .delete_vm_favorite_entry(vm_path)
  .save
end

Instance Method Details

#delete_vm_favorite_entry(vm_path) ⇒ Object



34
35
36
# File 'lib/fission/metadata.rb', line 34

def delete_vm_favorite_entry(vm_path)
  @content['VMFavoritesListDefaults2'].delete_if { |vm| vm['path'] == vm_path }
end

#delete_vm_restart_document(vm_path) ⇒ Object



28
29
30
31
32
# File 'lib/fission/metadata.rb', line 28

def delete_vm_restart_document(vm_path)
  if @content.has_key?('PLRestartDocumentPaths')
    @content['PLRestartDocumentPaths'].delete_if { |p| p == vm_path }
  end
end

#loadObject



16
17
18
19
# File 'lib/fission/metadata.rb', line 16

def load
  raw_data = CFPropertyList::List.new :file => Fission.config.attributes['plist_file']
  @content = CFPropertyList.native_types raw_data.value
end

#saveObject



21
22
23
24
25
26
# File 'lib/fission/metadata.rb', line 21

def save
  new_content = CFPropertyList::List.new
  new_content.value = CFPropertyList.guess @content
  new_content.save Fission.config.attributes['plist_file'],
                   CFPropertyList::List::FORMAT_BINARY
end