mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
Update Dynamic Mapping API's to match the rest of the 0.20.x style. Introduce support for predicate based dynamic matching.
* Rename RKDynamicMappingMatcher to RKObjectMappingMatcher since it is not strictly coupled to dynamic mapping and works with object mappings. * Rework matchers into using a class cluster style to enable flexible subclassing to introduce additional matchers.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#import "RKEntityMapping.h"
|
||||
#import "RKManagedObjectStore.h"
|
||||
#import "RKDynamicMappingMatcher.h"
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
#import "RKPropertyInspector+CoreData.h"
|
||||
#import "RKLog.h"
|
||||
#import "RKRelationshipMapping.h"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#import "RKLog.h"
|
||||
#import "RKManagedObjectStore.h"
|
||||
#import "RKMappingOperation.h"
|
||||
#import "RKDynamicMappingMatcher.h"
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
#import "RKManagedObjectCaching.h"
|
||||
#import "RKRelationshipConnectionOperation.h"
|
||||
#import "RKMappingErrors.h"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#import "RKEntityMapping.h"
|
||||
#import "RKLog.h"
|
||||
#import "RKManagedObjectCaching.h"
|
||||
#import "RKDynamicMappingMatcher.h"
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
#import "RKErrors.h"
|
||||
#import "RKObjectUtilities.h"
|
||||
|
||||
|
||||
@@ -441,7 +441,7 @@ static NSString *RKMIMETypeFromAFHTTPClientParameterEncoding(AFHTTPClientParamet
|
||||
_blockSuccess = [[object managedObjectContext] obtainPermanentIDsForObjects:@[object] error:&_blockError];
|
||||
}];
|
||||
if (! _blockSuccess) RKLogWarning(@"Failed to obtain permanent ID for object %@: %@", object, _blockError);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Non-Core Data operation
|
||||
operation = [self objectRequestOperationWithRequest:request success:nil failure:nil];
|
||||
|
||||
@@ -19,40 +19,77 @@
|
||||
//
|
||||
|
||||
#import "RKMapping.h"
|
||||
#import "RKObjectMapping.h"
|
||||
|
||||
typedef RKObjectMapping *(^RKDynamicMappingDelegateBlock)(id representation);
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
|
||||
/**
|
||||
Defines a dynamic object mapping that determines the appropriate concrete object mapping to apply at mapping time. This allows you to map very similar payloads differently depending on the type of data contained therein.
|
||||
The `RKDynamicMapping` class is an `RKMapping` subclass that provides an interface for deferring the decision about how a given object representation is to be mapped until run time. This enables many interesting mapping strategies, such as mapping similarly structured data differently and constructing object mappings at run time by examining the data being mapped.
|
||||
|
||||
## Configuring Mapping Selection
|
||||
|
||||
Dynamic mappings support the selection of the concrete object mapping in one of two ways:
|
||||
|
||||
1. Through the use of a mapping selection block configured by `setObjectMappingForRepresentationBlock:`. When configured, the block is called with a reference to the current object representation being mapped and is expected to return an `RKObjectMapping` object. Returning `nil` declines the mapping of the representation.
|
||||
1. Through the configuration of one of more `RKObjectMappingMatcher` objects. The matchers are consulted in registration order and the first matcher to return an object mapping is used to map the matched representation.
|
||||
|
||||
When both a mapping selection block and matchers are configured on a `RKDynamicMapping` object, the matcher objects are consulted first and if none match, the selection block is invoked.
|
||||
|
||||
## Using Matcher Objects
|
||||
|
||||
The `RKObjectMappingMatcher` class provides an interface for evaluating a key path or predicate based match and returning an appropriate object mapping. Matchers can be added to the `RKDynamicMapping` objects to declaratively describe a particular mapping strategy.
|
||||
|
||||
For example, suppose that we have a JSON fragment for a person that we want to map differently based on 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. The JSON might look something like this:
|
||||
|
||||
[ { "name": "Blake", "gender": "male" }, { "name": "Sarah", "gender": "female" } ]
|
||||
|
||||
We might define configure the dynamic mapping like so:
|
||||
|
||||
RKDynamicMapping *mapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[mapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"gender" expectedValue:@"male" objectMapping:boyMapping]];
|
||||
[mapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"gender" expectedValue:@"female" objectMapping:girlMapping]];
|
||||
|
||||
When evaluated, the matchers will invoke `valueForKeyPath:@"gender"` against each dictionary in the array of object representations and apply the appropriate object mapping for each representation. This would return a mapping result containing an array of two objects, one an instance of the `Boy` class and the other an instance of the `Girl` class.
|
||||
|
||||
## HTTP Integration
|
||||
|
||||
Dynamic mappings can be used to map HTTP requests and responses by adding them to an `RKRequestDescriptor` or `RKResponseDescriptor` objects.
|
||||
*/
|
||||
@interface RKDynamicMapping : RKMapping
|
||||
|
||||
///------------------------------------
|
||||
/// @name Configuring Mapping Selection
|
||||
///------------------------------------
|
||||
///------------------------------------------
|
||||
/// @name Configuring Block Mapping Selection
|
||||
///------------------------------------------
|
||||
|
||||
/**
|
||||
Sets a block to be invoked to determine the appropriate concrete object mapping with which to map an object representation.
|
||||
|
||||
@param block The block object to invoke to select the object mapping with which to map the given object representation.
|
||||
@param block The block object to invoke to select the object mapping with which to map the given object representation. The block returns an object mapping and accepts a single parameter: the object representation being mapped.
|
||||
*/
|
||||
- (void)setObjectMappingForRepresentationBlock:(RKDynamicMappingDelegateBlock)block;
|
||||
- (void)setObjectMappingForRepresentationBlock:(RKObjectMapping *(^)(id representation))block;
|
||||
|
||||
/**
|
||||
Defines a dynamic mapping rule stating that when the value of the key property matches the specified value, the given mapping should be used to map the representation.
|
||||
|
||||
For example, suppose that we have a JSON fragment for a person that we want to map differently based on 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:
|
||||
|
||||
RKDynamicMapping *mapping = [RKDynamicMapping new];
|
||||
[mapping setObjectMapping:boyMapping whenValueOfKeyPath:@"gender" isEqualTo:@"male"];
|
||||
[mapping setObjectMapping:girlMapping whenValueOfKeyPath:@"gender" isEqualTo:@"female"];
|
||||
|
||||
@param objectMapping The mapping to be used when the value at the given key path is equal to the given value.
|
||||
@param keyPath The key path to retrieve the comparison value from in the object representation being mapped.
|
||||
@param value The value to be compared with the value at `keyPath`. If they are equal, the `objectMapping` will be used to map the representation.
|
||||
Returns the array of matchers objects added to the receiver.
|
||||
*/
|
||||
- (void)setObjectMapping:(RKObjectMapping *)objectMapping whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)value;
|
||||
@property (nonatomic, strong, readonly) NSArray *matchers;
|
||||
|
||||
/**
|
||||
Adds a matcher to the receiver.
|
||||
|
||||
If the matcher has already been added to the receiver, then adding it again moves it to the top of the matcher stack.
|
||||
|
||||
@param matcher The matcher to add to the receiver.
|
||||
*/
|
||||
- (void)addMatcher:(RKObjectMappingMatcher *)matcher;
|
||||
|
||||
/**
|
||||
Removes a matcher from the receiver.
|
||||
|
||||
If the matcher has already been added to the receiver, then adding it again moves it to the top of the matcher stack.
|
||||
|
||||
@param matcher The matcher to remove from the receiver.
|
||||
*/
|
||||
- (void)removeMatcher:(RKObjectMappingMatcher *)matcher;
|
||||
|
||||
/**
|
||||
Returns an array of object mappings that have been registered with the receiver.
|
||||
@@ -68,6 +105,8 @@ typedef RKObjectMapping *(^RKDynamicMappingDelegateBlock)(id representation);
|
||||
/**
|
||||
Invoked by the `RKMapperOperation` and `RKMappingOperation` to determine the appropriate `RKObjectMapping` to use when mapping the given object representation.
|
||||
|
||||
This method searches the stack of registered matchers and then executes the block, if any, set by `setObjectMappingForRepresentationBlock:`. If `nil` is returned, then mapping for the representation is declined and it will not be mapped.
|
||||
|
||||
@param representation The object representation that being mapped dynamically for which to determine the appropriate concrete mapping.
|
||||
@return The object mapping to be used to map the given object representation.
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
//
|
||||
|
||||
#import "RKDynamicMapping.h"
|
||||
#import "RKDynamicMappingMatcher.h"
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
#import "RKLog.h"
|
||||
|
||||
// Set Logging Component
|
||||
@@ -27,8 +27,8 @@
|
||||
#define RKLogComponent RKlcl_cRestKitObjectMapping
|
||||
|
||||
@interface RKDynamicMapping ()
|
||||
@property (nonatomic, strong) NSMutableArray *matchers;
|
||||
@property (nonatomic, copy) RKDynamicMappingDelegateBlock objectMappingForRepresentationBlock;
|
||||
@property (nonatomic, strong) NSMutableArray *mutableMatchers;
|
||||
@property (nonatomic, copy) RKObjectMapping *(^objectMappingForRepresentationBlock)(id representation);
|
||||
@end
|
||||
|
||||
@implementation RKDynamicMapping
|
||||
@@ -37,22 +37,37 @@
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.matchers = [NSMutableArray new];
|
||||
self.mutableMatchers = [NSMutableArray new];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray *)objectMappings
|
||||
- (NSArray *)matchers
|
||||
{
|
||||
return [self.matchers valueForKey:@"objectMapping"];
|
||||
return [self.mutableMatchers copy];
|
||||
}
|
||||
|
||||
- (void)setObjectMapping:(RKObjectMapping *)objectMapping whenValueOfKeyPath:(NSString *)keyPath isEqualTo:(id)expectedValue
|
||||
- (NSArray *)objectMappings
|
||||
{
|
||||
RKLogDebug(@"Adding dynamic object mapping for key '%@' with value '%@' to destination class: %@", keyPath, expectedValue, NSStringFromClass(objectMapping.objectClass));
|
||||
RKDynamicMappingMatcher *matcher = [[RKDynamicMappingMatcher alloc] initWithKeyPath:keyPath expectedValue:expectedValue objectMapping:objectMapping];
|
||||
[_matchers addObject:matcher];
|
||||
return [self.mutableMatchers valueForKey:@"objectMapping"];
|
||||
}
|
||||
|
||||
- (void)addMatcher:(RKObjectMappingMatcher *)matcher
|
||||
{
|
||||
NSParameterAssert(matcher);
|
||||
if ([self.mutableMatchers containsObject:matcher]) {
|
||||
[self.mutableMatchers removeObject:matcher];
|
||||
[self.mutableMatchers insertObject:matcher atIndex:0];
|
||||
} else {
|
||||
[self.mutableMatchers addObject:matcher];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeMatcher:(RKObjectMappingMatcher *)matcher
|
||||
{
|
||||
NSParameterAssert(matcher);
|
||||
[self.mutableMatchers removeObject:matcher];
|
||||
}
|
||||
|
||||
- (RKObjectMapping *)objectMappingForRepresentation:(id)representation
|
||||
@@ -62,7 +77,7 @@
|
||||
RKLogTrace(@"Performing dynamic object mapping for object representation: %@", representation);
|
||||
|
||||
// Consult the declarative matchers first
|
||||
for (RKDynamicMappingMatcher *matcher in _matchers) {
|
||||
for (RKObjectMappingMatcher *matcher in self.mutableMatchers) {
|
||||
if ([matcher matches:representation]) {
|
||||
RKLogTrace(@"Found declarative match for matcher: %@.", matcher);
|
||||
return matcher.objectMapping;
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
//
|
||||
// RKDynamicMappingMatcher.h
|
||||
// RestKit
|
||||
//
|
||||
// Created by Jeff Arena on 8/2/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "RKObjectMapping.h"
|
||||
|
||||
/**
|
||||
The `RKDynamicMappingMatcher` class provides an interface for encapsulating the selection of an object mapping based on the runtime value of a property at a given key path. A matcher object is initialized with a key path, an expected value to be read from the key path, and an object mapping that is to be applied if the match evaluates to `YES`. When evaluating the match, the matcher invokes `valueForKeyPath:` on the object being matched and compares the value returned with the `expectedValue` via the `RKObjectIsEqualToObject` function.
|
||||
|
||||
@see `RKObjectIsEqualToObject()`
|
||||
*/
|
||||
// TODO: better name? RKKeyPathMappingMatcher | RKMappingMatcher | RKKeyPathMatcher | RKMatcher | RKValueMatcher | RKPropertyMatcher
|
||||
@interface RKDynamicMappingMatcher : NSObject
|
||||
|
||||
///-----------------------------
|
||||
/// @name Initializing a Matcher
|
||||
///-----------------------------
|
||||
|
||||
/**
|
||||
Initializes the receiver with a given key path, expected value, and an object mapping that applies in the event of a positive match.
|
||||
|
||||
@param keyPath The key path to obtain the comparison value from the object being matched via `valueForKeyPath:`.
|
||||
@param expectedValue The value that is expected to be read from `keyPath` if there is a match.
|
||||
@param objectMapping The object mapping object that applies if the comparison value is equal to the expected value.
|
||||
@return The receiver, initialized with the given key path, expected value, and object mapping.
|
||||
*/
|
||||
- (id)initWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping;
|
||||
|
||||
///-----------------------------
|
||||
/// @name Initializing a Matcher
|
||||
///-----------------------------
|
||||
|
||||
/**
|
||||
The key path to obtain the comparison value from the object being matched via `valueForKeyPath:`.
|
||||
*/
|
||||
@property (nonatomic, copy, readonly) NSString *keyPath;
|
||||
|
||||
/**
|
||||
The value that is expected to be read from `keyPath` if there is a match.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) id expectedValue;
|
||||
|
||||
/**
|
||||
The object mapping object that applies if the comparison value read from `keyPath` is equal to the `expectedValue`.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) RKObjectMapping *objectMapping;
|
||||
|
||||
///-------------------------
|
||||
/// @name Evaluating a Match
|
||||
///-------------------------
|
||||
|
||||
/**
|
||||
Returns a Boolean value that indicates if the given object matches the expectations of the receiver.
|
||||
|
||||
The match is evaluated by invoking `valueForKeyPath:` on the give object with the value of the `keyPath` property and comparing the returned value with the `expectedValue` using the `RKObjectIsEqualToObject` function.
|
||||
|
||||
@param object The object to be evaluated.
|
||||
@return `YES` if the object matches the expectations of the receiver, else `NO`.
|
||||
*/
|
||||
- (BOOL)matches:(id)object;
|
||||
|
||||
@end
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// RKDynamicMappingMatcher.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Jeff Arena on 8/2/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKDynamicMappingMatcher.h"
|
||||
#import "RKObjectUtilities.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@interface RKDynamicMappingMatcher ()
|
||||
@property (nonatomic, copy) NSString *keyPath;
|
||||
@property (nonatomic, strong, readwrite) id expectedValue;
|
||||
@property (nonatomic, strong, readwrite) RKObjectMapping *objectMapping;
|
||||
@end
|
||||
|
||||
@implementation RKDynamicMappingMatcher
|
||||
|
||||
- (id)initWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
NSParameterAssert(keyPath);
|
||||
NSParameterAssert(expectedValue);
|
||||
NSParameterAssert(objectMapping);
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.keyPath = keyPath;
|
||||
self.expectedValue = expectedValue;
|
||||
self.objectMapping = objectMapping;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)object
|
||||
{
|
||||
id value = [object valueForKeyPath:self.keyPath];
|
||||
if (value == nil) return NO;
|
||||
return RKObjectIsEqualToObject(value, self.expectedValue);
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@: %p when `%@` == '%@' objectMapping: %@>", NSStringFromClass([self class]), self, self.keyPath, self.expectedValue, self.objectMapping];
|
||||
}
|
||||
|
||||
@end
|
||||
75
Code/ObjectMapping/RKObjectMappingMatcher.h
Normal file
75
Code/ObjectMapping/RKObjectMappingMatcher.h
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// RKDynamicMappingMatcher.h
|
||||
// RestKit
|
||||
//
|
||||
// Created by Jeff Arena on 8/2/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "RKObjectMapping.h"
|
||||
|
||||
/**
|
||||
The `RKObjectMappingMatcher` class provides an interface for encapsulating the selection of an object mapping based on runtime values. Matcher objects may be configured by key path and expected value or with a predicate object.
|
||||
|
||||
## Key Path Matching
|
||||
|
||||
A key path matcher object is initialized with a key path, an expected value to be read from the key path, and an object mapping that is to be applied if the match evaluates to `YES`. When evaluating the match, the matcher invokes `valueForKeyPath:` on the object being matched and compares the value returned with the `expectedValue` via the `RKObjectIsEqualToObject` function. This provides a flexible, semantic match of the property value.
|
||||
|
||||
## Predicate Matching
|
||||
|
||||
A predicate matcher object is initialized with a predicate object and an object mapping that is to be applied if the predicate evaluates to `YES` for the object being matched.
|
||||
*/
|
||||
@interface RKObjectMappingMatcher : NSObject
|
||||
|
||||
///-------------------------------------
|
||||
/// @name Constructing Key Path Matchers
|
||||
///-------------------------------------
|
||||
|
||||
/**
|
||||
Creates and returns a key path matcher object with a given key path, expected value, and an object mapping that applies in the event of a positive match.
|
||||
|
||||
@param keyPath The key path to obtain the comparison value from the object being matched via `valueForKeyPath:`.
|
||||
@param expectedValue The value that is expected to be read from `keyPath` if there is a match.
|
||||
@param objectMapping The object mapping object that applies if the comparison value is equal to the expected value.
|
||||
@return The receiver, initialized with the given key path, expected value, and object mapping.
|
||||
*/
|
||||
+ (instancetype)matcherWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping;
|
||||
|
||||
///--------------------------------------
|
||||
/// @name Constructing Predicate Matchers
|
||||
///--------------------------------------
|
||||
|
||||
/**
|
||||
Creates and returns a predicate matcher object with a given predicate and an object mapping that applies in the predicate evaluates positively.
|
||||
|
||||
@param predicate The predicate with which to evaluate the matched object.
|
||||
@param objectMapping The object mapping object that applies if the predicate evaluates positively for the matched object.
|
||||
@return The receiver, initialized with the given key path, expected value, and object mapping.
|
||||
*/
|
||||
+ (instancetype)matcherWithPredicate:(NSPredicate *)predicate objectMapping:(RKObjectMapping *)objectMapping;
|
||||
|
||||
///-----------------------------------
|
||||
/// @name Accessing the Object Mapping
|
||||
///-----------------------------------
|
||||
|
||||
/**
|
||||
The object mapping object that applies when the receiver matches a given object.
|
||||
|
||||
@see `matches:`
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) RKObjectMapping *objectMapping;
|
||||
|
||||
///-------------------------
|
||||
/// @name Evaluating a Match
|
||||
///-------------------------
|
||||
|
||||
/**
|
||||
Returns a Boolean value that indicates if the given object matches the expectations of the receiver.
|
||||
|
||||
@param object The object to be evaluated.
|
||||
@return `YES` if the object matches the expectations of the receiver, else `NO`.
|
||||
*/
|
||||
- (BOOL)matches:(id)object;
|
||||
|
||||
@end
|
||||
123
Code/ObjectMapping/RKObjectMappingMatcher.m
Normal file
123
Code/ObjectMapping/RKObjectMappingMatcher.m
Normal file
@@ -0,0 +1,123 @@
|
||||
//
|
||||
// RKDynamicMappingMatcher.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Jeff Arena on 8/2/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
|
||||
#import "RKObjectMappingMatcher.h"
|
||||
#import "RKObjectUtilities.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@interface RKObjectMappingMatcher ()
|
||||
@property (nonatomic, strong, readwrite) RKObjectMapping *objectMapping;
|
||||
@end
|
||||
|
||||
@interface RKKeyPathObjectMappingMatcher : RKObjectMappingMatcher
|
||||
@property (nonatomic, copy) NSString *keyPath;
|
||||
@property (nonatomic, strong, readwrite) id expectedValue;
|
||||
|
||||
- (id)initWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping;
|
||||
@end
|
||||
|
||||
@interface RKPredicateObjectMappingMatcher : RKObjectMappingMatcher
|
||||
@property (nonatomic, strong) NSPredicate *predicate;
|
||||
|
||||
- (id)initWithPredicate:(NSPredicate *)predicate objectMapping:(RKObjectMapping *)objectMapping;
|
||||
@end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@implementation RKObjectMappingMatcher
|
||||
|
||||
+ (instancetype)matcherWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
return [[RKKeyPathObjectMappingMatcher alloc] initWithKeyPath:keyPath expectedValue:expectedValue objectMapping:objectMapping];
|
||||
}
|
||||
|
||||
+ (instancetype)matcherWithPredicate:(NSPredicate *)predicate objectMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
return [[RKPredicateObjectMappingMatcher alloc] initWithPredicate:predicate objectMapping:objectMapping];
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
if ([self isMemberOfClass:[RKObjectMappingMatcher class]]) {
|
||||
@throw [NSException exceptionWithName:NSInternalInconsistencyException
|
||||
reason:[NSString stringWithFormat:@"%@ is not meant to be directly instantiated. Use one of the initializer methods instead.",
|
||||
NSStringFromClass([self class])]
|
||||
userInfo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)object
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKKeyPathObjectMappingMatcher
|
||||
|
||||
- (id)initWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
NSParameterAssert(keyPath);
|
||||
NSParameterAssert(expectedValue);
|
||||
NSParameterAssert(objectMapping);
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.keyPath = keyPath;
|
||||
self.expectedValue = expectedValue;
|
||||
self.objectMapping = objectMapping;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)object
|
||||
{
|
||||
id value = [object valueForKeyPath:self.keyPath];
|
||||
if (value == nil) return NO;
|
||||
return RKObjectIsEqualToObject(value, self.expectedValue);
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@: %p when `%@` == '%@' objectMapping: %@>", NSStringFromClass([self class]), self, self.keyPath, self.expectedValue, self.objectMapping];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKPredicateObjectMappingMatcher
|
||||
|
||||
- (id)initWithPredicate:(NSPredicate *)predicate objectMapping:(RKObjectMapping *)objectMapping
|
||||
{
|
||||
NSParameterAssert(predicate);
|
||||
NSParameterAssert(objectMapping);
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.predicate = predicate;
|
||||
self.objectMapping = objectMapping;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)matches:(id)object
|
||||
{
|
||||
return [self.predicate evaluateWithObject:object];
|
||||
}
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@: %p when '%@' objectMapping: %@>", NSStringFromClass([self class]), self, self.predicate, self.objectMapping];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -254,8 +254,8 @@
|
||||
251610B71456F2330060A5C5 /* RKParent.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610081456F2330060A5C5 /* RKParent.m */; };
|
||||
251610B81456F2330060A5C5 /* RKResident.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516100A1456F2330060A5C5 /* RKResident.m */; };
|
||||
251610B91456F2330060A5C5 /* RKResident.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516100A1456F2330060A5C5 /* RKResident.m */; };
|
||||
251610D21456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */; };
|
||||
251610D31456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */; };
|
||||
251610D21456F2330060A5C5 /* RKDynamicMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicMappingTest.m */; };
|
||||
251610D31456F2330060A5C5 /* RKDynamicMappingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 2516101C1456F2330060A5C5 /* RKDynamicMappingTest.m */; };
|
||||
251610DC1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610211456F2330060A5C5 /* RKObjectMappingNextGenTest.m */; };
|
||||
251610DD1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610211456F2330060A5C5 /* RKObjectMappingNextGenTest.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
|
||||
251610DE1456F2330060A5C5 /* RKMappingOperationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610221456F2330060A5C5 /* RKMappingOperationTest.m */; };
|
||||
@@ -388,6 +388,8 @@
|
||||
257ABAB71511371E00CCAA76 /* NSManagedObject+RKAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 257ABAB41511371C00CCAA76 /* NSManagedObject+RKAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
257ABAB81511371E00CCAA76 /* NSManagedObject+RKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 257ABAB51511371D00CCAA76 /* NSManagedObject+RKAdditions.m */; };
|
||||
257ABAB91511371E00CCAA76 /* NSManagedObject+RKAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 257ABAB51511371D00CCAA76 /* NSManagedObject+RKAdditions.m */; };
|
||||
258BEA02168D058300C74C8C /* RKObjectMappingMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 258BEA01168D058300C74C8C /* RKObjectMappingMatcher.m */; };
|
||||
258BEA03168D058300C74C8C /* RKObjectMappingMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 258BEA01168D058300C74C8C /* RKObjectMappingMatcher.m */; };
|
||||
258EA4A815A38BC0007E07A6 /* RKObjectMappingOperationDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 258EA4A615A38BBF007E07A6 /* RKObjectMappingOperationDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
258EA4A915A38BC0007E07A6 /* RKObjectMappingOperationDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 258EA4A615A38BBF007E07A6 /* RKObjectMappingOperationDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
258EA4AA15A38BC0007E07A6 /* RKObjectMappingOperationDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 258EA4A715A38BBF007E07A6 /* RKObjectMappingOperationDataSource.m */; };
|
||||
@@ -499,10 +501,8 @@
|
||||
25B6E95614CF795D00B1E881 /* RKErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 25B6E95414CF795D00B1E881 /* RKErrors.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
25B6E95814CF7A1C00B1E881 /* RKErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E95714CF7A1C00B1E881 /* RKErrors.m */; };
|
||||
25B6E95914CF7A1C00B1E881 /* RKErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E95714CF7A1C00B1E881 /* RKErrors.m */; };
|
||||
25B6E95C14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 25B6E95A14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
25B6E95D14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 25B6E95A14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
25B6E95E14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E95B14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m */; };
|
||||
25B6E95F14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E95B14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m */; };
|
||||
25B6E95C14CF7E3C00B1E881 /* RKObjectMappingMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 25B6E95A14CF7E3C00B1E881 /* RKObjectMappingMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
25B6E95D14CF7E3C00B1E881 /* RKObjectMappingMatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 25B6E95A14CF7E3C00B1E881 /* RKObjectMappingMatcher.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
25B6E9DB14CF912500B1E881 /* RKSearchable.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E9D614CF912500B1E881 /* RKSearchable.m */; };
|
||||
25B6E9DC14CF912500B1E881 /* RKSearchable.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E9D614CF912500B1E881 /* RKSearchable.m */; };
|
||||
25B6E9DD14CF912500B1E881 /* RKTestAddress.m in Sources */ = {isa = PBXBuildFile; fileRef = 25B6E9D814CF912500B1E881 /* RKTestAddress.m */; };
|
||||
@@ -760,7 +760,7 @@
|
||||
251610081456F2330060A5C5 /* RKParent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKParent.m; sourceTree = "<group>"; };
|
||||
251610091456F2330060A5C5 /* RKResident.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKResident.h; sourceTree = "<group>"; };
|
||||
2516100A1456F2330060A5C5 /* RKResident.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKResident.m; sourceTree = "<group>"; };
|
||||
2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDynamicObjectMappingTest.m; sourceTree = "<group>"; };
|
||||
2516101C1456F2330060A5C5 /* RKDynamicMappingTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDynamicMappingTest.m; sourceTree = "<group>"; };
|
||||
2516101F1456F2330060A5C5 /* RKObjectManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectManagerTest.m; sourceTree = "<group>"; };
|
||||
251610211456F2330060A5C5 /* RKObjectMappingNextGenTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = RKObjectMappingNextGenTest.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||
251610221456F2330060A5C5 /* RKMappingOperationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = RKMappingOperationTest.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||
@@ -838,6 +838,7 @@
|
||||
257ABAAF15112DD400CCAA76 /* NSManagedObjectContext+RKAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObjectContext+RKAdditions.m"; sourceTree = "<group>"; };
|
||||
257ABAB41511371C00CCAA76 /* NSManagedObject+RKAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+RKAdditions.h"; sourceTree = "<group>"; };
|
||||
257ABAB51511371D00CCAA76 /* NSManagedObject+RKAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+RKAdditions.m"; sourceTree = "<group>"; };
|
||||
258BEA01168D058300C74C8C /* RKObjectMappingMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingMatcher.m; sourceTree = "<group>"; };
|
||||
258EA4A615A38BBF007E07A6 /* RKObjectMappingOperationDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKObjectMappingOperationDataSource.h; sourceTree = "<group>"; };
|
||||
258EA4A715A38BBF007E07A6 /* RKObjectMappingOperationDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKObjectMappingOperationDataSource.m; sourceTree = "<group>"; };
|
||||
258EA4AD15A38E7D007E07A6 /* RKMappingOperationDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKMappingOperationDataSource.h; sourceTree = "<group>"; };
|
||||
@@ -894,8 +895,7 @@
|
||||
25B408251491CDDB00F21111 /* RKPathUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKPathUtilities.m; sourceTree = "<group>"; };
|
||||
25B6E95414CF795D00B1E881 /* RKErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKErrors.h; sourceTree = "<group>"; };
|
||||
25B6E95714CF7A1C00B1E881 /* RKErrors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKErrors.m; sourceTree = "<group>"; };
|
||||
25B6E95A14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKDynamicMappingMatcher.h; sourceTree = "<group>"; };
|
||||
25B6E95B14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKDynamicMappingMatcher.m; sourceTree = "<group>"; };
|
||||
25B6E95A14CF7E3C00B1E881 /* RKObjectMappingMatcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKObjectMappingMatcher.h; sourceTree = "<group>"; };
|
||||
25B6E9D514CF912500B1E881 /* RKSearchable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKSearchable.h; sourceTree = "<group>"; };
|
||||
25B6E9D614CF912500B1E881 /* RKSearchable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RKSearchable.m; sourceTree = "<group>"; };
|
||||
25B6E9D714CF912500B1E881 /* RKTestAddress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RKTestAddress.h; sourceTree = "<group>"; };
|
||||
@@ -1151,8 +1151,8 @@
|
||||
25160D7A145650490060A5C5 /* ObjectMapping */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
25B6E95A14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h */,
|
||||
25B6E95B14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m */,
|
||||
258BEA01168D058300C74C8C /* RKObjectMappingMatcher.m */,
|
||||
25B6E95A14CF7E3C00B1E881 /* RKObjectMappingMatcher.h */,
|
||||
25160D7C145650490060A5C5 /* RKDynamicMapping.h */,
|
||||
25160D7D145650490060A5C5 /* RKDynamicMapping.m */,
|
||||
25160D7E145650490060A5C5 /* RKErrorMessage.h */,
|
||||
@@ -1466,7 +1466,7 @@
|
||||
2516101B1456F2330060A5C5 /* ObjectMapping */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2516101C1456F2330060A5C5 /* RKDynamicObjectMappingTest.m */,
|
||||
2516101C1456F2330060A5C5 /* RKDynamicMappingTest.m */,
|
||||
2516101F1456F2330060A5C5 /* RKObjectManagerTest.m */,
|
||||
251610211456F2330060A5C5 /* RKObjectMappingNextGenTest.m */,
|
||||
251610221456F2330060A5C5 /* RKMappingOperationTest.m */,
|
||||
@@ -1723,7 +1723,7 @@
|
||||
25160E2E145650490060A5C5 /* RestKit.h in Headers */,
|
||||
25B408261491CDDC00F21111 /* RKPathUtilities.h in Headers */,
|
||||
25B6E95514CF795D00B1E881 /* RKErrors.h in Headers */,
|
||||
25B6E95C14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h in Headers */,
|
||||
25B6E95C14CF7E3C00B1E881 /* RKObjectMappingMatcher.h in Headers */,
|
||||
253B495214E35D1A00B0483F /* RKTestFixture.h in Headers */,
|
||||
25FABED214E3796B00E609E7 /* RKTestNotificationObserver.h in Headers */,
|
||||
25055B8414EEF32A00B9C4DD /* RKMappingTest.h in Headers */,
|
||||
@@ -1826,7 +1826,7 @@
|
||||
25160F25145655AF0060A5C5 /* RestKit.h in Headers */,
|
||||
25B408271491CDDC00F21111 /* RKPathUtilities.h in Headers */,
|
||||
25B6E95614CF795D00B1E881 /* RKErrors.h in Headers */,
|
||||
25B6E95D14CF7E3C00B1E881 /* RKDynamicMappingMatcher.h in Headers */,
|
||||
25B6E95D14CF7E3C00B1E881 /* RKObjectMappingMatcher.h in Headers */,
|
||||
25FABED314E3796C00E609E7 /* RKTestNotificationObserver.h in Headers */,
|
||||
25055B8514EEF32A00B9C4DD /* RKMappingTest.h in Headers */,
|
||||
25055B8914EEF32A00B9C4DD /* RKTestFactory.h in Headers */,
|
||||
@@ -2238,7 +2238,6 @@
|
||||
25160F0A1456532C0060A5C5 /* SOCKit.m in Sources */,
|
||||
25B408281491CDDC00F21111 /* RKPathUtilities.m in Sources */,
|
||||
25B6E95814CF7A1C00B1E881 /* RKErrors.m in Sources */,
|
||||
25B6E95E14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m in Sources */,
|
||||
25FABED114E3796400E609E7 /* RKTestNotificationObserver.m in Sources */,
|
||||
25CA7A8F14EC570200888FF8 /* RKMapping.m in Sources */,
|
||||
25055B8614EEF32A00B9C4DD /* RKMappingTest.m in Sources */,
|
||||
@@ -2294,6 +2293,7 @@
|
||||
25E88C8A165C5CC30042ABD0 /* RKConnectionDescription.m in Sources */,
|
||||
25019497166406E30081D68A /* RKValueTransformers.m in Sources */,
|
||||
25A8C2361673BD480014D9A6 /* RKConnectionTestExpectation.m in Sources */,
|
||||
258BEA02168D058300C74C8C /* RKObjectMappingMatcher.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -2314,7 +2314,7 @@
|
||||
251610B41456F2330060A5C5 /* RKObjectMapperTestModel.m in Sources */,
|
||||
251610B61456F2330060A5C5 /* RKParent.m in Sources */,
|
||||
251610B81456F2330060A5C5 /* RKResident.m in Sources */,
|
||||
251610D21456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */,
|
||||
251610D21456F2330060A5C5 /* RKDynamicMappingTest.m in Sources */,
|
||||
251610DC1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */,
|
||||
251610DE1456F2330060A5C5 /* RKMappingOperationTest.m in Sources */,
|
||||
251610E21456F2330060A5C5 /* RKMappingResultTest.m in Sources */,
|
||||
@@ -2387,7 +2387,6 @@
|
||||
25160F991456576C0060A5C5 /* RKPathMatcher.m in Sources */,
|
||||
25B408291491CDDC00F21111 /* RKPathUtilities.m in Sources */,
|
||||
25B6E95914CF7A1C00B1E881 /* RKErrors.m in Sources */,
|
||||
25B6E95F14CF7E3C00B1E881 /* RKDynamicMappingMatcher.m in Sources */,
|
||||
25FABED014E3796400E609E7 /* RKTestNotificationObserver.m in Sources */,
|
||||
25CA7A9014EC570200888FF8 /* RKMapping.m in Sources */,
|
||||
25CA7A9114EC5C2D00888FF8 /* RKTestFixture.m in Sources */,
|
||||
@@ -2444,6 +2443,7 @@
|
||||
25E88C8B165C5CC30042ABD0 /* RKConnectionDescription.m in Sources */,
|
||||
25019498166406E30081D68A /* RKValueTransformers.m in Sources */,
|
||||
25A8C2371673BD480014D9A6 /* RKConnectionTestExpectation.m in Sources */,
|
||||
258BEA03168D058300C74C8C /* RKObjectMappingMatcher.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -2464,7 +2464,7 @@
|
||||
251610B51456F2330060A5C5 /* RKObjectMapperTestModel.m in Sources */,
|
||||
251610B71456F2330060A5C5 /* RKParent.m in Sources */,
|
||||
251610B91456F2330060A5C5 /* RKResident.m in Sources */,
|
||||
251610D31456F2330060A5C5 /* RKDynamicObjectMappingTest.m in Sources */,
|
||||
251610D31456F2330060A5C5 /* RKDynamicMappingTest.m in Sources */,
|
||||
251610DD1456F2330060A5C5 /* RKObjectMappingNextGenTest.m in Sources */,
|
||||
251610DF1456F2330060A5C5 /* RKMappingOperationTest.m in Sources */,
|
||||
251610E31456F2330060A5C5 /* RKMappingResultTest.m in Sources */,
|
||||
|
||||
@@ -96,8 +96,8 @@
|
||||
parentMapping.identificationAttributes = @[ @"railsID" ];
|
||||
[parentMapping addAttributeMappingsFromArray:@[@"name", @"age"]];
|
||||
|
||||
[dynamicMapping setObjectMapping:parentMapping whenValueOfKeyPath:@"type" isEqualTo:@"Parent"];
|
||||
[dynamicMapping setObjectMapping:childMapping whenValueOfKeyPath:@"type" isEqualTo:@"Child"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Parent" objectMapping:parentMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Child" objectMapping:childMapping]];
|
||||
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"parent.json"]];
|
||||
expect(mapping).notTo.beNil();
|
||||
|
||||
@@ -300,7 +300,7 @@ NSSet *RKSetByRemovingSubkeypathsFromSet(NSSet *setOfKeyPaths);
|
||||
[entityMapping addAttributeMappingsFromArray:@[ @"name" ]];
|
||||
[userMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"favorite_cat" toKeyPath:@"friends" withMapping:entityMapping]];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:userMapping whenValueOfKeyPath:@"name" isEqualTo:@"Blake Watters"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"name" expectedValue:@"Blake Watters" objectMapping:userMapping]];
|
||||
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:nil keyPath:@"human" statusCodes:[NSIndexSet indexSetWithIndex:200]];
|
||||
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/JSON/humans/with_to_one_relationship.json" relativeToURL:[RKTestFactory baseURL]]];
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
{
|
||||
RKObjectMapping *invalidMapping = [RKObjectMapping mappingForClass:[RKRequestDescriptorTest class]];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:invalidMapping whenValueOfKeyPath:@"whatever" isEqualTo:@"whatever"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"whatever" expectedValue:@"whatever" objectMapping:invalidMapping]];
|
||||
|
||||
NSException *exception = nil;
|
||||
@try {
|
||||
|
||||
146
Tests/Logic/ObjectMapping/RKDynamicMappingTest.m
Normal file
146
Tests/Logic/ObjectMapping/RKDynamicMappingTest.m
Normal file
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// RKDynamicMappingTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 7/28/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKDynamicMapping.h"
|
||||
#import "RKDynamicMappingModels.h"
|
||||
|
||||
@interface RKDynamicMappingTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKDynamicMappingTest
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnAnAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Girl" objectMapping:girlMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Boy" objectMapping:boyMapping]];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testShouldMatchOnAnNSNumberAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"numeric_type" expectedValue:@(0) objectMapping:girlMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"numeric_type" expectedValue:@(1) objectMapping:boyMapping]];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testMappingSelectionUsingPredicateMatchers
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 0"] objectMapping:girlMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 1"] objectMapping:boyMapping]];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testThatRegistrationOfMatcherASecondTimeMovesToTopOfTheStack
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMappingMatcher *girlMatcher = [RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 0"] objectMapping:girlMapping];
|
||||
RKObjectMappingMatcher *boyMatcher = [RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 0"] objectMapping:boyMapping];
|
||||
[dynamicMapping addMatcher:girlMatcher];
|
||||
[dynamicMapping addMatcher:boyMatcher];
|
||||
|
||||
// Frst time you get a Girl
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
|
||||
// Reregister boyMatcher
|
||||
[dynamicMapping addMatcher:boyMatcher];
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testIteratingAndRemovingAllMatchers
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 0"] objectMapping:girlMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithPredicate:[NSPredicate predicateWithFormat:@"numeric_type = 1"] objectMapping:boyMapping]];
|
||||
|
||||
for (RKObjectMappingMatcher *matcher in dynamicMapping.matchers) {
|
||||
[dynamicMapping removeMatcher:matcher];
|
||||
}
|
||||
expect(dynamicMapping.matchers).to.beEmpty();
|
||||
}
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnBlockDelegateCallback
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
|
||||
if ([[representation valueForKey:@"type"] isEqualToString:@"Girl"]) {
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
} else if ([[representation valueForKey:@"type"] isEqualToString:@"Boy"]) {
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// RKDynamicMappingTest.m
|
||||
// RestKit
|
||||
//
|
||||
// Created by Blake Watters on 7/28/11.
|
||||
// Copyright (c) 2009-2012 RestKit. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#import "RKTestEnvironment.h"
|
||||
#import "RKDynamicMapping.h"
|
||||
#import "RKDynamicMappingModels.h"
|
||||
|
||||
@interface RKDynamicMappingTest : RKTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RKDynamicMappingTest
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnAnAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"type" isEqualTo:@"Girl"];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"type" isEqualTo:@"Boy"];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testShouldMatchOnAnNSNumberAttributeValue
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKObjectMapping *boyMapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[boyMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"numeric_type" isEqualTo:[NSNumber numberWithInt:0]];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"numeric_type" isEqualTo:[NSNumber numberWithInt:1]];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
- (void)testShouldPickTheAppropriateMappingBasedOnBlockDelegateCallback
|
||||
{
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
|
||||
if ([[representation valueForKey:@"type"] isEqualToString:@"Girl"]) {
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
} else if ([[representation valueForKey:@"type"] isEqualToString:@"Boy"]) {
|
||||
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Boy class]];
|
||||
[mapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
return mapping;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}];
|
||||
RKObjectMapping *mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"girl.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Girl")));
|
||||
mapping = [dynamicMapping objectMappingForRepresentation:[RKTestFixture parsedObjectWithContentsOfFixture:@"boy.json"]];
|
||||
assertThat(mapping, is(notNilValue()));
|
||||
assertThat(NSStringFromClass(mapping.objectClass), is(equalTo(@"Boy")));
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -515,7 +515,7 @@
|
||||
{
|
||||
RKEntityMapping *humanMapping = [RKEntityMapping mappingForEntityForName:@"Human" inManagedObjectStore:_objectManager.managedObjectStore];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:humanMapping whenValueOfKeyPath:@"whatever" isEqualTo:@"whatever"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"whatever" expectedValue:@"whatever" objectMapping:humanMapping]];
|
||||
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:dynamicMapping pathPattern:nil keyPath:nil statusCodes:nil];
|
||||
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:@"http://restkit.org"]];
|
||||
manager.managedObjectStore = [RKTestFactory managedObjectStore];
|
||||
|
||||
@@ -1924,8 +1924,8 @@
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"type" isEqualTo:@"Boy"];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"type" isEqualTo:@"Girl"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Boy" objectMapping:boyMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Girl" objectMapping:girlMapping]];
|
||||
|
||||
NSMutableDictionary *mappingsDictionary = [NSMutableDictionary dictionary];
|
||||
[mappingsDictionary setObject:dynamicMapping forKey:[NSNull null]];
|
||||
@@ -1945,8 +1945,8 @@
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"type" isEqualTo:@"Boy"];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"type" isEqualTo:@"Girl"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Boy" objectMapping:boyMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Girl" objectMapping:girlMapping]];
|
||||
|
||||
NSMutableDictionary *mappingsDictionary = [NSMutableDictionary dictionary];
|
||||
[mappingsDictionary setObject:dynamicMapping forKey:[NSNull null]];
|
||||
@@ -1971,8 +1971,8 @@
|
||||
RKObjectMapping *girlMapping = [RKObjectMapping mappingForClass:[Girl class]];
|
||||
[girlMapping addAttributeMappingsFromArray:@[@"name"]];
|
||||
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
|
||||
[dynamicMapping setObjectMapping:boyMapping whenValueOfKeyPath:@"type" isEqualTo:@"Boy"];
|
||||
[dynamicMapping setObjectMapping:girlMapping whenValueOfKeyPath:@"type" isEqualTo:@"Girl"];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Boy" objectMapping:boyMapping]];
|
||||
[dynamicMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"type" expectedValue:@"Girl" objectMapping:girlMapping]];
|
||||
[boyMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"friends" toKeyPath:@"friends" withMapping:dynamicMapping]];;
|
||||
|
||||
NSMutableDictionary *mappingsDictionary = [NSMutableDictionary dictionary];
|
||||
|
||||
@@ -486,8 +486,8 @@ typedef enum {
|
||||
[routeMapping addAttributeMappingsFromDictionary:@{ @"airlineID": @"airline_id", @"departureAirportID": @"departure_airport_id", @"arrivalAirportID": @"arrival_airport_id" }];
|
||||
|
||||
RKDynamicMapping *flightSearchMapping = [RKDynamicMapping new];
|
||||
[flightSearchMapping setObjectMapping:flightNumberMapping whenValueOfKeyPath:@"mode" isEqualTo:@(RKSearchByFlightNumberMode)];
|
||||
[flightSearchMapping setObjectMapping:routeMapping whenValueOfKeyPath:@"mode" isEqualTo:@(RKSearchByRouteMode)];
|
||||
[flightSearchMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"mode" expectedValue:@(RKSearchByFlightNumberMode) objectMapping:flightNumberMapping]];
|
||||
[flightSearchMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"mode" expectedValue:@(RKSearchByRouteMode) objectMapping:routeMapping]];
|
||||
|
||||
RKDynamicParameterizationFlightSearch *flightSearch = [RKDynamicParameterizationFlightSearch new];
|
||||
flightSearch.airlineID = @5678;
|
||||
@@ -525,7 +525,7 @@ typedef enum {
|
||||
[concreteMapping addAttributeMappingsFromDictionary:@{ @"departureDate": @"departure_date" }];
|
||||
|
||||
RKDynamicMapping *flightSearchMapping = [RKDynamicMapping new];
|
||||
[flightSearchMapping setObjectMapping:concreteMapping whenValueOfKeyPath:@"mode" isEqualTo:@(RKSearchByFlightNumberMode)];
|
||||
[flightSearchMapping addMatcher:[RKObjectMappingMatcher matcherWithKeyPath:@"mode" expectedValue:@(RKSearchByFlightNumberMode) objectMapping:concreteMapping]];
|
||||
|
||||
RKDynamicParameterizationFlightSearch *flightSearch = [RKDynamicParameterizationFlightSearch new];
|
||||
flightSearch.airlineID = @5678;
|
||||
|
||||
Reference in New Issue
Block a user