Class: Rucola::Nib::KeyedObjects
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
-
#change_files_owner_class(new_class) ⇒ Object
Changes the custom class of the File’s Owner.
- #files_owner_class ⇒ Object
-
#initialize(path) ⇒ KeyedObjects
constructor
A new instance of KeyedObjects.
-
#save(new_path = nil) ⇒ Object
Save the keyedobjects.nib back to the original path.
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
#data ⇒ Object (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_class ⇒ Object
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 |