Introduce RKPropertyMapping abstract superclass for RKAttributeMapping and RKRelationshipMapping.

Add primitives for working with attribute, relationship, and property mapping objects.
This commit is contained in:
Blake Watters
2012-08-28 13:40:32 -04:00
parent 15acf30a66
commit d926e240f8
13 changed files with 211 additions and 110 deletions

View File

@@ -19,39 +19,32 @@
//
#import "RKRelationshipMapping.h"
#import "RKMapping.h"
@interface RKRelationshipMapping ()
@property (nonatomic, strong, readwrite) NSString *sourceKeyPath;
@property (nonatomic, strong, readwrite) NSString *destinationKeyPath;
@property (nonatomic, strong, readwrite) RKMapping *mapping;
@end
@implementation RKRelationshipMapping
@synthesize mapping = _mapping;
@synthesize reversible = _reversible;
+ (RKRelationshipMapping *)mappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(id)objectOrDynamicMapping reversible:(BOOL)reversible
+ (RKRelationshipMapping *)relationshipMappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)mapping
{
RKRelationshipMapping *relationshipMapping = (RKRelationshipMapping *)[self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath];
relationshipMapping.reversible = reversible;
relationshipMapping.mapping = objectOrDynamicMapping;
RKRelationshipMapping *relationshipMapping = [self new];
relationshipMapping.sourceKeyPath = sourceKeyPath;
relationshipMapping.destinationKeyPath = destinationKeyPath;
relationshipMapping.mapping = mapping;
return relationshipMapping;
}
+ (RKRelationshipMapping *)mappingFromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(id)objectOrDynamicMapping
{
return [self mappingFromKeyPath:sourceKeyPath toKeyPath:destinationKeyPath withMapping:objectOrDynamicMapping reversible:YES];
}
- (id)copyWithZone:(NSZone *)zone
{
RKRelationshipMapping *copy = [super copyWithZone:zone];
copy.mapping = self.mapping;
copy.reversible = self.reversible;
return copy;
}
- (void)dealloc
{
[_mapping release];
[super dealloc];
}
- (BOOL)isEqualToMapping:(RKRelationshipMapping *)otherMapping
{
if (! [otherMapping isMemberOfClass:[RKRelationshipMapping class]]) return NO;