mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
Replaced newObject with object to make the static analyzer happy. Changed method signature for createManagedObjectContext to newManagedObjectContext.
This commit is contained in:
@@ -95,9 +95,9 @@
|
||||
return count;
|
||||
}
|
||||
|
||||
+ (id)newObject {
|
||||
id model = [[self alloc] initWithEntity:[self entity] insertIntoManagedObjectContext:[RKManagedObject managedObjectContext]];
|
||||
return [model autorelease];
|
||||
+ (id)object {
|
||||
id object = [[self alloc] initWithEntity:[self entity] insertIntoManagedObjectContext:[RKManagedObject managedObjectContext]];
|
||||
return [object autorelease];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
@@ -108,35 +108,7 @@
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark RKModelMappable
|
||||
|
||||
// TODO: All this path shit needs cleaning up...
|
||||
- (NSString*)resourcePath {
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
return nil;
|
||||
}
|
||||
|
||||
// TODO: This is Rails specific. Clean up!
|
||||
// TODO: Moves to the router
|
||||
- (NSString*)resourcePathForMethod:(RKRequestMethod)method {
|
||||
// TODO: Support an optional RKObjectAdapter class?
|
||||
switch (method) {
|
||||
case RKRequestMethodGET:
|
||||
case RKRequestMethodPUT:
|
||||
case RKRequestMethodDELETE:
|
||||
return [NSString stringWithFormat:@"%@/%@", [self resourcePath], [self valueForKey:[[self class] primaryKey]]];
|
||||
break;
|
||||
|
||||
case RKRequestMethodPOST:
|
||||
return [NSString stringWithFormat:@"%@", [self resourcePath]];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
#pragma mark RKObjectMappable
|
||||
|
||||
// TODO: Would be nice to specify this via an annotation in the mappings definition...
|
||||
+ (NSString*)primaryKey {
|
||||
|
||||
@@ -15,7 +15,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
|
||||
@interface RKManagedObjectStore (Private)
|
||||
- (void)createPersistentStoreCoordinator;
|
||||
- (NSString *)applicationDocumentsDirectory;
|
||||
- (NSManagedObjectContext*)createManagedObjectContext;
|
||||
- (NSManagedObjectContext*)newManagedObjectContext;
|
||||
@end
|
||||
|
||||
@implementation RKManagedObjectStore
|
||||
@@ -30,7 +30,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
|
||||
_storeFilename = [storeFilename retain];
|
||||
_managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
|
||||
[self createPersistentStoreCoordinator];
|
||||
_managedObjectContext = [self createManagedObjectContext];
|
||||
_managedObjectContext = [self newManagedObjectContext];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -78,7 +78,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
|
||||
}
|
||||
}
|
||||
|
||||
- (NSManagedObjectContext*)createManagedObjectContext {
|
||||
- (NSManagedObjectContext*)newManagedObjectContext {
|
||||
NSManagedObjectContext* managedObjectContext = [[NSManagedObjectContext alloc] init];
|
||||
[managedObjectContext setPersistentStoreCoordinator:self.persistentStoreCoordinator];
|
||||
[managedObjectContext setUndoManager:nil];
|
||||
@@ -120,7 +120,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
|
||||
[_managedObjectContext release];
|
||||
|
||||
[self createPersistentStoreCoordinator];
|
||||
_managedObjectContext = [self createManagedObjectContext];
|
||||
_managedObjectContext = [self newManagedObjectContext];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +136,7 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
|
||||
NSMutableDictionary* threadDictionary = [[NSThread currentThread] threadDictionary];
|
||||
NSManagedObjectContext* backgroundThreadContext = [threadDictionary objectForKey:kRKManagedObjectContextKey];
|
||||
if (!backgroundThreadContext) {
|
||||
backgroundThreadContext = [self createManagedObjectContext];
|
||||
backgroundThreadContext = [self newManagedObjectContext];
|
||||
[threadDictionary setObject:backgroundThreadContext forKey:kRKManagedObjectContextKey];
|
||||
[backgroundThreadContext release];
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
return [NSDictionary dictionary];
|
||||
}
|
||||
|
||||
+ (id)newObject {
|
||||
+ (id)object {
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
|
||||
@@ -213,8 +213,8 @@ static const NSString* kRKModelMapperMappingFormatParserKey = @"RKMappingFormatP
|
||||
|
||||
// instantiate if object is nil
|
||||
if (object == nil) {
|
||||
if ([class respondsToSelector:@selector(newObject)]) {
|
||||
object = [class newObject];
|
||||
if ([class respondsToSelector:@selector(object)]) {
|
||||
object = [class object];
|
||||
} else {
|
||||
object = [[[class alloc] init] autorelease];
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
/**
|
||||
* Creates a new managed object and inserts it into the managedObjectContext.
|
||||
*/
|
||||
+ (id)newObject;
|
||||
+ (id)object;
|
||||
|
||||
/**
|
||||
* Retrieves a model object from the appropriate context using the objectId
|
||||
|
||||
@@ -47,9 +47,9 @@
|
||||
- (NSDictionary*)paramsForSerialization;
|
||||
|
||||
/**
|
||||
* Must return a new instance of the model class ready for mapping. Used to initialize the model
|
||||
* Must return a new autoreleased instance of the model class ready for mapping. Used to initialize the model
|
||||
* via any method other than alloc & init.
|
||||
*/
|
||||
+ (id)newObject;
|
||||
+ (id)object;
|
||||
|
||||
@end
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
RKStaticRouter* router = [[[RKStaticRouter alloc] init] autorelease];
|
||||
NSException* exception = nil;
|
||||
@try {
|
||||
[router pathForObject:[RKHuman newObject] method:RKRequestMethodPOST];
|
||||
[router pathForObject:[RKHuman object] method:RKRequestMethodPOST];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
exception = e;
|
||||
@@ -34,7 +34,7 @@
|
||||
[router routeClass:[RKHuman class] toPath:@"/HumanService.asp" forMethod:RKRequestMethodGET];
|
||||
NSException* exception = nil;
|
||||
@try {
|
||||
[router pathForObject:[RKHuman newObject] method:RKRequestMethodPOST];
|
||||
[router pathForObject:[RKHuman object] method:RKRequestMethodPOST];
|
||||
}
|
||||
@catch (NSException * e) {
|
||||
exception = e;
|
||||
@@ -45,16 +45,16 @@
|
||||
-(void)itShouldReturnPathsRegisteredForSpecificRequestMethods {
|
||||
RKStaticRouter* router = [[[RKStaticRouter alloc] init] autorelease];
|
||||
[router routeClass:[RKHuman class] toPath:@"/HumanService.asp" forMethod:RKRequestMethodGET];
|
||||
NSString* path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodGET];
|
||||
NSString* path = [router pathForObject:[RKHuman object] method:RKRequestMethodGET];
|
||||
[expectThat(path) should:be(@"/HumanService.asp")];
|
||||
}
|
||||
|
||||
-(void)itShouldReturnPathsRegisteredForTheClassAsAWhole {
|
||||
RKStaticRouter* router = [[[RKStaticRouter alloc] init] autorelease];
|
||||
[router routeClass:[RKHuman class] toPath:@"/HumanService.asp"];
|
||||
NSString* path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodGET];
|
||||
NSString* path = [router pathForObject:[RKHuman object] method:RKRequestMethodGET];
|
||||
[expectThat(path) should:be(@"/HumanService.asp")];
|
||||
path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodPOST];
|
||||
path = [router pathForObject:[RKHuman object] method:RKRequestMethodPOST];
|
||||
[expectThat(path) should:be(@"/HumanService.asp")];
|
||||
}
|
||||
|
||||
@@ -62,11 +62,11 @@
|
||||
RKStaticRouter* router = [[[RKStaticRouter alloc] init] autorelease];
|
||||
[router routeClass:[RKHuman class] toPath:@"/HumanService.asp"];
|
||||
[router routeClass:[RKHuman class] toPath:@"/HumanServiceForPUT.asp" forMethod:RKRequestMethodPUT];
|
||||
NSString* path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodGET];
|
||||
NSString* path = [router pathForObject:[RKHuman object] method:RKRequestMethodGET];
|
||||
[expectThat(path) should:be(@"/HumanService.asp")];
|
||||
path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodPOST];
|
||||
path = [router pathForObject:[RKHuman object] method:RKRequestMethodPOST];
|
||||
[expectThat(path) should:be(@"/HumanService.asp")];
|
||||
path = [router pathForObject:[RKHuman newObject] method:RKRequestMethodPUT];
|
||||
path = [router pathForObject:[RKHuman object] method:RKRequestMethodPUT];
|
||||
[expectThat(path) should:be(@"/HumanServiceForPUT.asp")];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user