Browse files

Add category prefix for persistent store and coordinator categories

  • Loading branch information...
1 parent 396573e commit 1bc58918635b40078ec4bcc45ff2b2f17a60c344 @casademora casademora committed Jul 24, 2011
View
1 Mac App Unit Tests/Mac App Unit Tests-Prefix.pch
@@ -9,6 +9,7 @@
#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>
+ #define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"
#import "FixtureHelpers.h"
#endif
View
59 Source/Categories/NSManagedObject+MagicalRecord.h
@@ -108,33 +108,34 @@
#endif
-
-#ifdef MR_SHORTHAND
-
-#define defaultBatchSize MR_defaultBatchSize
-#define setDefaultBatchSize MR_setDefaultBatchSize
-
-#define createFetchRequest MR_createFetchRequest
-#define executeFetchRequest MR_executeFetchRequest
-
-#define requestAll MR_requestAll
-#define trucateAll MR_truncateAll
-
-#define numberOfEntities MR_numberOfEntities
-#define hasAtLeastOneEntity MR_hasAtLeastOneEntity
-
-#define findAll MR_findAll
-#define findByAttribute MR_findByAttribute
-
-#define findFirst MR_findFirst
-#define findFirstByAttribute MR_findFirstByAttribute
-
-#define fetchAllSortedBy MR_fetchAllSortedBy
-#define fetchRequest MR_fetchRequest
-
-#define inContext MR_inContext
-#define inThreadContext MR_inThreadContext
-
-#endif
-
@end
+
+/*
+ #ifdef MR_SHORTHAND
+
+ #define defaultBatchSize MR_defaultBatchSize
+ #define setDefaultBatchSize MR_setDefaultBatchSize
+
+ #define createFetchRequest MR_createFetchRequest
+ #define executeFetchRequest MR_executeFetchRequest
+
+ #define requestAll MR_requestAll
+ #define trucateAll MR_truncateAll
+
+ #define numberOfEntities MR_numberOfEntities
+ #define hasAtLeastOneEntity MR_hasAtLeastOneEntity
+
+ #define findAll MR_findAll
+ #define findByAttribute MR_findByAttribute
+
+ #define findFirst MR_findFirst
+ #define findFirstByAttribute MR_findFirstByAttribute
+
+ #define fetchAllSortedBy MR_fetchAllSortedBy
+ #define fetchRequest MR_fetchRequest
+
+ #define inContext MR_inContext
+ #define inThreadContext MR_inThreadContext
+
+ #endif
+ */
View
8 Source/Categories/NSManagedObjectContext+MagicalRecord.h
@@ -39,7 +39,7 @@
@end
-
+/*
#ifdef MR_SHORTHAND
#define observeContext MR_observeContext
@@ -56,10 +56,12 @@
#define setNotifiesMainContextOnSave MR_setNotifiesMainContextOnSave
#define notifiesMainContextonSave MR_notifiesMainContextonSave
-#define context] MR_context]
+//#define context] MR_context]
#define contextForCurrentThread MR_contextForCurrentThread
#define contextThatNotifiesDefaultContextOnMainThread MR_contextThatNotifiesDefaultContextOnMainThread
#define contextWithStoreCoordinator MR_contextWithStoreCoodinator
-#endif
+#endif
+
+*/
View
2 Source/Categories/NSManagedObjectContext+MagicalRecord.m
@@ -224,7 +224,7 @@ + (NSManagedObjectContext *) contextThatNotifiesDefaultContextOnMainThreadWithCo
+ (NSManagedObjectContext *) context
{
- return [self contextWithStoreCoordinator:[NSPersistentStoreCoordinator defaultStoreCoordinator]];
+ return [self contextWithStoreCoordinator:[NSPersistentStoreCoordinator MR_defaultStoreCoordinator]];
}
+ (NSManagedObjectContext *) contextThatNotifiesDefaultContextOnMainThread
View
4 Source/Categories/NSManagedObjectModel+MagicalRecord.h
@@ -20,6 +20,7 @@
@end
+/*
#ifdef MR_SHORTHAND
#define defaultManagedObjectModel MR_defaultManagedObjectModel
@@ -28,4 +29,5 @@
#define managedObectModelNamed MR_managedObjectModelNamed
#define newModelNamed MR_newModelNamed
-#endif
+#endif
+*/
View
8 Source/Categories/NSPersistentStore+MagicalRecord.h
@@ -12,12 +12,12 @@ extern NSString * const kMagicalRecordDefaultStoreFileName;
@interface NSPersistentStore (MagicalRecord)
-+ (NSURL *) defaultLocalStoreUrl;
++ (NSURL *) MR_defaultLocalStoreUrl;
-+ (NSPersistentStore *) defaultPersistentStore;
-+ (void) setDefaultPersistentStore:(NSPersistentStore *) store;
++ (NSPersistentStore *) MR_defaultPersistentStore;
++ (void) MR_setDefaultPersistentStore:(NSPersistentStore *) store;
-+ (NSURL *) urlForStoreName:(NSString *)storeFileName;
++ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName;
@end
View
32 Source/Categories/NSPersistentStore+MagicalRecord.m
@@ -10,47 +10,47 @@
NSString * const kMagicalRecordDefaultStoreFileName = @"CoreDataStore.sqlite";
-static NSPersistentStore *defaultPersistentStore = nil;
+static NSPersistentStore *defaultPersistentStore_ = nil;
@implementation NSPersistentStore (MagicalRecord)
-+ (NSPersistentStore *) defaultPersistentStore
++ (NSPersistentStore *) MR_defaultPersistentStore
{
- return defaultPersistentStore;
+ return defaultPersistentStore_;
}
-+ (void) setDefaultPersistentStore:(NSPersistentStore *) store
++ (void) MR_setDefaultPersistentStore:(NSPersistentStore *) store
{
- defaultPersistentStore = store;
+ defaultPersistentStore_ = store;
}
-+ (NSString *) directory:(int) type
++ (NSString *) MR_directory:(int) type
{
return [NSSearchPathForDirectoriesInDomains(type, NSUserDomainMask, YES) lastObject];
}
-+ (NSString *)applicationDocumentsDirectory
++ (NSString *)MR_applicationDocumentsDirectory
{
- return [self directory:NSDocumentDirectory];
+ return [self MR_directory:NSDocumentDirectory];
}
-+ (NSString *)applicationLibraryDirectory
++ (NSString *)MR_applicationLibraryDirectory
{
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
NSString *applicationName = [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];
- return [[self directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName];
+ return [[self MR_directory:NSApplicationSupportDirectory] stringByAppendingPathComponent:applicationName];
#else
- return [self directory:NSLibraryDirectory];
+ return [self MR_directory:NSLibraryDirectory];
#endif
}
-+ (NSURL *) urlForStoreName:(NSString *)storeFileName
++ (NSURL *) MR_urlForStoreName:(NSString *)storeFileName
{
- NSArray *paths = [NSArray arrayWithObjects:[self applicationDocumentsDirectory], [self applicationLibraryDirectory], nil];
+ NSArray *paths = [NSArray arrayWithObjects:[self MR_applicationDocumentsDirectory], [self MR_applicationLibraryDirectory], nil];
NSFileManager *fm = [[NSFileManager alloc] init];
for (NSString *path in paths)
@@ -63,12 +63,12 @@ + (NSURL *) urlForStoreName:(NSString *)storeFileName
}
//set default url
- return [NSURL fileURLWithPath:[[self applicationLibraryDirectory] stringByAppendingPathComponent:storeFileName]];
+ return [NSURL fileURLWithPath:[[self MR_applicationLibraryDirectory] stringByAppendingPathComponent:storeFileName]];
}
-+ (NSURL *)defaultLocalStoreUrl
++ (NSURL *)MR_defaultLocalStoreUrl
{
- return [self urlForStoreName:kMagicalRecordDefaultStoreFileName];
+ return [self MR_urlForStoreName:kMagicalRecordDefaultStoreFileName];
}
@end
View
16 Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.h
@@ -11,18 +11,18 @@
@interface NSPersistentStoreCoordinator (MagicalRecord)
-+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator;
-+ (void) setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator;
++ (NSPersistentStoreCoordinator *) MR_defaultStoreCoordinator;
++ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator;
-+ (NSPersistentStoreCoordinator *) coordinatorWithInMemoryStore;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithInMemoryStore;
-+ (NSPersistentStoreCoordinator *)newPersistentStoreCoordinator;
++ (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator;
-+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName;
-+ (NSPersistentStoreCoordinator *) coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
-+ (NSPersistentStoreCoordinator *) coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
-- (NSPersistentStore *) addInMemoryStore;
+- (NSPersistentStore *) MR_addInMemoryStore;
@end
View
40 Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m
@@ -15,24 +15,24 @@
@implementation NSPersistentStoreCoordinator (MagicalRecord)
-+ (NSPersistentStoreCoordinator *) defaultStoreCoordinator
++ (NSPersistentStoreCoordinator *) MR_defaultStoreCoordinator
{
@synchronized (self)
{
if (defaultCoordinator == nil)
{
- defaultCoordinator = [self newPersistentStoreCoordinator];
+ defaultCoordinator = [self MR_newPersistentStoreCoordinator];
}
}
return defaultCoordinator;
}
-+ (void) setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
++ (void) MR_setDefaultStoreCoordinator:(NSPersistentStoreCoordinator *)coordinator
{
defaultCoordinator = coordinator;
}
-- (void) setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)options
+- (void) MR_setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)options
{
NSURL *url = [storeFileName isKindOfClass:[NSURL class]] ? storeFileName : [NSPersistentStore urlForStoreName:storeFileName];
NSError *error = nil;
@@ -48,66 +48,66 @@ - (void) setupSqliteStoreNamed:(id)storeFileName withOptions:(NSDictionary *)opt
[NSPersistentStore setDefaultPersistentStore:store];
}
-+ (NSPersistentStoreCoordinator *) coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithPersitentStore:(NSPersistentStore *)persistentStore;
{
NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
- [psc setupSqliteStoreNamed:[persistentStore URL] withOptions:nil];
+ [psc MR_setupSqliteStoreNamed:[persistentStore URL] withOptions:nil];
return psc;
}
-+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName withOptions:(NSDictionary *)options
{
NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
- [psc setupSqliteStoreNamed:storeFileName withOptions:options];
+ [psc MR_setupSqliteStoreNamed:storeFileName withOptions:options];
return psc;
}
-+ (NSPersistentStoreCoordinator *) coordinatorWithSqliteStoreNamed:(NSString *)storeFileName
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithSqliteStoreNamed:(NSString *)storeFileName
{
- return [self coordinatorWithSqliteStoreNamed:storeFileName withOptions:nil];
+ return [self MR_coordinatorWithSqliteStoreNamed:storeFileName withOptions:nil];
}
-- (void) setupAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
+- (void) MR_setupAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
- [self setupSqliteStoreNamed:storeFileName withOptions:options];
+ [self MR_setupSqliteStoreNamed:storeFileName withOptions:options];
}
-+ (NSPersistentStoreCoordinator *) coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithAutoMigratingSqliteStoreNamed:(NSString *) storeFileName
{
NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel];
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
- [coordinator setupAutoMigratingSqliteStoreNamed:storeFileName];
+ [coordinator MR_setupAutoMigratingSqliteStoreNamed:storeFileName];
//HACK: lame solution to fix automigration error "Migration failed after first pass"
if ([[coordinator persistentStores] count] == 0)
{
- [coordinator performSelector:@selector(setupAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5];
+ [coordinator performSelector:@selector(MR_setupAutoMigratingSqliteStoreNamed:) withObject:storeFileName afterDelay:0.5];
}
return coordinator;
}
-+ (NSPersistentStoreCoordinator *) coordinatorWithInMemoryStore
++ (NSPersistentStoreCoordinator *) MR_coordinatorWithInMemoryStore
{
NSManagedObjectModel *model = [NSManagedObjectModel defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
- [NSPersistentStore setDefaultPersistentStore:[psc addInMemoryStore]];
+ [NSPersistentStore setDefaultPersistentStore:[psc MR_addInMemoryStore]];
return psc;
}
-- (NSPersistentStore *) addInMemoryStore
+- (NSPersistentStore *) MR_addInMemoryStore
{
NSError *error = nil;
NSPersistentStore *store = [self addPersistentStoreWithType:NSInMemoryStoreType
@@ -122,9 +122,9 @@ - (NSPersistentStore *) addInMemoryStore
return store;
}
-+ (NSPersistentStoreCoordinator *) newPersistentStoreCoordinator
++ (NSPersistentStoreCoordinator *) MR_newPersistentStoreCoordinator
{
- return [self coordinatorWithSqliteStoreNamed:kMagicalRecordDefaultStoreFileName];
+ return [self MR_coordinatorWithSqliteStoreNamed:kMagicalRecordDefaultStoreFileName];
}
@end
View
14 Source/MagicalRecordHelpers.m
@@ -17,7 +17,7 @@ + (void) cleanUp
[MRCoreDataAction cleanUp];
[NSManagedObjectContext setDefaultContext:nil];
[NSManagedObjectModel setDefaultManagedObjectModel:nil];
- [NSPersistentStoreCoordinator setDefaultStoreCoordinator:nil];
+ [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:nil];
[NSPersistentStore setDefaultPersistentStore:nil];
}
@@ -100,26 +100,26 @@ + (void) setupAutoMigratingCoreDataStack
+ (void) setupCoreDataStackWithStoreNamed:(NSString *)storeName
{
- NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithSqliteStoreNamed:storeName];
- [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithSqliteStoreNamed:storeName];
+ [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
[NSManagedObjectContext setDefaultContext:context];
}
+ (void) setupCoreDataStackWithAutoMigratingSqliteStoreNamed:(NSString *)storeName
{
- NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithAutoMigratingSqliteStoreNamed:storeName];
- [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithAutoMigratingSqliteStoreNamed:storeName];
+ [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
[NSManagedObjectContext setDefaultContext:context];
}
+ (void) setupCoreDataStackWithInMemoryStore
{
- NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator coordinatorWithInMemoryStore];
- [NSPersistentStoreCoordinator setDefaultStoreCoordinator:coordinator];
+ NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_coordinatorWithInMemoryStore];
+ [NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:coordinator];
NSManagedObjectContext *context = [NSManagedObjectContext contextWithStoreCoordinator:coordinator];
[NSManagedObjectContext setDefaultContext:context];
View
3 Unit Tests/MagicalRecordHelperTests.m
@@ -25,7 +25,7 @@ - (void) assertDefaultStack
{
assertThat([NSManagedObjectContext defaultContext], is(notNilValue()));
assertThat([NSManagedObjectModel defaultManagedObjectModel], is(notNilValue()));
- assertThat([NSPersistentStoreCoordinator defaultStoreCoordinator], is(notNilValue()));
+ assertThat([NSPersistentStoreCoordinator MR_defaultStoreCoordinator], is(notNilValue()));
assertThat([NSPersistentStore defaultPersistentStore], is(notNilValue()));
}
@@ -90,7 +90,6 @@ - (void) testUserSpecifiedErrorHandlersAreTriggeredOnError
assertThatBool(errorHandlerWasCalled_, is(equalToBool(YES)));
}
-
- (void) testLogsErrorsToLogger
{
GHFail(@"Test Not Implemented");
View
1 iOS App Unit Tests/iOS App Unit Tests-Prefix.pch
@@ -17,6 +17,7 @@
#define HC_SHORTHAND
#import <OCHamcrestIOS/OCHamcrestIOS.h>
+ #define MR_SHORTHAND
#import "CoreData+MagicalRecord.h"
#import "FixtureHelpers.h"
#endif

0 comments on commit 1bc5891

Please sign in to comment.