Permalink
Browse files

slight cleanup of the Core Data template

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@5293 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
mattetti committed Mar 23, 2011
1 parent 66f5446 commit 8f9c7714f63f9297065c94de6da8c5e7b323b12f
@@ -169,22 +169,22 @@ end
# Creates if necessary and returns the managed object model for the application.
#
def managedObjectModel
- if @managedObjectModel.nil?
+ unless @managedObjectModel
model_url = NSBundle.mainBundle.URLForResource("___PACKAGENAMEASIDENTIFIER___", withExtension:"momd")
@managedObjectModel = NSManagedObjectModel.alloc.initWithContentsOfURL(model_url)
- else
- @managedObjectModel
end
+
+ @managedObjectModel
end
#
# Returns the persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.)
#
def persistentStoreCoordinator
- return @persistentStoreCoordinator unless @persistentStoreCoordinator.nil?
+ return @persistentStoreCoordinator if @persistentStoreCoordinator
mom = self.managedObjectModel
- if mom.nil?
+ unless mom
puts "#{self.class} No model to generate a store from"
return nil
end
@@ -211,7 +211,6 @@ def persistentStoreCoordinator
NSApplication.sharedApplication.presentError(error)
return nil
- end
end
url = directory.URLByAppendingPathComponent("___PACKAGENAMEASIDENTIFIER___.storedata")
@@ -230,11 +229,10 @@ end
# bound to the persistent store coordinator for the application.)
#
def managedObjectContext
- return @managedObjectContext unless @managedObjectContext.nil?
-
+ return @managedObjectContext if @managedObjectContext
coordinator = self.persistentStoreCoordinator
- if coordinator.nil?
+ unless coordinator
dict = {
NSLocalizedDescriptionKey => "Failed to initialize the store",
NSLocalizedFailureReasonErrorKey => "There was an error building up the data file."
@@ -275,7 +273,7 @@ end
def applicationShouldTerminate(sender)
# Save changes in the application's managed object context before the application terminates.
- return NSTerminateNow if @managedObjectContext.nil?
+ return NSTerminateNow unless @managedObjectContext
unless self.managedObjectContext.commitEditing
puts "%@ unable to commit editing to terminate" % self.class
@@ -288,9 +286,7 @@ def applicationShouldTerminate(sender)
error = Pointer.new_with_type('@')
unless self.managedObjectContext.save(error)
# Customize this code block to include application-specific recovery steps.
- if sender.presentError(error[0]) == true
- return NSTerminateCancel
- end
+ return NSTerminateCancel if sender.presentError(error[0])
alert = NSAlert.alloc.init
alert.messageText = "Could not save changes while quitting. Quit anyway?"
@@ -299,10 +295,7 @@ def applicationShouldTerminate(sender)
alert.addButtonWithTitle "Cancel"
answer = alert.runModal
- if (answer == NSAlertAlternateReturn)
- return NSTerminateCancel
- end
-
+ return NSTerminateCancel if answer == NSAlertAlternateReturn
end
NSTerminateNow

0 comments on commit 8f9c771

Please sign in to comment.