-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: FastEasyMapping/Source/Core/Mapping/FEMMapping.h FastEasyMapping/Source/Core/Mapping/FEMMapping.m FastEasyMappingTests/Mapping Provider/MappingProvider.m FastEasyMappingTests/Mapping Provider/MappingProviderNative.m
- Loading branch information
Showing
67 changed files
with
2,663 additions
and
2,104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
FastEasyMapping.xcodeproj/xcshareddata/xcschemes/FastEasyMapping.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 9 additions & 12 deletions
21
FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
// | ||
// Created by zen on 15/06/14. | ||
// Copyright (c) 2014 Yalantis. All rights reserved. | ||
// | ||
// For License please refer to LICENSE file in the root of FastEasyMapping project | ||
|
||
@import Foundation; | ||
#import <Foundation/Foundation.h> | ||
|
||
@class FEMAssignmentPolicyMetadata; | ||
@class FEMRelationshipAssignmentContext; | ||
|
||
typedef id (^FEMAssignmentPolicy)(FEMAssignmentPolicyMetadata *metadata); | ||
typedef __nullable id (^FEMAssignmentPolicy)(FEMRelationshipAssignmentContext * __nonnull context); | ||
|
||
OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyAssign; | ||
OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyAssign; | ||
|
||
OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge; | ||
OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge; | ||
OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge; | ||
OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge; | ||
|
||
OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace; | ||
OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace; | ||
OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace; | ||
OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace; |
56 changes: 26 additions & 30 deletions
56
FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,60 @@ | ||
// | ||
// Created by zen on 15/06/14. | ||
// Copyright (c) 2014 Yalantis. All rights reserved. | ||
// | ||
// For License please refer to LICENSE file in the root of FastEasyMapping project | ||
|
||
#import "FEMAssignmentPolicy.h" | ||
|
||
#import "FEMAssignmentPolicyMetadata.h" | ||
#import "FEMRelationshipAssignmentContext.h" | ||
#import "FEMExcludableCollection.h" | ||
#import "FEMMergeableCollection.h" | ||
|
||
@import CoreData; | ||
|
||
FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (FEMAssignmentPolicyMetadata *metadata) { | ||
return metadata.targetValue; | ||
FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id(FEMRelationshipAssignmentContext * context) { | ||
return context.targetRelationshipValue; | ||
}; | ||
|
||
FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { | ||
return metadata.targetValue ?: metadata.existingValue; | ||
FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id(FEMRelationshipAssignmentContext *context) { | ||
return context.targetRelationshipValue ?: context.sourceRelationshipValue; | ||
}; | ||
|
||
FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { | ||
if (!metadata.targetValue) return metadata.existingValue; | ||
FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id(FEMRelationshipAssignmentContext *context) { | ||
if (!context.targetRelationshipValue) return context.sourceRelationshipValue; | ||
|
||
NSCAssert( | ||
[metadata.targetValue conformsToProtocol:@protocol(FEMMergeableCollection)], | ||
[context.targetRelationshipValue conformsToProtocol:@protocol(FEMMergeableCollection)], | ||
@"Collection %@ should support protocol %@", | ||
NSStringFromClass([metadata.targetValue class]), | ||
NSStringFromClass([context.targetRelationshipValue class]), | ||
NSStringFromProtocol(@protocol(FEMMergeableCollection)) | ||
); | ||
|
||
return [metadata.targetValue collectionByMergingObjects:metadata.existingValue]; | ||
return [context.targetRelationshipValue collectionByMergingObjects:context.sourceRelationshipValue]; | ||
}; | ||
|
||
FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { | ||
if (metadata.existingValue && ![metadata.existingValue isEqual:metadata.targetValue]) { | ||
[metadata.context deleteObject:metadata.existingValue]; | ||
FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id(FEMRelationshipAssignmentContext *context) { | ||
if (context.sourceRelationshipValue && ![context.sourceRelationshipValue isEqual:context.targetRelationshipValue]) { | ||
[context deleteRelationshipObject:context.sourceRelationshipValue]; | ||
} | ||
|
||
return metadata.targetValue; | ||
return context.targetRelationshipValue; | ||
}; | ||
|
||
FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { | ||
if (!metadata.existingValue) return metadata.targetValue; | ||
FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id(FEMRelationshipAssignmentContext *context) { | ||
if (!context.sourceRelationshipValue) return context.targetRelationshipValue; | ||
|
||
if (metadata.targetValue) { | ||
if (context.targetRelationshipValue) { | ||
NSCAssert( | ||
[metadata.existingValue conformsToProtocol:@protocol(FEMExcludableCollection)], | ||
[context.sourceRelationshipValue conformsToProtocol:@protocol(FEMExcludableCollection)], | ||
@"Collection %@ should support protocol %@", | ||
NSStringFromClass([metadata.targetValue class]), | ||
NSStringFromClass([context.targetRelationshipValue class]), | ||
NSStringFromProtocol(@protocol(FEMExcludableCollection)) | ||
); | ||
|
||
for (id object in [(id<FEMExcludableCollection>)metadata.existingValue collectionByExcludingObjects:metadata.targetValue]) { | ||
[metadata.context deleteObject:object]; | ||
id objectsToDelete = [(id <FEMExcludableCollection>) context.sourceRelationshipValue collectionByExcludingObjects:context.targetRelationshipValue]; | ||
for (id object in objectsToDelete) { | ||
[context deleteRelationshipObject:object]; | ||
} | ||
} else { | ||
for (id object in metadata.existingValue) { | ||
[metadata.context deleteObject:object]; | ||
for (id object in context.sourceRelationshipValue) { | ||
[context deleteRelationshipObject:object]; | ||
} | ||
} | ||
|
||
return metadata.targetValue; | ||
return context.targetRelationshipValue; | ||
}; |
16 changes: 0 additions & 16 deletions
16
FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.m
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Created by zen on 13/05/15. | ||
// Copyright (c) 2015 Yalantis. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "FEMRelationshipAssignmentContext.h" | ||
|
||
@interface FEMRelationshipAssignmentContext (Internal) | ||
|
||
@property (nonatomic, strong) id destinationObject; | ||
@property (nonatomic, strong) FEMRelationship *relationship; | ||
|
||
@property (nonatomic, strong) id sourceRelationshipValue; | ||
@property (nonatomic, strong) id targetRelationshipValue; | ||
|
||
@end |
31 changes: 31 additions & 0 deletions
31
FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by zen on 13/05/15. | ||
// Copyright (c) 2015 Yalantis. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class FEMRelationship, FEMObjectStore, FEMRelationshipAssignmentContext; | ||
|
||
@protocol FEMRelationshipAssignmentContextDelegate <NSObject> | ||
@required | ||
|
||
- (void)assignmentContext:(nonnull FEMRelationshipAssignmentContext *)context deletedObject:(nonnull id)object; | ||
|
||
@end | ||
|
||
|
||
@interface FEMRelationshipAssignmentContext: NSObject | ||
|
||
@property (nonatomic, unsafe_unretained, readonly, nonnull) FEMObjectStore *store; | ||
- (nonnull instancetype)initWithStore:(nonnull FEMObjectStore *)store; | ||
|
||
@property (nonatomic, strong, readonly, nonnull) id destinationObject; | ||
@property (nonatomic, strong, readonly, nonnull) FEMRelationship *relationship; | ||
|
||
@property (nonatomic, strong, readonly, nullable) id sourceRelationshipValue; | ||
@property (nonatomic, strong, readonly, nullable) id targetRelationshipValue; | ||
|
||
- (void)deleteRelationshipObject:(nonnull id)object; | ||
|
||
@end |
49 changes: 49 additions & 0 deletions
49
FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Created by zen on 13/05/15. | ||
// Copyright (c) 2015 Yalantis. All rights reserved. | ||
// | ||
|
||
#import "FEMRelationshipAssignmentContext.h" | ||
#import "FEMRelationshipAssignmentContext+Internal.h" | ||
|
||
#import "FEMRelationship.h" | ||
#import "FEMObjectStore.h" | ||
|
||
@interface FEMRelationshipAssignmentContext () | ||
|
||
@property (nonatomic, strong) id destinationObject; | ||
@property (nonatomic, strong) FEMRelationship *relationship; | ||
|
||
@property (nonatomic, strong) id sourceRelationshipValue; | ||
@property (nonatomic, strong) id targetRelationshipValue; | ||
|
||
@property (nonatomic, unsafe_unretained) id<FEMRelationshipAssignmentContextDelegate> delegate; | ||
|
||
@end | ||
|
||
@implementation FEMRelationshipAssignmentContext | ||
|
||
- (instancetype)initWithStore:(FEMObjectStore *)store { | ||
self = [super init]; | ||
if (self) { | ||
_store = store; | ||
self.delegate = store; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)deleteRelationshipObject:(id)object { | ||
[self.delegate assignmentContext:self deletedObject:object]; | ||
} | ||
|
||
@end | ||
|
||
@implementation FEMRelationshipAssignmentContext (Internal) | ||
|
||
@dynamic destinationObject; | ||
@dynamic relationship; | ||
@dynamic sourceRelationshipValue; | ||
@dynamic targetRelationshipValue; | ||
|
||
@end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.