mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-18 12:13:25 +08:00
Renamed RKObjectDynamicMapping to RKDynamicObjectMapping to better mesh with Cocoa idioms. fixes #354
The old class name has been aliased for backwards compatibility.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 7/28/11.
|
||||
// Copyright 2011 Two Toasters
|
||||
// Copyright 2011 RestKit
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@
|
||||
/**
|
||||
Return the appropriate object mapping given a mappable data
|
||||
*/
|
||||
@protocol RKObjectDynamicMappingDelegate <NSObject>
|
||||
@protocol RKDynamicObjectMappingDelegate <NSObject>
|
||||
|
||||
@required
|
||||
- (RKObjectMapping*)objectMappingForData:(id)data;
|
||||
@@ -32,7 +32,7 @@
|
||||
@end
|
||||
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
typedef RKObjectMapping*(^RKObjectDynamicMappingDelegateBlock)(id);
|
||||
typedef RKObjectMapping*(^RKDynamicObjectMappingDelegateBlock)(id);
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -40,11 +40,11 @@ typedef RKObjectMapping*(^RKObjectDynamicMappingDelegateBlock)(id);
|
||||
object mapping to apply at mapping time. This allows you to map very similar payloads
|
||||
differently depending on the type of data contained therein.
|
||||
*/
|
||||
@interface RKObjectDynamicMapping : NSObject <RKObjectMappingDefinition> {
|
||||
NSMutableArray* _matchers;
|
||||
id<RKObjectDynamicMappingDelegate> _delegate;
|
||||
@interface RKDynamicObjectMapping : NSObject <RKObjectMappingDefinition> {
|
||||
NSMutableArray *_matchers;
|
||||
id<RKDynamicObjectMappingDelegate> _delegate;
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
RKObjectDynamicMappingDelegateBlock _objectMappingForDataBlock;
|
||||
RKDynamicObjectMappingDelegateBlock _objectMappingForDataBlock;
|
||||
#endif
|
||||
BOOL _forceCollectionMapping;
|
||||
}
|
||||
@@ -55,14 +55,14 @@ typedef RKObjectMapping*(^RKObjectDynamicMappingDelegateBlock)(id);
|
||||
|
||||
@see RKDynamicObjectMappingDelegate
|
||||
*/
|
||||
@property (nonatomic, assign) id<RKObjectDynamicMappingDelegate> delegate;
|
||||
@property (nonatomic, assign) id<RKDynamicObjectMappingDelegate> delegate;
|
||||
|
||||
#ifdef NS_BLOCKS_AVAILABLE
|
||||
/**
|
||||
A block to invoke to determine the appropriate concrete object mapping
|
||||
to apply to the mappable data.
|
||||
*/
|
||||
@property (nonatomic, copy) RKObjectDynamicMappingDelegateBlock objectMappingForDataBlock;
|
||||
@property (nonatomic, copy) RKDynamicObjectMappingDelegateBlock objectMappingForDataBlock;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -75,14 +75,14 @@ typedef RKObjectMapping*(^RKObjectDynamicMappingDelegateBlock)(id);
|
||||
/**
|
||||
Return a new auto-released dynamic object mapping
|
||||
*/
|
||||
+ (RKObjectDynamicMapping*)dynamicMapping;
|
||||
+ (RKDynamicObjectMapping *)dynamicMapping;
|
||||
|
||||
#if NS_BLOCKS_AVAILABLE
|
||||
|
||||
/**
|
||||
Return a new auto-released dynamic object mapping after yielding it to the block for configuration
|
||||
*/
|
||||
+ (RKObjectDynamicMapping*)dynamicMappingWithBlock:(void(^)(RKObjectDynamicMapping*))block;
|
||||
+ (RKDynamicObjectMapping *)dynamicMappingWithBlock:(void(^)(RKDynamicObjectMapping *))block;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -94,16 +94,21 @@ typedef RKObjectMapping*(^RKObjectDynamicMappingDelegateBlock)(id);
|
||||
the gender of the person. When the gender is 'male', we want to use the Boy class and when then the gender
|
||||
is 'female' we want to use the Girl class. We might define our dynamic mapping like so:
|
||||
|
||||
RKObjectdynamicMapping* mapping = [RKObjectdynamicMapping dynamicMapping];
|
||||
RKDynamicObjectMapping* mapping = [RKDynamicObjectMapping dynamicMapping];
|
||||
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"male"];
|
||||
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"female"];
|
||||
*/
|
||||
- (void)setObjectMapping:(RKObjectMapping*)objectMapping whenValueOfKeyPath:(NSString*)keyPath isEqualTo:(id)value;
|
||||
- (void)setObjectMapping:(RKObjectMapping *)objectMapping whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)value;
|
||||
|
||||
/**
|
||||
Invoked by the RKObjectMapper and RKObjectMappingOperation to determine the appropriate RKObjectMapping to use
|
||||
when mapping the specified dictionary of mappable data.
|
||||
*/
|
||||
- (RKObjectMapping*)objectMappingForDictionary:(NSDictionary*)dictionary;
|
||||
- (RKObjectMapping *)objectMappingForDictionary:(NSDictionary *)dictionary;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
Define an alias for the old class name for compatibility
|
||||
*/
|
||||
@compatibility_alias RKObjectDynamicMapping RKDynamicObjectMapping;
|
||||
@@ -18,7 +18,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKObjectDynamicMapping.h"
|
||||
#import "RKDynamicObjectMapping.h"
|
||||
#import "../Support/RKLog.h"
|
||||
|
||||
// Set Logging Component
|
||||
@@ -28,7 +28,7 @@
|
||||
// Implemented in RKObjectMappingOperation
|
||||
BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
|
||||
@interface RKObjectDynamicMappingMatcher : NSObject {
|
||||
@interface RKDynamicObjectMappingMatcher : NSObject {
|
||||
NSString* _keyPath;
|
||||
id _value;
|
||||
RKObjectMapping* _objectMapping;
|
||||
@@ -41,7 +41,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
- (NSString*)matchDescription;
|
||||
@end
|
||||
|
||||
@implementation RKObjectDynamicMappingMatcher
|
||||
@implementation RKDynamicObjectMappingMatcher
|
||||
|
||||
@synthesize objectMapping = _objectMapping;
|
||||
|
||||
@@ -75,20 +75,20 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@implementation RKObjectDynamicMapping
|
||||
@implementation RKDynamicObjectMapping
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize objectMappingForDataBlock = _objectMappingForDataBlock;
|
||||
@synthesize forceCollectionMapping = _forceCollectionMapping;
|
||||
|
||||
+ (RKObjectDynamicMapping*)dynamicMapping {
|
||||
+ (RKDynamicObjectMapping*)dynamicMapping {
|
||||
return [[self new] autorelease];
|
||||
}
|
||||
|
||||
#if NS_BLOCKS_AVAILABLE
|
||||
|
||||
+ (RKObjectDynamicMapping*)dynamicMappingWithBlock:(void(^)(RKObjectDynamicMapping*))block {
|
||||
RKObjectDynamicMapping* mapping = [self dynamicMapping];
|
||||
+ (RKDynamicObjectMapping*)dynamicMappingWithBlock:(void(^)(RKDynamicObjectMapping*))block {
|
||||
RKDynamicObjectMapping* mapping = [self dynamicMapping];
|
||||
block(mapping);
|
||||
return mapping;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
|
||||
- (void)setObjectMapping:(RKObjectMapping*)objectMapping whenValueOfKeyPath:(NSString*)keyPath isEqualTo:(id)value {
|
||||
RKLogDebug(@"Adding dynamic object mapping for key '%@' with value '%@' to destination class: %@", keyPath, value, NSStringFromClass(objectMapping.objectClass));
|
||||
RKObjectDynamicMappingMatcher* matcher = [[RKObjectDynamicMappingMatcher alloc] initWithKey:keyPath value:value objectMapping:objectMapping];
|
||||
RKDynamicObjectMappingMatcher* matcher = [[RKDynamicObjectMappingMatcher alloc] initWithKey:keyPath value:value objectMapping:objectMapping];
|
||||
[_matchers addObject:matcher];
|
||||
[matcher release];
|
||||
}
|
||||
@@ -123,7 +123,7 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
|
||||
RKLogTrace(@"Performing dynamic object mapping for mappable data: %@", data);
|
||||
|
||||
// Consult the declarative matchers first
|
||||
for (RKObjectDynamicMappingMatcher* matcher in _matchers) {
|
||||
for (RKDynamicObjectMappingMatcher* matcher in _matchers) {
|
||||
if ([matcher isMatchForData:data]) {
|
||||
RKLogTrace(@"Found declarative match for data: %@.", [matcher matchDescription]);
|
||||
return matcher.objectMapping;
|
||||
@@ -118,8 +118,8 @@
|
||||
if (self.targetObject) {
|
||||
destinationObject = self.targetObject;
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKObjectDynamicMapping class]]) {
|
||||
objectMapping = [(RKObjectDynamicMapping*)mapping objectMappingForDictionary:mappableObject];
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:mappableObject];
|
||||
} else if ([mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
objectMapping = (RKObjectMapping*)mapping;
|
||||
} else {
|
||||
@@ -229,8 +229,8 @@
|
||||
- (id)objectWithMapping:(id<RKObjectMappingDefinition>)mapping andData:(id)mappableData {
|
||||
NSAssert([mapping conformsToProtocol:@protocol(RKObjectMappingDefinition)], @"Expected an object implementing RKObjectMappingDefinition");
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKObjectDynamicMapping class]]) {
|
||||
objectMapping = [(RKObjectDynamicMapping*)mapping objectMappingForDictionary:mappableData];
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:mappableData];
|
||||
if (! objectMapping) {
|
||||
RKLogDebug(@"Mapping %@ declined mapping for data %@: returned nil objectMapping", mapping, mappableData);
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
_sourceObject = [sourceObject retain];
|
||||
_destinationObject = [destinationObject retain];
|
||||
|
||||
if ([objectMapping isKindOfClass:[RKObjectDynamicMapping class]]) {
|
||||
_objectMapping = [[(RKObjectDynamicMapping*)objectMapping objectMappingForDictionary:_sourceObject] retain];
|
||||
if ([objectMapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
_objectMapping = [[(RKDynamicObjectMapping*)objectMapping objectMappingForDictionary:_sourceObject] retain];
|
||||
RKLogDebug(@"RKObjectMappingOperation was initialized with a dynamic mapping. Determined concrete mapping = %@", _objectMapping);
|
||||
} else if ([objectMapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
_objectMapping = (RKObjectMapping*)[objectMapping retain];
|
||||
@@ -408,8 +408,8 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
for (id nestedObject in value) {
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKObjectDynamicMapping class]]) {
|
||||
objectMapping = [(RKObjectDynamicMapping*)mapping objectMappingForDictionary:nestedObject];
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:nestedObject];
|
||||
if (! objectMapping) {
|
||||
RKLogDebug(@"Mapping %@ declined mapping for data %@: returned nil objectMapping", mapping, nestedObject);
|
||||
continue;
|
||||
@@ -456,8 +456,8 @@ BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue) {
|
||||
|
||||
id<RKObjectMappingDefinition> mapping = relationshipMapping.mapping;
|
||||
RKObjectMapping* objectMapping = nil;
|
||||
if ([mapping isKindOfClass:[RKObjectDynamicMapping class]]) {
|
||||
objectMapping = [(RKObjectDynamicMapping*)mapping objectMappingForDictionary:value];
|
||||
if ([mapping isKindOfClass:[RKDynamicObjectMapping class]]) {
|
||||
objectMapping = [(RKDynamicObjectMapping*)mapping objectMappingForDictionary:value];
|
||||
} else if ([mapping isKindOfClass:[RKObjectMapping class]]) {
|
||||
objectMapping = (RKObjectMapping*)mapping;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//
|
||||
|
||||
#import "RKObjectMapping.h"
|
||||
#import "RKObjectDynamicMapping.h"
|
||||
#import "RKDynamicObjectMapping.h"
|
||||
|
||||
/**
|
||||
Responsible for providing object mappings to an instance of the object mapper
|
||||
|
||||
Reference in New Issue
Block a user