Skip to content
Browse files

Removing references to ActiveRecord, renaming to MagicalRecord

  • Loading branch information...
1 parent c9533eb commit 1a4f8d6e3981d3c9ba3a5b92b59cbb06f1826404 @casademora casademora committed Jun 29, 2011
View
2 ARCoreDataAction.h
@@ -7,7 +7,7 @@
//
#import <Foundation/Foundation.h>
-#import "NSManagedObjectContext+ActiveRecord.h"
+#import "NSManagedObjectContext+MagicalRecord.h"
typedef enum
{
View
2 ARCoreDataAction.m
@@ -18,7 +18,7 @@ dispatch_queue_t background_save_queue()
{
if (coredata_background_save_queue == NULL)
{
- coredata_background_save_queue = dispatch_queue_create("com.magicalpanda.coredata.backgroundsaves", 0);
+ coredata_background_save_queue = dispatch_queue_create("com.magicalpanda.magicalrecord.backgroundsaves", 0);
}
return coredata_background_save_queue;
}
View
10 CoreData+MagicalRecord.h
@@ -17,10 +17,10 @@
#import "MagicalRecordHelpers.h"
#import "ARCoreDataAction.h"
-#import "NSManagedObject+ActiveRecord.h"
-#import "NSManagedObjectContext+ActiveRecord.h"
-#import "NSPersistentStoreCoordinator+ActiveRecord.h"
-#import "NSManagedObjectModel+ActiveRecord.h"
-#import "NSPersistentStore+ActiveRecord.h"
+#import "NSManagedObject+MagicalRecord.h"
+#import "NSManagedObjectContext+MagicalRecord.h"
+#import "NSPersistentStoreCoordinator+MagicalRecord.h"
+#import "NSManagedObjectModel+MagicalRecord.h"
+#import "NSPersistentStore+MagicalRecord.h"
#import "NSManagedObject+JSONHelpers.h"
View
2 MagicalRecordHelpers.h
@@ -1,5 +1,5 @@
//
-// ActiveRecordHelpers.h
+// MagicalRecordHelpers.h
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
View
4 MagicalRecordHelpers.m
@@ -1,5 +1,5 @@
//
-// ActiveRecordHelpers.m
+// MagicalRecordHelpers.m
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
@@ -86,7 +86,7 @@ + (void) setupCoreDataStack
+ (void) setupAutoMigratingCoreDataStack
{
- [self setupCoreDataStackWithAutoMigratingSqliteStoreNamed:kActiveRecordDefaultStoreFileName];
+ [self setupCoreDataStackWithAutoMigratingSqliteStoreNamed:kMagicalRecordDefaultStoreFileName];
}
+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName
View
6 NSManagedObject+ActiveRecord.h → NSManagedObject+MagicalRecord.h
@@ -7,11 +7,9 @@
#import <CoreData/CoreData.h>
#import "MagicalRecordHelpers.h"
-#define kActiveRecordDefaultBatchSize 20
+#define kMagicalRecordDefaultBatchSize 20
-@interface NSManagedObject (ActiveRecord)
-
-//+ (void) handleErrors:(NSError *)error;
+@interface NSManagedObject (MagicalRecord)
+ (NSUInteger) defaultBatchSize;
+ (void) setDefaultBatchSize:(NSUInteger)newBatchSize;
View
10 NSManagedObject+ActiveRecord.m → NSManagedObject+MagicalRecord.m
@@ -3,12 +3,12 @@
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
-#import "NSManagedObject+ActiveRecord.h"
+#import "NSManagedObject+MagicalRecord.h"
#import "CoreData+MagicalRecord.h"
-static NSUInteger defaultBatchSize = kActiveRecordDefaultBatchSize;
+static NSUInteger defaultBatchSize = kMagicalRecordDefaultBatchSize;
-@implementation NSManagedObject (ActiveRecord)
+@implementation NSManagedObject (MagicalRecord)
+ (void) setDefaultBatchSize:(NSUInteger)newBatchSize
@@ -370,7 +370,7 @@ + (NSFetchedResultsController *) fetchRequestAllGroupedBy:(NSString *)group with
{
NSString *cacheName = nil;
#ifdef STORE_USE_CACHE
- cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass(self)];
+ cacheName = [NSString stringWithFormat:@"MagicalRecord-Cache-%@", NSStringFromClass(self)];
#endif
NSFetchRequest *request = [self requestAllSortedBy:sortTerm
@@ -419,7 +419,7 @@ + (NSFetchedResultsController *) fetchRequest:(NSFetchRequest *)request groupedB
{
NSString *cacheName = nil;
#ifdef STORE_USE_CACHE
- cacheName = [NSString stringWithFormat:@"ActiveRecord-Cache-%@", NSStringFromClass([self class])];
+ cacheName = [NSString stringWithFormat:@"MagicalRecord-Cache-%@", NSStringFromClass([self class])];
#endif
NSFetchedResultsController *controller =
[[NSFetchedResultsController alloc] initWithFetchRequest:request
View
4 NSManagedObjectContext+ActiveRecord.h → NSManagedObjectContext+MagicalRecord.h
@@ -1,13 +1,13 @@
//
-// NSManagedObjectContext+ActiveRecord.h
+// NSManagedObjectContext+MagicalRecord.h
//
// Created by Saul Mora on 11/23/09.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
#import "MagicalRecordHelpers.h"
-@interface NSManagedObjectContext (ActiveRecord)
+@interface NSManagedObjectContext (MagicalRecord)
- (void) observeContext:(NSManagedObjectContext *)otherContext;
- (void) stopObservingContext:(NSManagedObjectContext *)otherContext;
View
10 NSManagedObjectContext+ActiveRecord.m → NSManagedObjectContext+MagicalRecord.m
@@ -1,5 +1,5 @@
//
-// NSManagedObjectContext+ActiveRecord.m
+// NSManagedObjectContext+MagicalRecord.m
//
// Created by Saul Mora on 11/23/09.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
@@ -9,9 +9,9 @@
#import <objc/runtime.h>
static NSManagedObjectContext *defaultManageObjectContext = nil;
-static NSString const * kActiveRecordManagedObjectContextKey = @"MagicalRecord_NSManagedObjectContextForThreadKey";
+static NSString const * kMagicalRecordManagedObjectContextKey = @"MagicalRecord_NSManagedObjectContextForThreadKey";
-@implementation NSManagedObjectContext (ActiveRecord)
+@implementation NSManagedObjectContext (MagicalRecord)
+ (NSManagedObjectContext *)defaultContext
{
@@ -56,11 +56,11 @@ + (NSManagedObjectContext *) contextForCurrentThread
else
{
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
- NSManagedObjectContext *threadContext = [threadDict objectForKey:kActiveRecordManagedObjectContextKey];
+ NSManagedObjectContext *threadContext = [threadDict objectForKey:kMagicalRecordManagedObjectContextKey];
if (threadContext == nil)
{
threadContext = [self contextThatNotifiesDefaultContextOnMainThread];
- [threadDict setObject:threadContext forKey:kActiveRecordManagedObjectContextKey];
+ [threadDict setObject:threadContext forKey:kMagicalRecordManagedObjectContextKey];
}
return threadContext;
}
View
4 NSManagedObjectModel+ActiveRecord.h → NSManagedObjectModel+MagicalRecord.h
@@ -1,5 +1,5 @@
//
-// NSManagedObjectModel+ActiveRecord.h
+// NSManagedObjectModel+MagicalRecord.h
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
@@ -8,7 +8,7 @@
#import <Foundation/Foundation.h>
#import "MagicalRecordHelpers.h"
-@interface NSManagedObjectModel (ActiveRecord)
+@interface NSManagedObjectModel (MagicalRecord)
+ (NSManagedObjectModel *)defaultManagedObjectModel;
+ (void) setDefaultManagedObjectModel:(NSManagedObjectModel *)newDefaultModel;
View
6 NSManagedObjectModel+ActiveRecord.m → NSManagedObjectModel+MagicalRecord.m
@@ -1,16 +1,16 @@
//
-// NSManagedObjectModel+ActiveRecord.m
+// NSManagedObjectModel+MagicalRecord.m
// DocBook
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
-#import "NSManagedObjectModel+ActiveRecord.h"
+#import "NSManagedObjectModel+MagicalRecord.h"
static NSManagedObjectModel *defaultManagedObjectModel = nil;
-@implementation NSManagedObjectModel (ActiveRecord)
+@implementation NSManagedObjectModel (MagicalRecord)
+ (NSManagedObjectModel *)defaultManagedObjectModel
View
6 NSPersistentStore+ActiveRecord.h → NSPersistentStore+MagicalRecord.h
@@ -1,15 +1,15 @@
//
-// NSPersistentStore+ActiveRecord.h
+// NSPersistentStore+MagicalRecord.h
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
#import "MagicalRecordHelpers.h"
-#define kActiveRecordDefaultStoreFileName @"CoreDataStore.sqlite"
+#define kMagicalRecordDefaultStoreFileName @"CoreDataStore.sqlite"
-@interface NSPersistentStore (ActiveRecord)
+@interface NSPersistentStore (MagicalRecord)
+ (NSURL *) defaultLocalStoreUrl;
View
12 NSPersistentStore+ActiveRecord.m → NSPersistentStore+MagicalRecord.m
@@ -1,15 +1,15 @@
//
-// NSPersistentStore+ActiveRecord.m
+// NSPersistentStore+MagicalRecord.m
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
-#import "NSPersistentStore+ActiveRecord.h"
+#import "NSPersistentStore+MagicalRecord.h"
static NSPersistentStore *defaultPersistentStore = nil;
-@implementation NSPersistentStore (ActiveRecord)
+@implementation NSPersistentStore (MagicalRecord)
+ (NSPersistentStore *) defaultPersistentStore
{
@@ -33,12 +33,12 @@ + (NSString *)applicationDocumentsDirectory
+ (NSString *)applicationLibraryDirectory
{
-#ifdef TARGET_OS_MAC
+#if !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR)
NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];
return [[self directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName];
-#elif defined(TARGET_OS_IPHONE)
+#elif defined(TARGET_OS_MAC)
return [self directory:NSLibraryDirectory];
@@ -67,7 +67,7 @@ + (NSURL *) urlForStoreName:(NSString *)storeFileName
+ (NSURL *)defaultLocalStoreUrl
{
- return [self urlForStoreName:kActiveRecordDefaultStoreFileName];
+ return [self urlForStoreName:kMagicalRecordDefaultStoreFileName];
}
@end
View
6 NSPersistentStoreCoordinator+ActiveRecord.h → NSPersistentStoreCoordinator+MagicalRecord.h
@@ -1,15 +1,15 @@
//
-// NSPersistentStoreCoordinator+ActiveRecord.h
+// NSPersistentStoreCoordinator+MagicalRecord.h
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
#import "MagicalRecordHelpers.h"
-#import "NSPersistentStore+ActiveRecord.h"
+#import "NSPersistentStore+MagicalRecord.h"
-@interface NSPersistentStoreCoordinator (ActiveRecord)
+@interface NSPersistentStoreCoordinator (MagicalRecord)
+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator;
+ (void) setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator;
View
12 NSPersistentStoreCoordinator+ActiveRecord.m → NSPersistentStoreCoordinator+MagicalRecord.m
@@ -1,17 +1,17 @@
//
-// NSPersistentStoreCoordinator+ActiveRecord.m
+// NSPersistentStoreCoordinator+MagicalRecord.m
//
// Created by Saul Mora on 3/11/10.
// Copyright 2010 Magical Panda Software, LLC All rights reserved.
//
-#import "NSPersistentStoreCoordinator+ActiveRecord.h"
-#import "NSManagedObjectModel+ActiveRecord.h"
-#import "NSPersistentStore+ActiveRecord.h"
+#import "NSPersistentStoreCoordinator+MagicalRecord.h"
+#import "NSManagedObjectModel+MagicalRecord.h"
+#import "NSPersistentStore+MagicalRecord.h"
static NSPersistentStoreCoordinator *defaultCoordinator = nil;
-@implementation NSPersistentStoreCoordinator (ActiveRecord)
+@implementation NSPersistentStoreCoordinator (MagicalRecord)
+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator
{
@@ -122,7 +122,7 @@ - (NSPersistentStore *) addInMemoryStore
+ (NSPersistentStoreCoordinator *) newPersistentStoreCoordinator
{
- return [self coordinatorWithSqliteStoreNamed:kActiveRecordDefaultStoreFileName];
+ return [self coordinatorWithSqliteStoreNamed:kMagicalRecordDefaultStoreFileName];
}
@end
View
14 README.md
@@ -1,4 +1,4 @@
-# ActiveRecord Fetching for Core Data
+# MagicalRecord for Core Data
In software engineering, the active record pattern is a design pattern found in software that stores its data in relational databases. It was named by Martin Fowler in his book Patterns of Enterprise Application Architecture. The interface to such an object would include functions such as Insert, Update, and Delete, plus properties that correspond more-or-less directly to the columns in the underlying database table.
@@ -22,8 +22,8 @@ Active Record for Core Data was inspired by the ease of Ruby on Rails' Active Re
## Setting up the Core Data Stack
-To get started, first, import the header file *CoreData+ActiveRecordFetching.h* in your project's pch file. This will allow a global include of all the required headers.
-Next, somewhere in your app's startup, say in the applicationDidFinishLaunching:(UIApplication *) withOptions:(NSDictionary *) method, use one of the following setup calls with the ActiveRecordHelpers class:
+To get started, first, import the header file *CoreData+MagicalRecord.h* in your project's pch file. This will allow a global include of all the required headers.
+Next, somewhere in your app's startup, say in the applicationDidFinishLaunching:(UIApplication *) withOptions:(NSDictionary *) method, use one of the following setup calls with the MagicalRecordHelpers class:
+ (void) setupCoreDataStack;
+ (void) setupAutoMigratingDefaultCoreDataStack;
@@ -37,11 +37,11 @@ Simply start creating, fetching and updating objects. A default stack will be cr
And, before your app exits, you can use the clean up method:
- [ActiveRecordHelpers cleanUp];
+ [MagicalRecordHelpers cleanUp];
### Default Managed Object Context
-When using Core Data, you will deal with two types of objects the most: NSManagedObject and NSManagedObjectContext. ActiveRecord for Core Data gives you a place for a default NSManagedObjectContext for use within your app. This is great for single threaded apps. If you need to create a new Managed Object Context for use in other threads, based on your single persistent store, use:
+When using Core Data, you will deal with two types of objects the most: NSManagedObject and NSManagedObjectContext. MagicalRecord for Core Data gives you a place for a default NSManagedObjectContext for use within your app. This is great for single threaded apps. If you need to create a new Managed Object Context for use in other threads, based on your single persistent store, use:
NSManagedObjectContext *myNewContext = [NSManagedObjectContext context];
@@ -59,7 +59,7 @@ This will use the same object model and persistent store, but create an entirely
### Fetching
#### Basic Finding
-Most methods in the ActiveRecord for Core Data library return an NSArray of results. So, if you have an Entity called Person, related to a Department (as seen in various Apple Core Data documentation), to get all the Person entities from your Persistent Store:
+Most methods in the MagicalRecord for Core Data library return an NSArray of results. So, if you have an Entity called Person, related to a Department (as seen in various Apple Core Data documentation), to get all the Person entities from your Persistent Store:
NSArray *people = [Person findAll];
@@ -175,7 +175,7 @@ Paraphrasing the [Apple documentation on Core Data and Threading]("http://develo
* Use an instance of your NSManagedObjects that is local for the new NSManagedObjectContext
* Notify other contexts that the background is updated or saved
-The Active Record fetching library is trying to make these steps more reusable with the following methods:
+The Magical Record library is trying to make these steps more reusable with the following methods:
+ (void) performSaveDataOperationWithBlock:(CoreDataBlock)block;
+ (void) performSaveDataOperationInBackgroundWithBlock:(CoreDataBlock)block;

3 comments on commit 1a4f8d6

@zorn
zorn commented on 1a4f8d6 Jul 19, 2011

Any reason you sticking with "ARCoreDataAction.h" rather than "MRCoreDataAction.h" ?

@casademora
Magical Panda Software member
@zorn
zorn commented on 1a4f8d6 Jul 19, 2011

Ok. Sounds good.

Please sign in to comment.
Something went wrong with that request. Please try again.