mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
Ported RestKit to using managed object contexts with concurrency types. Numerous cleanups and API updates.
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "RKObjectMappingOperation.h"
|
||||
#import "RKMappingOperation.h"
|
||||
#import "RKMappingTestExpectation.h"
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@
|
||||
@param evaluationBlock A block with which to evaluate the success of the mapping.
|
||||
@see RKObjectMappingTestExpectation
|
||||
*/
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath passingTest:(BOOL (^)(RKObjectAttributeMapping *mapping, id value))evaluationBlock;
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath passingTest:(BOOL (^)(RKAttributeMapping *mapping, id value))evaluationBlock;
|
||||
|
||||
/**
|
||||
Creates and adds an expectation that a key path on the source object will be mapped to a new
|
||||
@@ -108,7 +108,7 @@
|
||||
@param mapping An object mapping that should be used for mapping the source key path.
|
||||
@see RKObjectMappingTestExpectation
|
||||
*/
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath usingMapping:(RKObjectMappingDefinition *)mapping;
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath usingMapping:(RKMapping *)mapping;
|
||||
|
||||
/**
|
||||
Adds an expectation to the receiver to be evaluated during verification.
|
||||
|
||||
@@ -27,19 +27,19 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
|
||||
@interface RKMappingTestEvent : NSObject
|
||||
|
||||
@property (nonatomic, strong, readonly) RKObjectAttributeMapping *mapping;
|
||||
@property (nonatomic, strong, readonly) RKAttributeMapping *mapping;
|
||||
@property (nonatomic, strong, readonly) id value;
|
||||
|
||||
@property (nonatomic, readonly) NSString *sourceKeyPath;
|
||||
@property (nonatomic, readonly) NSString *destinationKeyPath;
|
||||
|
||||
+ (RKMappingTestEvent *)eventWithMapping:(RKObjectAttributeMapping *)mapping value:(id)value;
|
||||
+ (RKMappingTestEvent *)eventWithMapping:(RKAttributeMapping *)mapping value:(id)value;
|
||||
|
||||
@end
|
||||
|
||||
@interface RKMappingTestEvent ()
|
||||
@property (nonatomic, strong, readwrite) id value;
|
||||
@property (nonatomic, strong, readwrite) RKObjectAttributeMapping *mapping;
|
||||
@property (nonatomic, strong, readwrite) RKAttributeMapping *mapping;
|
||||
@end
|
||||
|
||||
@implementation RKMappingTestEvent
|
||||
@@ -47,7 +47,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
@synthesize value;
|
||||
@synthesize mapping;
|
||||
|
||||
+ (RKMappingTestEvent *)eventWithMapping:(RKObjectAttributeMapping *)mapping value:(id)value
|
||||
+ (RKMappingTestEvent *)eventWithMapping:(RKAttributeMapping *)mapping value:(id)value
|
||||
{
|
||||
RKMappingTestEvent *event = [RKMappingTestEvent new];
|
||||
event.value = value;
|
||||
@@ -77,7 +77,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
///-----------------------------------------------------------------------------
|
||||
///-----------------------------------------------------------------------------
|
||||
|
||||
@interface RKMappingTest () <RKObjectMappingOperationDelegate>
|
||||
@interface RKMappingTest () <RKMappingOperationDelegate>
|
||||
@property (nonatomic, strong, readwrite) RKObjectMapping *mapping;
|
||||
@property (nonatomic, strong, readwrite) id sourceObject;
|
||||
@property (nonatomic, strong, readwrite) id destinationObject;
|
||||
@@ -151,12 +151,12 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
[self addExpectation:[RKMappingTestExpectation expectationWithSourceKeyPath:sourceKeyPath destinationKeyPath:destinationKeyPath value:value]];
|
||||
}
|
||||
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath passingTest:(BOOL (^)(RKObjectAttributeMapping *mapping, id value))evaluationBlock
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath passingTest:(BOOL (^)(RKAttributeMapping *mapping, id value))evaluationBlock
|
||||
{
|
||||
[self addExpectation:[RKMappingTestExpectation expectationWithSourceKeyPath:sourceKeyPath destinationKeyPath:destinationKeyPath evaluationBlock:evaluationBlock]];
|
||||
}
|
||||
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath usingMapping:(RKObjectMappingDefinition *)mapping
|
||||
- (void)expectMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath usingMapping:(RKMapping *)mapping
|
||||
{
|
||||
[self addExpectation:[RKMappingTestExpectation expectationWithSourceKeyPath:sourceKeyPath destinationKeyPath:destinationKeyPath mapping:mapping]];
|
||||
}
|
||||
@@ -192,9 +192,9 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
[self description], expectation, [event.value class], event.value];
|
||||
}
|
||||
} else if (expectation.mapping) {
|
||||
if ([event.mapping isKindOfClass:[RKObjectRelationshipMapping class]]) {
|
||||
if ([event.mapping isKindOfClass:[RKRelationshipMapping class]]) {
|
||||
// Check the mapping that was used to map the relationship
|
||||
RKObjectMappingDefinition *relationshipMapping = [(RKObjectRelationshipMapping *)event.mapping mapping];
|
||||
RKMapping *relationshipMapping = [(RKRelationshipMapping *)event.mapping mapping];
|
||||
success = [relationshipMapping isEqualToMapping:expectation.mapping];
|
||||
|
||||
if (! success) {
|
||||
@@ -226,7 +226,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
if (nil == self.destinationObject) {
|
||||
self.destinationObject = [self.mapping mappableObjectForData:self.sourceObject];
|
||||
}
|
||||
RKObjectMappingOperation *mappingOperation = [RKObjectMappingOperation mappingOperationFromObject:sourceObject toObject:self.destinationObject withMapping:self.mapping];
|
||||
RKMappingOperation *mappingOperation = [RKMappingOperation mappingOperationFromObject:sourceObject toObject:self.destinationObject withMapping:self.mapping];
|
||||
NSError *error = nil;
|
||||
mappingOperation.delegate = self;
|
||||
BOOL success = [mappingOperation performMapping:&error];
|
||||
@@ -289,12 +289,12 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
[self.events addObject:event];
|
||||
}
|
||||
|
||||
- (void)objectMappingOperation:(RKObjectMappingOperation *)operation didSetValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKObjectAttributeMapping *)mapping
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didSetValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKAttributeMapping *)mapping
|
||||
{
|
||||
[self addEvent:[RKMappingTestEvent eventWithMapping:mapping value:value]];
|
||||
}
|
||||
|
||||
- (void)objectMappingOperation:(RKObjectMappingOperation *)operation didNotSetUnchangedValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKObjectAttributeMapping *)mapping
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didNotSetUnchangedValue:(id)value forKeyPath:(NSString *)keyPath usingMapping:(RKAttributeMapping *)mapping
|
||||
{
|
||||
[self addEvent:[RKMappingTestEvent eventWithMapping:mapping value:value]];
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
@class RKObjectMappingDefinition, RKObjectAttributeMapping;
|
||||
@class RKMapping, RKAttributeMapping;
|
||||
|
||||
/**
|
||||
An RKMappingTestExpectation defines an expected mapping event that should
|
||||
@@ -51,7 +51,7 @@
|
||||
@param evaluationBlock A block with which to evaluate the success of the mapping.
|
||||
@return An expectation specifying that sourceKeyPath should be mapped to destinationKeyPath with value.
|
||||
*/
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath evaluationBlock:(BOOL (^)(RKObjectAttributeMapping *mapping, id value))evaluationBlock;
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath evaluationBlock:(BOOL (^)(RKAttributeMapping *mapping, id value))evaluationBlock;
|
||||
|
||||
/**
|
||||
Creates and returns a new expectation specifying that a key path in a source object should be
|
||||
@@ -62,7 +62,7 @@
|
||||
@param mapping An object mapping that is expected to be used for mapping the nested relationship.
|
||||
@return An expectation specifying that sourceKeyPath should be mapped to destinationKeyPath using a specific object mapping.
|
||||
*/
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKObjectMappingDefinition *)mapping;
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKMapping *)mapping;
|
||||
|
||||
///-----------------------------------------------------------------------------
|
||||
/// @name Expectation Values
|
||||
@@ -86,12 +86,12 @@
|
||||
/**
|
||||
A block used to evaluate if the expectation has been satisfied.
|
||||
*/
|
||||
@property (nonatomic, copy, readonly) BOOL (^evaluationBlock)(RKObjectAttributeMapping *mapping, id value);
|
||||
@property (nonatomic, copy, readonly) BOOL (^evaluationBlock)(RKAttributeMapping *mapping, id value);
|
||||
|
||||
/**
|
||||
Returns the expected object mapping to be used for mapping a nested relationship.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) RKObjectMappingDefinition *mapping;
|
||||
@property (nonatomic, strong, readonly) RKMapping *mapping;
|
||||
|
||||
/**
|
||||
Returns a string summary of the expected keyPath mapping within the expectation
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
//
|
||||
|
||||
#import "RKMappingTestExpectation.h"
|
||||
#import "RKObjectAttributeMapping.h"
|
||||
#import "RKAttributeMapping.h"
|
||||
|
||||
@interface RKMappingTestExpectation ()
|
||||
@property (nonatomic, copy, readwrite) NSString *sourceKeyPath;
|
||||
@property (nonatomic, copy, readwrite) NSString *destinationKeyPath;
|
||||
@property (nonatomic, strong, readwrite) id value;
|
||||
@property (nonatomic, copy, readwrite) BOOL (^evaluationBlock)(RKObjectAttributeMapping *mapping, id value);
|
||||
@property (nonatomic, strong, readwrite) RKObjectMappingDefinition *mapping;
|
||||
@property (nonatomic, copy, readwrite) BOOL (^evaluationBlock)(RKAttributeMapping *mapping, id value);
|
||||
@property (nonatomic, strong, readwrite) RKMapping *mapping;
|
||||
@end
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
return expectation;
|
||||
}
|
||||
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath evaluationBlock:(BOOL (^)(RKObjectAttributeMapping *mapping, id value))testBlock
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath evaluationBlock:(BOOL (^)(RKAttributeMapping *mapping, id value))testBlock
|
||||
{
|
||||
RKMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
@@ -55,7 +55,7 @@
|
||||
return expectation;
|
||||
}
|
||||
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKObjectMappingDefinition *)mapping
|
||||
+ (RKMappingTestExpectation *)expectationWithSourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKMapping *)mapping
|
||||
{
|
||||
RKMappingTestExpectation *expectation = [self new];
|
||||
expectation.sourceKeyPath = sourceKeyPath;
|
||||
|
||||
Reference in New Issue
Block a user