Document RKDynamicMappingMatcher and clean up API

This commit is contained in:
Blake Watters
2012-09-21 22:59:43 -04:00
parent 43be066e0b
commit 654364af61
8 changed files with 73 additions and 61 deletions

View File

@@ -8,70 +8,39 @@
#import "RKDynamicMappingMatcher.h"
// Implemented in RKMappingOperation
BOOL RKObjectIsValueEqualToValue(id sourceValue, id destinationValue);
BOOL RKValueIsEqualToValue(id sourceValue, id destinationValue);
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface RKDynamicMappingMatcher ()
@property (nonatomic, copy) NSString *keyPath;
@property (nonatomic, strong) id value;
@property (nonatomic, copy) BOOL (^isMatchForDataBlock)(id data);
@property (nonatomic, strong, readwrite) id expectedValue;
@property (nonatomic, strong, readwrite) RKObjectMapping *objectMapping;
@property (nonatomic, copy, readwrite) NSString *primaryKeyAttribute;
@end
@implementation RKDynamicMappingMatcher
- (id)initWithKey:(NSString *)key value:(id)value objectMapping:(RKObjectMapping *)objectMapping
- (id)initWithKeyPath:(NSString *)keyPath expectedValue:(id)expectedValue objectMapping:(RKObjectMapping *)objectMapping
{
self = [super init];
if (self) {
self.keyPath = key;
self.value = value;
self.keyPath = keyPath;
self.expectedValue = expectedValue;
self.objectMapping = objectMapping;
}
return self;
}
- (id)initWithKey:(NSString *)key value:(id)value primaryKeyAttribute:(NSString *)primaryKeyAttribute
- (BOOL)matches:(id)object
{
self = [super init];
if (self) {
self.keyPath = key;
self.value = value;
self.primaryKeyAttribute = primaryKeyAttribute;
}
return self;
return RKValueIsEqualToValue([object valueForKeyPath:self.keyPath], self.expectedValue);
}
- (id)initWithPrimaryKeyAttribute:(NSString *)primaryKeyAttribute evaluationBlock:(BOOL (^)(id data))block
- (NSString *)description
{
self = [super init];
if (self) {
self.primaryKeyAttribute = primaryKeyAttribute;
self.isMatchForDataBlock = block;
}
return self;
}
- (BOOL)isMatchForData:(id)data
{
if (self.isMatchForDataBlock) {
return self.isMatchForDataBlock(data);
}
return RKObjectIsValueEqualToValue([data valueForKeyPath:_keyPath], _value);
}
- (NSString *)matchDescription
{
if (self.isMatchForDataBlock) {
return @"No description available. Using block to perform match.";
}
return [NSString stringWithFormat:@"%@ == %@", _keyPath, _value];
return [NSString stringWithFormat:@"<%@: %p when `%@` == '%@' objectMapping: %@>", NSStringFromClass([self class]), self, self.keyPath, self.expectedValue, self.objectMapping];
}
@end