Class: Rucola::Nib::KeyedObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/rucola/nib.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ KeyedObjects

Returns a new instance of KeyedObjects.



63
64
65
66
67
68
69
# File 'lib/rucola/nib.rb', line 63

def initialize(path)
  @path = path
  @data, format, error = OSX::NSPropertyListSerialization.propertyListFromData_mutabilityOption_format_errorDescription(
    OSX::NSData.dataWithContentsOfFile(@path),
    OSX::NSPropertyListMutableContainersAndLeaves
  )
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



57
58
59
# File 'lib/rucola/nib.rb', line 57

def data
  @data
end

Class Method Details

.open(path) ⇒ Object



59
60
61
# File 'lib/rucola/nib.rb', line 59

def self.open(path)
  new(path)
end

Instance Method Details

#change_files_owner_class(new_class) ⇒ Object

Changes the custom class of the File’s Owner.



76
77
78
79
80
81
82
# File 'lib/rucola/nib.rb', line 76

def change_files_owner_class(new_class)
  # With a fresh nib the name of the custom class always appears as the 4th object
  # in the $objects array. But this might not always be the case. At least for
  # setting the initial custom class with a known nib, such as the one we use
  # as a template, will work.
  @data['$objects'][3] = new_class
end

#files_owner_classObject



71
72
73
# File 'lib/rucola/nib.rb', line 71

def files_owner_class
  @data['$objects'][3]
end

#save(new_path = nil) ⇒ Object

Save the keyedobjects.nib back to the original path. Or alternatively pass it a new path.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rucola/nib.rb', line 86

def save(new_path = nil)
  new_data, new_error = OSX::NSPropertyListSerialization.dataFromPropertyList_format_errorDescription(@data, OSX::NSPropertyListBinaryFormat_v1_0)

  Rucola::Nib.backup(@path)

  path = (new_path.nil? ? @path : new_path)
  dirname = File.dirname(path)
  FileUtils.mkdir_p(dirname) unless File.exists?(dirname)

  new_data.writeToFile_atomically(path, true)
end