From bc88eaa9767a1cba2e15a3c4e71b09d9b3035af0 Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 12:01:28 +0300 Subject: [PATCH 01/95] [rename] ManagedObjectDeserializer to Deserializer --- FastEasyMapping.xcodeproj/project.pbxproj | 16 +- ...ObjectDeserializer.h => FEMDeserializer.h} | 2 +- ...ObjectDeserializer.m => FEMDeserializer.m} | 4 +- .../Core/Deserializer/FEMObjectDeserializer.m | 2 +- FastEasyMapping/Source/FastEasyMapping.h | 2 +- FastEasyMappingTests/Specs/FEMCacheSpec.m | 32 ++-- .../Specs/FEMManagedObjectDeserializerSpec.m | 144 +++++++++--------- 7 files changed, 101 insertions(+), 101 deletions(-) rename FastEasyMapping/Source/Core/Deserializer/{FEMManagedObjectDeserializer.h => FEMDeserializer.h} (96%) rename FastEasyMapping/Source/Core/Deserializer/{FEMManagedObjectDeserializer.m => FEMDeserializer.m} (99%) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 36b7943..0033d2c 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -64,7 +64,7 @@ 2CF809A518C3AE9A00C07899 /* FEMRelationshipMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1A1592194E312212F9 /* FEMRelationshipMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1B2AB96554F9FDF10B /* FEMSerializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A818C3AE9A00C07899 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 2CF809A918C3AE9A00C07899 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED771F4A0CC2BB6D9583BC /* FEMManagedObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AA18C3AE9A00C07899 /* FastEasyMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED77A829DD1436A5A2CA1B /* FastEasyMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AC18C3AEC800C07899 /* FEMAttributeMapping+Extension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7539B5509DF9599396EA /* FEMAttributeMapping+Extension.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -86,7 +86,7 @@ 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationshipMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationshipMapping.m */; }; 69ED7C04B0D06A2E75D9CDDD /* FEMObjectMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7972B98B6046006A3F97 /* FEMObjectMapping.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; - 69ED7DADB8044F2B42C1CD94 /* FEMManagedObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMManagedObjectDeserializer.m */; }; + 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; @@ -179,8 +179,8 @@ 69ED76DB4A492924FFE33FAF /* AlienNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlienNative.h; sourceTree = ""; }; 69ED76E0E8184C9BDF3CE713 /* CatNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CatNative.m; sourceTree = ""; }; 69ED770C14BAB15CA7926116 /* NSObject+FEMKVCExtension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+FEMKVCExtension.m"; sourceTree = ""; }; - 69ED771F4A0CC2BB6D9583BC /* FEMManagedObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializer.h; sourceTree = ""; }; - 69ED772E50A1A831B78D48B3 /* FEMManagedObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializer.m; sourceTree = ""; }; + 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializer.h; sourceTree = ""; }; + 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMDeserializer.m; sourceTree = ""; }; 69ED7745B6C0CD6C179EE0A8 /* CarNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CarNative.h; sourceTree = ""; }; 69ED775F5613FEA881051644 /* PhoneNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PhoneNative.h; sourceTree = ""; }; 69ED779509541DFE7A36679D /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; @@ -543,8 +543,8 @@ children = ( 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */, 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */, - 69ED771F4A0CC2BB6D9583BC /* FEMManagedObjectDeserializer.h */, - 69ED772E50A1A831B78D48B3 /* FEMManagedObjectDeserializer.m */, + 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */, + 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */, ); path = Deserializer; sourceTree = ""; @@ -581,7 +581,7 @@ 2CF809A518C3AE9A00C07899 /* FEMRelationshipMapping.h in Headers */, 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */, 2CF809A818C3AE9A00C07899 /* FEMObjectDeserializer.h in Headers */, - 2CF809A918C3AE9A00C07899 /* FEMManagedObjectDeserializer.h in Headers */, + 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */, 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */, 2CF809AC18C3AEC800C07899 /* FEMAttributeMapping+Extension.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, @@ -710,7 +710,7 @@ 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationshipMapping.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, 69ED776944D5FF7D7166F975 /* FEMObjectDeserializer.m in Sources */, - 69ED7DADB8044F2B42C1CD94 /* FEMManagedObjectDeserializer.m in Sources */, + 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, 69ED756EBF9D955A7B6A580A /* FEMCache.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h similarity index 96% rename from FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h rename to FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 63524b1..65a81f6 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -4,7 +4,7 @@ @class FEMManagedObjectMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; -@interface FEMManagedObjectDeserializer : NSObject +@interface FEMDeserializer : NSObject + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m similarity index 99% rename from FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m rename to FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index ef81577..cb04b57 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -1,6 +1,6 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project -#import "FEMManagedObjectDeserializer.h" +#import "FEMDeserializer.h" #import @@ -13,7 +13,7 @@ #import "FEMCache.h" #import "FEMAssignmentPolicyMetadata.h" -@implementation FEMManagedObjectDeserializer +@implementation FEMDeserializer #pragma mark - Deserialization diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m index df02e9b..8f9a921 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m @@ -5,7 +5,7 @@ #import "FEMTypeIntrospection.h" #import "FEMAttributeMapping.h" #import -#import "FEMManagedObjectDeserializer.h" +#import "FEMDeserializer.h" #import "NSArray+FEMPropertyRepresentation.h" #import "FEMAttributeMapping+Extension.h" #import "FEMObjectMapping.h" diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index 7cdbdc0..d2077e2 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -11,7 +11,7 @@ #import "FEMObjectMapping.h" #import "FEMManagedObjectMapping.h" -#import "FEMManagedObjectDeserializer.h" +#import "FEMDeserializer.h" #import "FEMObjectDeserializer.h" #import "FEMSerializer.h" diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 97290c7..49e0e66 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -12,7 +12,7 @@ #import "FEMCache.h" #import "MappingProvider.h" #import "Car.h" -#import "FEMManagedObjectDeserializer.h" +#import "FEMDeserializer.h" #import "FEMRelationshipMapping.h" @@ -82,9 +82,9 @@ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] beNil]; - Car *car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [cache addExistingObject:car usingMapping:mapping]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] equal:car]; @@ -93,9 +93,9 @@ it(@"should return registered object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [[[context objectRegisteredForID:car.objectID] should] equal:car]; @@ -106,9 +106,9 @@ it(@"should return saved object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [context MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:context]) should] equal:@1]; @@ -144,18 +144,18 @@ }); it(@"should return nil for missing nested object", ^{ - [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; id missingObjectRepresentation = @{@"id": @2}; [[[cache existingObjectForRepresentation:missingObjectRepresentation mapping:carMapping] should] beNil]; }); it(@"should return existing nested object", ^{ - Person *person = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Person *person = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [[[cache existingObjectForRepresentation:representation[@"car"] mapping:carMapping] should] equal:person.car]; }); }); diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index d46b180..4c368ac 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -7,7 +7,7 @@ #import "MappingProvider.h" #import "Person.h" #import "Car.h" -#import "FEMManagedObjectDeserializer.h" +#import "FEMDeserializer.h" #import "FEMRelationshipMapping.h" #import "FEMMapping.h" #import "FEMManagedObjectMapping.h" @@ -15,7 +15,7 @@ SPEC_BEGIN(FEMManagedObjectDeserializerSpec) -describe(@"FEMManagedObjectDeserializer", ^{ +describe(@"FEMDeserializer", ^{ __block NSManagedObjectContext *moc; beforeEach(^{ @@ -40,9 +40,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMapping] + context:moc]; }); specify(^{ @@ -77,9 +77,9 @@ @"year" : @"2013" }; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; }); specify(^{ @@ -119,9 +119,9 @@ oldCar.model = @""; externalRepresentation = @{@"id" : @(1), @"model" : @"i30",}; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; }); specify(^{ @@ -148,9 +148,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithRootKeyMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carWithRootKeyMapping] + context:moc]; externalRepresentation = [externalRepresentation objectForKey:@"car"]; }); @@ -174,9 +174,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carNestedAttributesMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carNestedAttributesMapping] + context:moc]; }); specify(^{ @@ -200,9 +200,9 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithDateMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carWithDateMapping] + context:moc]; }); specify(^{ @@ -240,9 +240,9 @@ expectedCar.year = @"2013"; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider personMapping] + context:moc]; }); specify(^{ @@ -265,9 +265,9 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider personMapping] + context:moc]; }); specify(^{ @@ -288,9 +288,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Cars"]; - carsArray = [FEMManagedObjectDeserializer deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; + carsArray = [FEMDeserializer deserializeCollectionExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMapping] + context:moc]; }); specify(^{ @@ -309,7 +309,7 @@ beforeAll(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; FEMManagedObjectMapping *mapping = [MappingProvider personMapping]; - person = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:moc]; + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:moc]; }); context(@"to-one", ^{ @@ -351,9 +351,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyAssign; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -361,9 +361,9 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; + Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping + context:moc]; [[person_v1 should] equal:person_v2]; Car *car_v2 = person_v1.car; @@ -378,9 +378,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectMerge; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -388,9 +388,9 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; + Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[person_v1 should] equal:person_v2]; @@ -406,18 +406,18 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectReplace; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping + context:moc]; Car *car_v1 = person_v1.car; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - [FEMManagedObjectDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping]; + [FEMDeserializer fillObject:person_v1 + fromExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -445,9 +445,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionMerge; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; @@ -455,9 +455,9 @@ NSSet *phones_1 = person_v1.phones; [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - [FEMManagedObjectDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping]; + [FEMDeserializer fillObject:person_v1 + fromExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@3]; @@ -471,9 +471,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionReplace; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; @@ -481,9 +481,9 @@ NSSet *phones_1 = person_v1.phones; [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - [FEMManagedObjectDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping]; + [FEMDeserializer fillObject:person_v1 + fromExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; @@ -514,10 +514,10 @@ it(@"should replace all existing objects", ^{ [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - [FEMManagedObjectDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:nil - context:moc]; + [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] + usingMapping:mapping + predicate:nil + context:moc]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; Car *existingCar = [Car MR_findFirstInContext:moc]; [[existingCar.carID should] equal:@2]; @@ -529,10 +529,10 @@ [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID == 1"]; - [FEMManagedObjectDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:predicate - context:moc]; + [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] + usingMapping:mapping + predicate:predicate + context:moc]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; Car *existingCar = [Car MR_findFirstInContext:moc]; [[existingCar.carID should] equal:@2]; @@ -542,10 +542,10 @@ [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID != 1"]; - [FEMManagedObjectDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:predicate - context:moc]; + [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] + usingMapping:mapping + predicate:predicate + context:moc]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@2]; }); }); From 9e8740e3d2732922fe31e5c82d175631ce2d5f35 Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 12:03:46 +0300 Subject: [PATCH 02/95] [pull] primaryKey to FEMMapping --- FastEasyMapping.xcodeproj/project.pbxproj | 10 ++++++++++ .../Source/Core/Mapping/FEMMapping.h | 3 +++ .../Mapping/Object/FEMManagedObjectMapping.h | 3 --- .../Source/Core/Source/FEMDeserializerSource.h | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 0033d2c..593f56d 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -131,6 +131,7 @@ 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicyMetadata.m; sourceTree = ""; }; + 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicyMetadata.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; @@ -263,6 +264,14 @@ path = Collection; sourceTree = ""; }; + 1D6A356C1E80A3B922952414 /* Source */ = { + isa = PBXGroup; + children = ( + 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */, + ); + path = Source; + sourceTree = ""; + }; 1D6A3A11394959655882C6B7 /* Assignment Policy */ = { isa = PBXGroup; children = ( @@ -432,6 +441,7 @@ 69ED7C8732A1C26BF1CF78CD /* Deserializer */, 69ED7CB4B4B9CD8DDF958D64 /* Cache */, 1D6A3A11394959655882C6B7 /* Assignment Policy */, + 1D6A356C1E80A3B922952414 /* Source */, ); path = Core; sourceTree = ""; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 339f65e..293688a 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -13,6 +13,9 @@ @property (nonatomic, copy) NSString *rootPath; - (id)initWithRootPath:(NSString *)rootPath; +@property (nonatomic, copy) NSString *primaryKey; +@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyMapping; + @property (nonatomic, strong, readonly) NSArray *attributeMappings; - (void)addAttributeMapping:(FEMAttributeMapping *)attributeMapping; diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 079f7d3..c688f15 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -15,9 +15,6 @@ @interface FEMManagedObjectMapping : FEMMapping @property (nonatomic, copy, readonly) NSString *entityName; -@property (nonatomic, copy) NSString *primaryKey; - -@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyMapping; + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName; + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName diff --git a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h new file mode 100644 index 0000000..509748c --- /dev/null +++ b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h @@ -0,0 +1,17 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +@import Foundation; + +@protocol FEMDeserializerSource + + + +//- (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObjectMapping *)mapping; +//- (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping; +// +//- (NSDictionary *)existingObjectsForMapping:(FEMManagedObjectMapping *)mapping; + +@end \ No newline at end of file From 5d2a061ce89c13f7a08e2e561479c20b8bc881bc Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 12:15:56 +0300 Subject: [PATCH 03/95] [add] dummy deserializer source --- FastEasyMapping.xcodeproj/project.pbxproj | 6 +++ .../Source/Core/Mapping/FEMMapping.m | 2 + .../Core/Source/FEMDeserializerSource.h | 13 +++-- .../FEMManagedObjectDeserializerSource.h | 14 ++++++ .../FEMManagedObjectDeserializerSource.m | 48 +++++++++++++++++++ 5 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h create mode 100644 FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 593f56d..c48a25f 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; + 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; @@ -119,11 +120,13 @@ /* Begin PBXFileReference section */ 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; + 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializerSource.m; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; + 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; 1D6A3ACBBC8E66609F169E94 /* Person_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_2.json; sourceTree = ""; }; @@ -268,6 +271,8 @@ isa = PBXGroup; children = ( 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */, + 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */, + 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */, ); path = Source; sourceTree = ""; @@ -760,6 +765,7 @@ 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */, 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */, 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */, + 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 8396ac2..a729774 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -4,6 +4,8 @@ #import "FEMAttributeMapping.h" #import "FEMRelationshipMapping.h" +#import "FEMDeserializer.h" +#import "FEMManagedObjectDeserializerSource.h" @implementation FEMMapping diff --git a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h index 509748c..d3f9d9a 100644 --- a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h @@ -5,13 +5,16 @@ @import Foundation; -@protocol FEMDeserializerSource +@class FEMMapping, FEMDeserializer; +@protocol FEMDeserializerSource +@required +- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; +- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; -//- (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObjectMapping *)mapping; -//- (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping; -// -//- (NSDictionary *)existingObjectsForMapping:(FEMManagedObjectMapping *)mapping; +@optional +- (void)prepareForDeserializationOfExternalRepresentation:(id)externalRepresentation deserializer:(FEMDeserializer *)deserializer; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h new file mode 100644 index 0000000..81016b6 --- /dev/null +++ b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h @@ -0,0 +1,14 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +#import "FEMDeserializerSource.h" + +@class FEMManagedObjectMapping, NSManagedObjectContext; + +@interface FEMManagedObjectDeserializerSource : NSObject + +- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping managedObjectContext:(NSManagedObjectContext *)managedObjectContext; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m new file mode 100644 index 0000000..584c757 --- /dev/null +++ b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m @@ -0,0 +1,48 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +#import "FEMManagedObjectDeserializerSource.h" + +#import "FEMManagedObjectMapping.h" +#import "FEMCache.h" + +@implementation FEMManagedObjectDeserializerSource { + FEMCache *_cache; + + NSManagedObjectContext *_managedObjectContext; + FEMManagedObjectMapping *_mapping; +} + +#pragma mark - Init + +- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping managedObjectContext:(NSManagedObjectContext *)managedObjectContext { + self = [super init]; + if (self) { + _managedObjectContext = managedObjectContext; + _mapping = mapping; + } + + return self; +} + +#pragma mark - FEMDeserializerSource + +- (void)prepareForDeserializationOfExternalRepresentation:(id)externalRepresentation deserializer:(FEMDeserializer *)deserializer { + _cache = [[FEMCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; +} + +- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { + return [_cache existingObjectForRepresentation:representation mapping:mapping]; +} + +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping { + return [_cache addExistingObject:object usingMapping:mapping]; +} + +- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { + return [_cache existingObjectsForMapping:mapping]; +} + +@end \ No newline at end of file From f71939bb8a62769f1c0d9add1f6f975b7dcbab24 Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 12:59:22 +0300 Subject: [PATCH 04/95] [implement] collection deserialization using source --- FastEasyMapping/Source/Core/Cache/FEMCache.h | 2 + FastEasyMapping/Source/Core/Cache/FEMCache.m | 6 + .../Core/Deserializer/FEMDeserializer.h | 9 + .../Core/Deserializer/FEMDeserializer.m | 177 +++++++++++++++--- .../Core/Source/FEMDeserializerSource.h | 10 +- .../FEMManagedObjectDeserializerSource.h | 4 +- .../FEMManagedObjectDeserializerSource.m | 21 ++- 7 files changed, 191 insertions(+), 38 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.h b/FastEasyMapping/Source/Core/Cache/FEMCache.h index af4d288..529addb 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.h +++ b/FastEasyMapping/Source/Core/Cache/FEMCache.h @@ -19,6 +19,8 @@ OBJC_EXTERN void FEMCacheRemoveCurrent(); #pragma mark - - (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObjectMapping *)mapping; +- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMManagedObjectMapping *)mapping; + - (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping; - (NSDictionary *)existingObjectsForMapping:(FEMManagedObjectMapping *)mapping; diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.m b/FastEasyMapping/Source/Core/Cache/FEMCache.m index 81767c3..a43da2a 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMCache.m @@ -159,6 +159,12 @@ - (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObje return entityObjectsMap[primaryKeyValue]; } +- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMManagedObjectMapping *)mapping { + NSDictionary *entityObjectsMap = [self cachedObjectsForMapping:mapping]; + + return entityObjectsMap[primaryKey]; +} + - (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping { NSParameterAssert(mapping.primaryKey); NSParameterAssert(object); diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 65a81f6..6aff757 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -2,10 +2,19 @@ #import +@protocol FEMDeserializerSource; + @class FEMManagedObjectMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; @interface FEMDeserializer : NSObject +@property (nonatomic, strong, readonly) id source; +- (id)initWithDeserializerSource:(id)deserializerSource; + +- (id)deserializeObject; + +- (NSArray *)deserializeCollection; + + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index cb04b57..9f6dc94 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -8,12 +8,119 @@ #import "FEMAttributeMapping.h" #import "FEMTypeIntrospection.h" #import "NSArray+FEMPropertyRepresentation.h" +#import "FEMDeserializerSource.h" #import "FEMAttributeMapping+Extension.h" #import "FEMRelationshipMapping.h" #import "FEMCache.h" #import "FEMAssignmentPolicyMetadata.h" +#import "FEMManagedObjectDeserializerSource.h" +#import "KWExample.h" -@implementation FEMDeserializer +@implementation FEMDeserializer { + id _source; +} + +- (id)initWithDeserializerSource:(id)deserializerSource { + NSParameterAssert(deserializerSource != nil); + self = [super init]; + if (self) { + _source = deserializerSource; + } + + return self; +} + +#pragma mark - Utility + +- (id)representationFromExternalRepresentation:(id)externalRepresentation forMapping:(FEMMapping *)mapping { + return mapping.rootPath ? [externalRepresentation valueForKeyPath:mapping.rootPath] : externalRepresentation; +} + +#pragma mark - IMP + +- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { + for (FEMAttributeMapping *attributeMapping in mapping.attributeMappings) { + [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; + } + + for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { + @autoreleasepool { + id relationshipRepresentation = [self representationFromExternalRepresentation:representation + forMapping:relationshipMapping]; + // skip missing key + if (relationshipRepresentation == nil) continue; + + FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; + NSManagedObjectContext *context = object.managedObjectContext; + [metadata setContext:context]; + [metadata setExistingValue:[object valueForKey:relationshipMapping.property]]; + + FEMMapping *objectMapping = relationshipMapping.objectMapping; + id targetValue = nil; + if (relationshipRepresentation != NSNull.null) { + if (relationshipMapping.isToMany) { + targetValue = [self collectionFromRepresentation:relationshipRepresentation + usingMapping:relationshipMapping.objectMapping]; + + objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); + targetValue = [targetValue fem_propertyRepresentation:property]; + } else { + targetValue = [self objectFromRepresentation:relationshipRepresentation + usingMapping:relationshipMapping.objectMapping]; + } + } + + metadata.targetValue = targetValue; + + [object setValue:relationshipMapping.assignmentPolicy(metadata) forKey:relationshipMapping.property]; + } + } + + return object; +} + +- (id)objectFromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { + id object = [self.source registeredObjectForRepresentation:representation mapping:mapping]; + if (!object) { + object = [self.source newObjectForMapping:mapping]; + } + + [self fulfillObject:object fromRepresentation:representation usingMapping:mapping]; + + if ([self.source shouldRegisterObject:object forMapping:mapping]) { + [self.source registerObject:object forMapping:mapping]; + } + + return object; +} + +- (NSArray *)collectionFromRepresentation:(id)representation usingMapping:(FEMMapping *)mapping { + NSMutableArray *output = [NSMutableArray array]; + for (id objectRepresentation in representation) { + @autoreleasepool { + id object = [self objectFromRepresentation:objectRepresentation usingMapping:self.source.mapping]; + [output addObject:object]; + } + } + return [output copy]; +} + +#pragma mark - Public + +- (id)deserializeObject { + return nil; +} + +- (id)fillObject:(id)object { + return nil; +} + +- (NSArray *)deserializeCollection { + NSArray *representation = [self representationFromExternalRepresentation:self.source.externalRepresentation + forMapping:self.source.mapping]; + + return [self collectionFromRepresentation:representation usingMapping:self.source.mapping]; +} #pragma mark - Deserialization @@ -114,40 +221,48 @@ + (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDiction return output; } -+ (NSArray *)_deserializeCollectionRepresentation:(NSArray *)representation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - NSMutableArray *output = [NSMutableArray array]; - for (id objectRepresentation in representation) { - @autoreleasepool { - [output addObject:[self _deserializeObjectRepresentation:objectRepresentation - usingMapping:mapping - context:context]]; - } - } - return [output copy]; -} - -+ (NSArray *)_deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - id representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self _deserializeCollectionRepresentation:representation usingMapping:mapping context:context]; -} +//+ (NSArray *)_deserializeCollectionRepresentation:(NSArray *)representation +// usingMapping:(FEMManagedObjectMapping *)mapping +// context:(NSManagedObjectContext *)context { +// NSMutableArray *output = [NSMutableArray array]; +// for (id objectRepresentation in representation) { +// @autoreleasepool { +// [output addObject:[self _deserializeObjectRepresentation:objectRepresentation +// usingMapping:mapping +// context:context]]; +// } +// } +// return [output copy]; +//} +// +//+ (NSArray *)_deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation +// usingMapping:(FEMManagedObjectMapping *)mapping +// context:(NSManagedObjectContext *)context { +// id representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; +// return [self _deserializeCollectionRepresentation:representation usingMapping:mapping context:context]; +//} + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:context]; - FEMCacheSetCurrent(cache); - NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:mapping - context:context]; - FEMCacheRemoveCurrent(); - - return output; + FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + externalRepresentation:externalRepresentation + managedObjectContext:context]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; + + return [deserializer deserializeCollection]; + + +// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping +// externalRepresentation:externalRepresentation +// context:context]; +// FEMCacheSetCurrent(cache); +// NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation +// usingMapping:mapping +// context:context]; +// FEMCacheRemoveCurrent(); +// +// return output; } + (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation diff --git a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h index d3f9d9a..54def35 100644 --- a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h @@ -10,11 +10,17 @@ @protocol FEMDeserializerSource @required + +@property (nonatomic, strong, readonly) FEMMapping *mapping; +@property (nonatomic, strong, readonly) id externalRepresentation; + +- (id)newObjectForMapping:(FEMMapping *)mapping; + - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; - (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; -@optional -- (void)prepareForDeserializationOfExternalRepresentation:(id)externalRepresentation deserializer:(FEMDeserializer *)deserializer; +- (BOOL)isObjectRegistered:(id)object forMapping:(FEMMapping *)mapping; +- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h index 81016b6..7e3e0eb 100644 --- a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h @@ -9,6 +9,8 @@ @interface FEMManagedObjectDeserializerSource : NSObject -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping managedObjectContext:(NSManagedObjectContext *)managedObjectContext; +- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping + externalRepresentation:(id)externalRepresentation + managedObjectContext:(NSManagedObjectContext *)managedObjectContext; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m index 584c757..6e46d68 100644 --- a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m +++ b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m @@ -5,6 +5,8 @@ #import "FEMManagedObjectDeserializerSource.h" +@import CoreData; + #import "FEMManagedObjectMapping.h" #import "FEMCache.h" @@ -15,13 +17,19 @@ @implementation FEMManagedObjectDeserializerSource { FEMManagedObjectMapping *_mapping; } +@synthesize mapping = _mapping; +@synthesize externalRepresentation = _externalRepresentation; + #pragma mark - Init -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping managedObjectContext:(NSManagedObjectContext *)managedObjectContext { +- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping externalRepresentation:(id)externalRepresentation managedObjectContext:(NSManagedObjectContext *)managedObjectContext { self = [super init]; if (self) { - _managedObjectContext = managedObjectContext; _mapping = mapping; + _externalRepresentation = externalRepresentation; + _managedObjectContext = managedObjectContext; + + _cache = [[FEMCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; } return self; @@ -29,8 +37,9 @@ - (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping managedObject #pragma mark - FEMDeserializerSource -- (void)prepareForDeserializationOfExternalRepresentation:(id)externalRepresentation deserializer:(FEMDeserializer *)deserializer { - _cache = [[FEMCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; +- (id)newObjectForMapping:(FEMMapping *)mapping { + NSString *entityName = [(FEMManagedObjectMapping *)mapping entityName]; + return [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:_managedObjectContext]; } - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { @@ -45,4 +54,8 @@ - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { return [_cache existingObjectsForMapping:mapping]; } +- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping { + return mapping.primaryKey != nil && [object isInserted]; +} + @end \ No newline at end of file From 7053830175fd1e75ec874065f34e36d13860da0b Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 13:08:10 +0300 Subject: [PATCH 05/95] [add] AssignmentPolicyContext --- FastEasyMapping.xcodeproj/project.pbxproj | 2 ++ .../Assignment Policy/FEMAssignmentPolicy.m | 30 +++++++++---------- .../FEMAssignmentPolicyContext.h | 18 +++++++++++ .../FEMAssignmentPolicyMetadata.h | 2 +- .../Core/Deserializer/FEMDeserializer.m | 4 +-- 5 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index c48a25f..b701363 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -125,6 +125,7 @@ 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; + 1D6A35EC486BE2758A03942C /* FEMAssignmentPolicyContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicyContext.h; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; @@ -284,6 +285,7 @@ 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */, 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */, 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */, + 1D6A35EC486BE2758A03942C /* FEMAssignmentPolicyContext.h */, ); path = "Assignment Policy"; sourceTree = ""; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index 742a457..74ac26b 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -16,11 +16,11 @@ }; FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - return metadata.targetValue ?: metadata.existingValue; + return metadata.targetValue ?: metadata.sourceValue; }; FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.targetValue) return metadata.existingValue; + if (!metadata.targetValue) return metadata.sourceValue; NSCAssert( [metadata.targetValue conformsToProtocol:@protocol(FEMMergeableCollection)], @@ -29,33 +29,33 @@ NSStringFromProtocol(@protocol(FEMMergeableCollection)) ); - return [metadata.targetValue collectionByMergingObjects:metadata.existingValue]; + return [metadata.targetValue collectionByMergingObjects:metadata.sourceValue]; }; FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (metadata.existingValue && ![metadata.existingValue isEqual:metadata.targetValue]) { - [metadata.context deleteObject:metadata.existingValue]; + if (metadata.sourceValue && ![metadata.sourceValue isEqual:metadata.targetValue]) { + [metadata.context deleteObject:metadata.sourceValue]; } return metadata.targetValue; }; FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.existingValue) return metadata.targetValue; + if (!metadata.sourceValue) return metadata.targetValue; if (metadata.targetValue) { NSCAssert( - [metadata.existingValue conformsToProtocol:@protocol(FEMExcludableCollection)], + [metadata.sourceValue conformsToProtocol:@ protocol(FEMExcludableCollection)], @"Collection %@ should support protocol %@", NSStringFromClass([metadata.targetValue class]), NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - for (id object in [(id)metadata.existingValue collectionByExcludingObjects:metadata.targetValue]) { + for (id object in [(id)metadata.sourceValue collectionByExcludingObjects:metadata.targetValue]) { [metadata.context deleteObject:object]; } } else { - for (id object in metadata.existingValue) { + for (id object in metadata.sourceValue) { [metadata.context deleteObject:object]; } } @@ -66,7 +66,7 @@ #pragma mark - Deprecated FEMAssignmentPolicy FEMAssignmentPolicyMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.targetValue) return metadata.existingValue; + if (!metadata.targetValue) return metadata.sourceValue; if ([metadata.targetValue isKindOfClass:NSManagedObject.class]) return metadata.targetValue; @@ -77,14 +77,14 @@ NSStringFromProtocol(@protocol(FEMMergeableCollection)) ); - return [metadata.targetValue collectionByMergingObjects:metadata.existingValue]; + return [metadata.targetValue collectionByMergingObjects:metadata.sourceValue]; }; FEMAssignmentPolicy FEMAssignmentPolicyReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.existingValue) return metadata.targetValue; + if (!metadata.sourceValue) return metadata.targetValue; - if ([metadata.existingValue isKindOfClass:NSManagedObject.class]) { - [metadata.context deleteObject:metadata.existingValue]; + if ([metadata.sourceValue isKindOfClass:NSManagedObject.class]) { + [metadata.context deleteObject:metadata.sourceValue]; } else if (metadata.targetValue) { NSCAssert( [metadata.targetValue conformsToProtocol:@protocol(FEMExcludableCollection)], @@ -93,7 +93,7 @@ NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - for (id object in [(id)metadata.existingValue collectionByExcludingObjects:metadata.targetValue]) { + for (id object in [(id)metadata.sourceValue collectionByExcludingObjects:metadata.targetValue]) { [metadata.context deleteObject:object]; } } diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h new file mode 100644 index 0000000..965177a --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h @@ -0,0 +1,18 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +@import Foundation; + +#import + +@protocol FEMAssignmentPolicyContext +@required +- (id)destinationObject; +- (objc_property_t)destinationProperty; + +- (id)existingValue; +- (id)targetValue; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h index 701bbbb..9b19471 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h @@ -9,7 +9,7 @@ @interface FEMAssignmentPolicyMetadata : NSObject -@property (nonatomic, strong) id existingValue; +@property (nonatomic, strong) id sourceValue; @property (nonatomic, strong) id targetValue; @property (nonatomic, strong) NSManagedObjectContext *context; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 9f6dc94..0cfcaf0 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -53,7 +53,7 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; NSManagedObjectContext *context = object.managedObjectContext; [metadata setContext:context]; - [metadata setExistingValue:[object valueForKey:relationshipMapping.property]]; + [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; FEMMapping *objectMapping = relationshipMapping.objectMapping; id targetValue = nil; @@ -182,7 +182,7 @@ + (id)_fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)r FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; [metadata setContext:context]; - [metadata setExistingValue:[object valueForKey:relationshipMapping.property]]; + [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; if (relationshipRepresentation != NSNull.null) { if (relationshipMapping.isToMany) { From bff07bfff88936ebf420728045d6ec4fec0e7426 Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 13:25:42 +0300 Subject: [PATCH 06/95] [ololo] --- FastEasyMapping.xcodeproj/project.pbxproj | 22 ++++--- .../Assignment Policy/FEMAssignmentContext.h | 21 ++++++ .../FEMAssignmentContextPrivate.h | 17 +++++ .../Assignment Policy/FEMAssignmentPolicy.h | 4 +- .../Assignment Policy/FEMAssignmentPolicy.m | 64 +++++++++---------- .../FEMAssignmentPolicyContext.h | 18 ------ .../FEMAssignmentPolicyMetadata.h | 16 ----- .../FEMAssignmentPolicyMetadata.m | 11 ---- .../FEMDefaultAssignmentContext.h | 16 +++++ .../FEMDefaultAssignmentContext.m | 33 ++++++++++ .../Core/Deserializer/FEMDeserializer.m | 6 +- .../Source/Core/Mapping/FEMMapping.m | 1 + .../Core/Source/FEMDeserializerSource.h | 5 +- .../FEMManagedObjectDeserializerSource.m | 5 ++ FastEasyMapping/Source/FastEasyMapping.h | 2 +- 15 files changed, 147 insertions(+), 94 deletions(-) create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.m create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index b701363..5739e26 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -11,7 +11,9 @@ 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */; }; + 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; + 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; @@ -91,9 +93,7 @@ 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; - ADC5B81E194E0F8900F07712 /* FEMAssignmentPolicyMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; - ADC5B820194E0FB700F07712 /* FEMAssignmentPolicyMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -120,23 +120,24 @@ /* Begin PBXFileReference section */ 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; + 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDefaultAssignmentContext.h; sourceTree = ""; }; 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializerSource.m; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; + 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMDefaultAssignmentContext.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; - 1D6A35EC486BE2758A03942C /* FEMAssignmentPolicyContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicyContext.h; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; + 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContextPrivate.h; sourceTree = ""; }; 1D6A3ACBBC8E66609F169E94 /* Person_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_2.json; sourceTree = ""; }; 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMExcludableCollection.h; sourceTree = ""; }; 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; - 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicyMetadata.m; sourceTree = ""; }; + 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContext.h; sourceTree = ""; }; 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; - 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicyMetadata.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; @@ -283,9 +284,10 @@ children = ( 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */, 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */, - 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */, - 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */, - 1D6A35EC486BE2758A03942C /* FEMAssignmentPolicyContext.h */, + 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */, + 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */, + 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */, + 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */, ); path = "Assignment Policy"; sourceTree = ""; @@ -602,13 +604,13 @@ 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */, 2CF809AC18C3AEC800C07899 /* FEMAttributeMapping+Extension.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, - ADC5B820194E0FB700F07712 /* FEMAssignmentPolicyMetadata.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 69ED702FCEC21C111D4518AC /* FEMPropertyMapping.h in Headers */, 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, + 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -722,7 +724,6 @@ 69ED7C04B0D06A2E75D9CDDD /* FEMObjectMapping.m in Sources */, 69ED7687DEAC011EE09F5D1A /* FEMManagedObjectMapping.m in Sources */, 69ED7299E71FA1B0B34E9764 /* FEMAttributeMapping.m in Sources */, - ADC5B81E194E0F8900F07712 /* FEMAssignmentPolicyMetadata.m in Sources */, 69ED70D8C859F4A0BDE4DCF8 /* FEMAttributeMapping+Extension.m in Sources */, 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationshipMapping.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, @@ -734,6 +735,7 @@ 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, + 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h new file mode 100644 index 0000000..c9e901a --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h @@ -0,0 +1,21 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +@import Foundation; + +#import + +@protocol FEMAssignmentContext + +@required +@property (nonatomic, readonly) id destinationObject; +@property (nonatomic, readonly) objc_property_t destinationProperty; + +@property (nonatomic, readonly) id existingRelationshipValue; +@property (nonatomic, readonly) id targetRelationshipValue; + +- (void)deleteRelationshipObject:(id)object; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h new file mode 100644 index 0000000..0e1b20e --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h @@ -0,0 +1,17 @@ +// +// Created by zen on 19/10/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +#import "FEMAssignmentContext.h" + +@protocol FEMAssignmentContextPrivate + +@required +@property (nonatomic, strong, readwrite) id destinationObject; +@property (nonatomic, readwrite) objc_property_t destinationProperty; + +@property (nonatomic, strong, readwrite) id existingRelationshipValue; +@property (nonatomic, strong, readwrite) id targetRelationshipValue; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index a368838..1388ba4 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -5,9 +5,9 @@ @import Foundation; -@class FEMAssignmentPolicyMetadata; +@class FEMDefaultAssignmentContext; -typedef id (^FEMAssignmentPolicy)(FEMAssignmentPolicyMetadata *metadata); +typedef id (^FEMAssignmentPolicy)(FEMDefaultAssignmentContext *metadata); OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyAssign; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index 74ac26b..429c96e 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -5,53 +5,53 @@ #import "FEMAssignmentPolicy.h" -#import "FEMAssignmentPolicyMetadata.h" +#import "FEMDefaultAssignmentContext.h" #import "FEMExcludableCollection.h" #import "FEMMergeableCollection.h" @import CoreData; -FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (FEMAssignmentPolicyMetadata *metadata) { - return metadata.targetValue; +FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (FEMDefaultAssignmentContext *metadata) { + return metadata.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - return metadata.targetValue ?: metadata.sourceValue; +FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (FEMDefaultAssignmentContext *metadata) { + return metadata.targetRelationshipValue ?: metadata.sourceValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.targetValue) return metadata.sourceValue; +FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (FEMDefaultAssignmentContext *metadata) { + if (!metadata.targetRelationshipValue) return metadata.sourceValue; NSCAssert( - [metadata.targetValue conformsToProtocol:@protocol(FEMMergeableCollection)], + [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMMergeableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetValue class]), + NSStringFromClass([metadata.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMMergeableCollection)) ); - return [metadata.targetValue collectionByMergingObjects:metadata.sourceValue]; + return [metadata.targetRelationshipValue collectionByMergingObjects:metadata.sourceValue]; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (metadata.sourceValue && ![metadata.sourceValue isEqual:metadata.targetValue]) { +FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (FEMDefaultAssignmentContext *metadata) { + if (metadata.sourceValue && ![metadata.sourceValue isEqual:metadata.targetRelationshipValue]) { [metadata.context deleteObject:metadata.sourceValue]; } - return metadata.targetValue; + return metadata.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.sourceValue) return metadata.targetValue; +FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (FEMDefaultAssignmentContext *metadata) { + if (!metadata.sourceValue) return metadata.targetRelationshipValue; - if (metadata.targetValue) { + if (metadata.targetRelationshipValue) { NSCAssert( [metadata.sourceValue conformsToProtocol:@ protocol(FEMExcludableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetValue class]), + NSStringFromClass([metadata.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - for (id object in [(id)metadata.sourceValue collectionByExcludingObjects:metadata.targetValue]) { + for (id object in [(id ) metadata.sourceValue collectionByExcludingObjects:metadata.targetRelationshipValue]) { [metadata.context deleteObject:object]; } } else { @@ -60,43 +60,43 @@ } } - return metadata.targetValue; + return metadata.targetRelationshipValue; }; #pragma mark - Deprecated -FEMAssignmentPolicy FEMAssignmentPolicyMerge = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.targetValue) return metadata.sourceValue; +FEMAssignmentPolicy FEMAssignmentPolicyMerge = ^id (FEMDefaultAssignmentContext *metadata) { + if (!metadata.targetRelationshipValue) return metadata.sourceValue; - if ([metadata.targetValue isKindOfClass:NSManagedObject.class]) return metadata.targetValue; + if ([metadata.targetRelationshipValue isKindOfClass:NSManagedObject.class]) return metadata.targetRelationshipValue; NSCAssert( - [metadata.targetValue conformsToProtocol:@protocol(FEMMergeableCollection)], + [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMMergeableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetValue class]), + NSStringFromClass([metadata.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMMergeableCollection)) ); - return [metadata.targetValue collectionByMergingObjects:metadata.sourceValue]; + return [metadata.targetRelationshipValue collectionByMergingObjects:metadata.sourceValue]; }; -FEMAssignmentPolicy FEMAssignmentPolicyReplace = ^id (FEMAssignmentPolicyMetadata *metadata) { - if (!metadata.sourceValue) return metadata.targetValue; +FEMAssignmentPolicy FEMAssignmentPolicyReplace = ^id (FEMDefaultAssignmentContext *metadata) { + if (!metadata.sourceValue) return metadata.targetRelationshipValue; if ([metadata.sourceValue isKindOfClass:NSManagedObject.class]) { [metadata.context deleteObject:metadata.sourceValue]; - } else if (metadata.targetValue) { + } else if (metadata.targetRelationshipValue) { NSCAssert( - [metadata.targetValue conformsToProtocol:@protocol(FEMExcludableCollection)], + [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMExcludableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetValue class]), + NSStringFromClass([metadata.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - for (id object in [(id)metadata.sourceValue collectionByExcludingObjects:metadata.targetValue]) { + for (id object in [(id ) metadata.sourceValue collectionByExcludingObjects:metadata.targetRelationshipValue]) { [metadata.context deleteObject:object]; } } - return metadata.targetValue; + return metadata.targetRelationshipValue; }; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h deleted file mode 100644 index 965177a..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyContext.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -@import Foundation; - -#import - -@protocol FEMAssignmentPolicyContext -@required -- (id)destinationObject; -- (objc_property_t)destinationProperty; - -- (id)existingValue; -- (id)targetValue; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h deleted file mode 100644 index 9b19471..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by zen on 15/06/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -@import Foundation; - -@class NSManagedObjectContext; - -@interface FEMAssignmentPolicyMetadata : NSObject - -@property (nonatomic, strong) id sourceValue; -@property (nonatomic, strong) id targetValue; -@property (nonatomic, strong) NSManagedObjectContext *context; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.m deleted file mode 100644 index f13fe9a..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicyMetadata.m +++ /dev/null @@ -1,11 +0,0 @@ -// -// Created by zen on 15/06/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -#import - -#import "FEMAssignmentPolicyMetadata.h" - -@implementation FEMAssignmentPolicyMetadata -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h new file mode 100644 index 0000000..91e13a0 --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h @@ -0,0 +1,16 @@ +// +// Created by zen on 15/06/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +@import Foundation; + +#import "FEMAssignmentContextPrivate.h" + +@class NSManagedObjectContext; + +@interface FEMDefaultAssignmentContext : NSObject + +- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m new file mode 100644 index 0000000..b92fcec --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m @@ -0,0 +1,33 @@ +// +// Created by zen on 15/06/14. +// Copyright (c) 2014 Yalantis. All rights reserved. +// + +#import "FEMDefaultAssignmentContext.h" + +@import CoreData; + +@implementation FEMDefaultAssignmentContext { + NSManagedObjectContext *_managedObjectContext; +} + +@synthesize destinationObject = _destinationObject; +@synthesize destinationProperty = _destinationProperty; +@synthesize existingRelationshipValue = _existingRelationshipValue; +@synthesize targetRelationshipValue = _targetRelationshipValue; + +#pragma mark - Init + +- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext { + self = [super init]; + if (self) { + _managedObjectContext = managedObjectContext; + } + + return self; +} + +- (void)deleteRelationshipObject:(id)object { + [_managedObjectContext deleteObject:object]; +} +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 0cfcaf0..d75e86b 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -12,7 +12,7 @@ #import "FEMAttributeMapping+Extension.h" #import "FEMRelationshipMapping.h" #import "FEMCache.h" -#import "FEMAssignmentPolicyMetadata.h" +#import "FEMDefaultAssignmentContext.h" #import "FEMManagedObjectDeserializerSource.h" #import "KWExample.h" @@ -50,7 +50,7 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation // skip missing key if (relationshipRepresentation == nil) continue; - FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; + FEMDefaultAssignmentContext *metadata = [FEMDefaultAssignmentContext new]; NSManagedObjectContext *context = object.managedObjectContext; [metadata setContext:context]; [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; @@ -180,7 +180,7 @@ + (id)_fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)r NSStringFromClass(FEMRelationshipMapping.class) ); - FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; + FEMDefaultAssignmentContext *metadata = [FEMDefaultAssignmentContext new]; [metadata setContext:context]; [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index a729774..f2f9e5a 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -6,6 +6,7 @@ #import "FEMRelationshipMapping.h" #import "FEMDeserializer.h" #import "FEMManagedObjectDeserializerSource.h" +#import "FEMAssignmentContextPrivate.h" @implementation FEMMapping diff --git a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h index 54def35..5df1a11 100644 --- a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h @@ -5,6 +5,8 @@ @import Foundation; +@protocol FEMAssignmentContextPrivate; + @class FEMMapping, FEMDeserializer; @protocol FEMDeserializerSource @@ -20,7 +22,8 @@ - (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; -- (BOOL)isObjectRegistered:(id)object forMapping:(FEMMapping *)mapping; - (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping; +- (id)newAssignmentContext; + @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m index 6e46d68..af8d271 100644 --- a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m +++ b/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m @@ -9,6 +9,7 @@ #import "FEMManagedObjectMapping.h" #import "FEMCache.h" +#import "FEMDefaultAssignmentContext.h" @implementation FEMManagedObjectDeserializerSource { FEMCache *_cache; @@ -58,4 +59,8 @@ - (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping { return mapping.primaryKey != nil && [object isInserted]; } +- (id)newAssignmentContext { + return [[FEMDefaultAssignmentContext alloc] initWithManagedObjectContext:_managedObjectContext]; +} + @end \ No newline at end of file diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index d2077e2..f824e90 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -16,7 +16,7 @@ #import "FEMSerializer.h" #import "FEMAssignmentPolicy.h" -#import "FEMAssignmentPolicyMetadata.h" +#import "FEMDefaultAssignmentContext.h" #import "FEMTypes.h" From 0e4de16701f54cfdde07f1348a8f961fe7a1608b Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 13:35:44 +0300 Subject: [PATCH 07/95] [update] assignment policy IMP --- .../Assignment Policy/FEMAssignmentContext.h | 6 +- .../FEMAssignmentContextPrivate.h | 4 +- .../Assignment Policy/FEMAssignmentPolicy.h | 6 +- .../Assignment Policy/FEMAssignmentPolicy.m | 89 ++++++------------- .../FEMDefaultAssignmentContext.m | 3 +- .../Core/Deserializer/FEMDeserializer.m | 13 ++- 6 files changed, 40 insertions(+), 81 deletions(-) diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h index c9e901a..4f0fe30 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h @@ -5,15 +5,15 @@ @import Foundation; -#import +@class FEMRelationshipMapping; @protocol FEMAssignmentContext @required @property (nonatomic, readonly) id destinationObject; -@property (nonatomic, readonly) objc_property_t destinationProperty; +@property (nonatomic, readonly) FEMRelationshipMapping *relationshipMapping; -@property (nonatomic, readonly) id existingRelationshipValue; +@property (nonatomic, readonly) id sourceRelationshipValue; @property (nonatomic, readonly) id targetRelationshipValue; - (void)deleteRelationshipObject:(id)object; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h index 0e1b20e..99b4b33 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h @@ -9,9 +9,9 @@ @required @property (nonatomic, strong, readwrite) id destinationObject; -@property (nonatomic, readwrite) objc_property_t destinationProperty; +@property (nonatomic, readwrite) FEMRelationshipMapping *relationshipMapping; -@property (nonatomic, strong, readwrite) id existingRelationshipValue; +@property (nonatomic, strong, readwrite) id sourceRelationshipValue; @property (nonatomic, strong, readwrite) id targetRelationshipValue; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index 1388ba4..f49ec33 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -5,16 +5,14 @@ @import Foundation; -@class FEMDefaultAssignmentContext; +@protocol FEMAssignmentContext; -typedef id (^FEMAssignmentPolicy)(FEMDefaultAssignmentContext *metadata); +typedef id (^FEMAssignmentPolicy)(id context); OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyAssign; -OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyMerge __attribute__((deprecated("will become obsolete in 0.5.0; use FEMAssignmentPolicyObjectMerge or FEMAssignmentPolicyCollectionMerge instead"))); OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge; OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge; -OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyReplace __attribute__((deprecated("will become obsolete in 0.5.0; use FEMAssignmentPolicyObjectReplace or FEMAssignmentPolicyCollectionReplace instead"))); OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace; OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index 429c96e..b4e2ab5 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -5,98 +5,59 @@ #import "FEMAssignmentPolicy.h" -#import "FEMDefaultAssignmentContext.h" +#import "FEMAssignmentContext.h" #import "FEMExcludableCollection.h" #import "FEMMergeableCollection.h" -@import CoreData; - -FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (FEMDefaultAssignmentContext *metadata) { - return metadata.targetRelationshipValue; +FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (id context) { + return context.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (FEMDefaultAssignmentContext *metadata) { - return metadata.targetRelationshipValue ?: metadata.sourceValue; +FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (id context) { + return context.targetRelationshipValue ?: context.sourceRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (FEMDefaultAssignmentContext *metadata) { - if (!metadata.targetRelationshipValue) return metadata.sourceValue; +FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (id context) { + if (!context.targetRelationshipValue) return context.sourceRelationshipValue; NSCAssert( - [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMMergeableCollection)], + [context.targetRelationshipValue conformsToProtocol:@protocol(FEMMergeableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetRelationshipValue class]), + NSStringFromClass([context.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMMergeableCollection)) ); - return [metadata.targetRelationshipValue collectionByMergingObjects:metadata.sourceValue]; + return [context.targetRelationshipValue collectionByMergingObjects:context.sourceRelationshipValue]; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (FEMDefaultAssignmentContext *metadata) { - if (metadata.sourceValue && ![metadata.sourceValue isEqual:metadata.targetRelationshipValue]) { - [metadata.context deleteObject:metadata.sourceValue]; +FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (id context) { + if (context.sourceRelationshipValue && ![context.sourceRelationshipValue isEqual:context.targetRelationshipValue]) { + [context deleteRelationshipObject:context.sourceRelationshipValue]; } - return metadata.targetRelationshipValue; + return context.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (FEMDefaultAssignmentContext *metadata) { - if (!metadata.sourceValue) return metadata.targetRelationshipValue; +FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (id context) { + if (!context.sourceRelationshipValue) return context.targetRelationshipValue; - if (metadata.targetRelationshipValue) { + if (context.targetRelationshipValue) { NSCAssert( - [metadata.sourceValue conformsToProtocol:@ protocol(FEMExcludableCollection)], + [context.sourceRelationshipValue conformsToProtocol:@ protocol(FEMExcludableCollection)], @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetRelationshipValue class]), + NSStringFromClass([context.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - for (id object in [(id ) metadata.sourceValue collectionByExcludingObjects:metadata.targetRelationshipValue]) { - [metadata.context deleteObject:object]; + id objectsToDelete = [(id)context.sourceRelationshipValue collectionByExcludingObjects:context.targetRelationshipValue]; + for (id object in objectsToDelete) { + [context deleteRelationshipObject:object]; } } else { - for (id object in metadata.sourceValue) { - [metadata.context deleteObject:object]; - } - } - - return metadata.targetRelationshipValue; -}; - -#pragma mark - Deprecated - -FEMAssignmentPolicy FEMAssignmentPolicyMerge = ^id (FEMDefaultAssignmentContext *metadata) { - if (!metadata.targetRelationshipValue) return metadata.sourceValue; - - if ([metadata.targetRelationshipValue isKindOfClass:NSManagedObject.class]) return metadata.targetRelationshipValue; - - NSCAssert( - [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMMergeableCollection)], - @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetRelationshipValue class]), - NSStringFromProtocol(@protocol(FEMMergeableCollection)) - ); - - return [metadata.targetRelationshipValue collectionByMergingObjects:metadata.sourceValue]; -}; - -FEMAssignmentPolicy FEMAssignmentPolicyReplace = ^id (FEMDefaultAssignmentContext *metadata) { - if (!metadata.sourceValue) return metadata.targetRelationshipValue; - - if ([metadata.sourceValue isKindOfClass:NSManagedObject.class]) { - [metadata.context deleteObject:metadata.sourceValue]; - } else if (metadata.targetRelationshipValue) { - NSCAssert( - [metadata.targetRelationshipValue conformsToProtocol:@ protocol(FEMExcludableCollection)], - @"Collection %@ should support protocol %@", - NSStringFromClass([metadata.targetRelationshipValue class]), - NSStringFromProtocol(@protocol(FEMExcludableCollection)) - ); - - for (id object in [(id ) metadata.sourceValue collectionByExcludingObjects:metadata.targetRelationshipValue]) { - [metadata.context deleteObject:object]; + for (id object in context.sourceRelationshipValue) { + [context deleteRelationshipObject:object]; } } - return metadata.targetRelationshipValue; + return context.targetRelationshipValue; }; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m index b92fcec..c3d408b 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m @@ -4,6 +4,7 @@ // #import "FEMDefaultAssignmentContext.h" +#import "FEMAssignmentContext.h" @import CoreData; @@ -13,7 +14,7 @@ @implementation FEMDefaultAssignmentContext { @synthesize destinationObject = _destinationObject; @synthesize destinationProperty = _destinationProperty; -@synthesize existingRelationshipValue = _existingRelationshipValue; +@synthesize sourceRelationshipValue = _existingRelationshipValue; @synthesize targetRelationshipValue = _targetRelationshipValue; #pragma mark - Init diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index d75e86b..90692a1 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -50,12 +50,7 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation // skip missing key if (relationshipRepresentation == nil) continue; - FEMDefaultAssignmentContext *metadata = [FEMDefaultAssignmentContext new]; - NSManagedObjectContext *context = object.managedObjectContext; - [metadata setContext:context]; - [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; - FEMMapping *objectMapping = relationshipMapping.objectMapping; id targetValue = nil; if (relationshipRepresentation != NSNull.null) { if (relationshipMapping.isToMany) { @@ -70,9 +65,13 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation } } - metadata.targetValue = targetValue; + id context = [self.source newAssignmentContext]; + context.destinationObject = object; + context.relationshipMapping = relationshipMapping; + context.sourceRelationshipValue = [object valueForKey:relationshipMapping.property]; + context.targetRelationshipValue = targetValue; - [object setValue:relationshipMapping.assignmentPolicy(metadata) forKey:relationshipMapping.property]; + [object setValue:relationshipMapping.assignmentPolicy(context) forKey:relationshipMapping.property]; } } From 5188fe92c4fe0ec5f68b3bf81bfcb46d4e811357 Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 13:47:12 +0300 Subject: [PATCH 08/95] [move] deserializer to source completely --- FastEasyMapping/Source/Core/Cache/FEMCache.m | 4 +- .../Core/Deserializer/FEMDeserializer.m | 204 ++++-------------- .../Core/Deserializer/FEMObjectDeserializer.m | 8 +- .../Source/Core/Mapping/FEMMapping.h | 2 +- .../Source/Core/Mapping/FEMMapping.m | 2 +- .../Relationship/FEMRelationshipMapping.h | 2 +- .../Relationship/FEMRelationshipMapping.m | 2 +- 7 files changed, 53 insertions(+), 171 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.m b/FastEasyMapping/Source/Core/Cache/FEMCache.m index a43da2a..103a7bb 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMCache.m @@ -75,7 +75,7 @@ - (void)inspectObjectRepresentation:(id)objectRepresentation usingMapping:(FEMMa } for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { - id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:objectRepresentation]; + id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:objectRepresentation]; if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { [self inspectRepresentation:relationshipRepresentation usingMapping:(FEMManagedObjectMapping *)relationshipMapping.objectMapping]; @@ -100,7 +100,7 @@ - (void)inspectRepresentation:(id)representation usingMapping:(FEMManagedObjectM } - (void)inspectExternalRepresentation:(id)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { - id representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + id representation = [mapping representationFromExternalRepresentation:externalRepresentation]; [self inspectRepresentation:representation usingMapping:mapping]; } diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 90692a1..f4e8bfe 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -30,12 +30,6 @@ - (id)initWithDeserializerSource:(id)deserializerSource { return self; } -#pragma mark - Utility - -- (id)representationFromExternalRepresentation:(id)externalRepresentation forMapping:(FEMMapping *)mapping { - return mapping.rootPath ? [externalRepresentation valueForKeyPath:mapping.rootPath] : externalRepresentation; -} - #pragma mark - IMP - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { @@ -45,12 +39,9 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { @autoreleasepool { - id relationshipRepresentation = [self representationFromExternalRepresentation:representation - forMapping:relationshipMapping]; - // skip missing key + id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:representation]; if (relationshipRepresentation == nil) continue; - id targetValue = nil; if (relationshipRepresentation != NSNull.null) { if (relationshipMapping.isToMany) { @@ -107,140 +98,42 @@ - (NSArray *)collectionFromRepresentation:(id)representation usingMapping:(FEMMa #pragma mark - Public - (id)deserializeObject { - return nil; + id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; + return [self objectFromRepresentation:representation usingMapping:self.source.mapping]; } -- (id)fillObject:(id)object { - return nil; +- (id)fulfillObject:(id)object { + id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; + return [self fulfillObject:object fromRepresentation:representation usingMapping:self.source.mapping]; } - (NSArray *)deserializeCollection { - NSArray *representation = [self representationFromExternalRepresentation:self.source.externalRepresentation - forMapping:self.source.mapping]; - + id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; return [self collectionFromRepresentation:representation usingMapping:self.source.mapping]; } #pragma mark - Deserialization -+ (id)_deserializeObjectRepresentation:(NSDictionary *)representation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - id object = [FEMCacheGetCurrent() existingObjectForRepresentation:representation mapping:mapping]; - if (!object) { - object = [NSEntityDescription insertNewObjectForEntityForName:mapping.entityName inManagedObjectContext:context]; - } - - [self _fillObject:object fromRepresentation:representation usingMapping:mapping]; - - if ([object isInserted] && mapping.primaryKey) { - [FEMCacheGetCurrent() addExistingObject:object usingMapping:mapping]; - } - - return object; -} - -+ (id)_deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - id objectRepresentation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self _deserializeObjectRepresentation:objectRepresentation usingMapping:mapping context:context]; -} - - + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:context]; - FEMCacheSetCurrent(cache); - id object = [self _deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:context]; - FEMCacheRemoveCurrent(); - - return object; -} - -+ (id)_fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMManagedObjectMapping *)mapping { - for (FEMAttributeMapping *attributeMapping in mapping.attributeMappings) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; - } - - NSManagedObjectContext *context = object.managedObjectContext; - for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { - id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:representation]; - // skip missing key - if (relationshipRepresentation == nil) continue; - - FEMManagedObjectMapping *objectMapping = (FEMManagedObjectMapping *)relationshipMapping.objectMapping; - NSAssert( - [objectMapping isKindOfClass:FEMManagedObjectMapping.class], - @"%@ expect %@ for %@.objectMapping", - NSStringFromClass(self), - NSStringFromClass(FEMManagedObjectMapping.class), - NSStringFromClass(FEMRelationshipMapping.class) - ); - - FEMDefaultAssignmentContext *metadata = [FEMDefaultAssignmentContext new]; - [metadata setContext:context]; - [metadata setSourceValue:[object valueForKey:relationshipMapping.property]]; - - if (relationshipRepresentation != NSNull.null) { - if (relationshipMapping.isToMany) { - NSArray *targetValue = [self _deserializeCollectionRepresentation:relationshipRepresentation - usingMapping:objectMapping - context:context]; - - objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); - [metadata setTargetValue:[targetValue fem_propertyRepresentation:property]]; - } else { - id targetValue = [self _deserializeObjectRepresentation:relationshipRepresentation - usingMapping:objectMapping - context:context]; - metadata.targetValue = targetValue; - } - } else { - metadata.targetValue = nil; - } - - [object setValue:relationshipMapping.assignmentPolicy(metadata) forKey:relationshipMapping.property]; - } + FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + externalRepresentation:externalRepresentation + managedObjectContext:context]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; - return object; + return [deserializer deserializeObject]; } + (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:object.managedObjectContext]; - FEMCacheSetCurrent(cache); - - id objectRepresentation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - id output = [self _fillObject:object fromRepresentation:objectRepresentation usingMapping:mapping]; - FEMCacheRemoveCurrent(); + FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + externalRepresentation:externalRepresentation + managedObjectContext:object.managedObjectContext]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; - return output; + return [deserializer fulfillObject:object]; } -//+ (NSArray *)_deserializeCollectionRepresentation:(NSArray *)representation -// usingMapping:(FEMManagedObjectMapping *)mapping -// context:(NSManagedObjectContext *)context { -// NSMutableArray *output = [NSMutableArray array]; -// for (id objectRepresentation in representation) { -// @autoreleasepool { -// [output addObject:[self _deserializeObjectRepresentation:objectRepresentation -// usingMapping:mapping -// context:context]]; -// } -// } -// return [output copy]; -//} -// -//+ (NSArray *)_deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation -// usingMapping:(FEMManagedObjectMapping *)mapping -// context:(NSManagedObjectContext *)context { -// id representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; -// return [self _deserializeCollectionRepresentation:representation usingMapping:mapping context:context]; -//} - + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { @@ -250,51 +143,40 @@ + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepr FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; return [deserializer deserializeCollection]; +} - -// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping -// externalRepresentation:externalRepresentation -// context:context]; ++ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation + usingMapping:(FEMManagedObjectMapping *)mapping + predicate:(NSPredicate *)predicate + context:(NSManagedObjectContext *)context { +// NSParameterAssert(mapping.primaryKey != nil); +// +// FEMAttributeMapping *primaryKeyMapping = [mapping primaryKeyMapping]; +// +// NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; +// [request setPredicate:predicate]; +// +// NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; +// NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; +// NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects +// forKeys:initialObjectsKeys]; +// +// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; // FEMCacheSetCurrent(cache); // NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation // usingMapping:mapping // context:context]; // FEMCacheRemoveCurrent(); // +// NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; +// [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; +// +// for (NSManagedObject *object in initialObjectsMap.allValues) { +// [context deleteObject:object]; +// } +// // return output; -} - -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context { - NSParameterAssert(mapping.primaryKey != nil); - - FEMAttributeMapping *primaryKeyMapping = [mapping primaryKeyMapping]; - - NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; - [request setPredicate:predicate]; - - NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; - NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; - NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects - forKeys:initialObjectsKeys]; - - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; - FEMCacheSetCurrent(cache); - NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:mapping - context:context]; - FEMCacheRemoveCurrent(); - - NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; - [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; - - for (NSManagedObject *object in initialObjectsMap.allValues) { - [context deleteObject:object]; - } - - return output; + return nil; } @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m index 8f9a921..60928ee 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m @@ -19,7 +19,7 @@ + (id)deserializeObjectRepresentation:(NSDictionary *)representation usingMappin } + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + NSDictionary *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; return [self deserializeObjectRepresentation:representation usingMapping:mapping]; } @@ -29,7 +29,7 @@ + (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation us } for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { - id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:representation]; + id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:representation]; if (relationshipRepresentation == nil) continue; FEMObjectMapping *objectMapping = (FEMObjectMapping *)relationshipMapping.objectMapping; @@ -63,7 +63,7 @@ + (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation us } + (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + NSDictionary *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; } @@ -78,7 +78,7 @@ + (NSArray *)deserializeCollectionRepresentation:(NSArray *)representation using } + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSArray *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + NSArray *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; return [self deserializeCollectionRepresentation:representation usingMapping:mapping]; } diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 293688a..d6db025 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -37,6 +37,6 @@ - (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; -- (id)extractRootFromExternalRepresentation:(id)externalRepresentation; +- (id)representationFromExternalRepresentation:(id)externalRepresentation; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index f2f9e5a..9dbd0b1 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -139,7 +139,7 @@ - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString [self addRelationshipMapping:relationshipMapping]; } -- (id)extractRootFromExternalRepresentation:(id)externalRepresentation { +- (id)representationFromExternalRepresentation:(id)externalRepresentation { return self.rootPath ? [externalRepresentation valueForKeyPath:self.rootPath] : externalRepresentation; } diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h index f9bcb28..97c594c 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h @@ -46,6 +46,6 @@ @interface FEMRelationshipMapping (Extension) -- (id)extractRootFromExternalRepresentation:(id)externalRepresentation; +- (id)representationFromExternalRepresentation:(id)externalRepresentation; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.m b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.m index 7c439b0..bf2f0e6 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.m @@ -92,7 +92,7 @@ + (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPa @implementation FEMRelationshipMapping (Extension) -- (id)extractRootFromExternalRepresentation:(id)externalRepresentation { +- (id)representationFromExternalRepresentation:(id)externalRepresentation { if (self.keyPath) return [externalRepresentation valueForKeyPath:self.keyPath]; return externalRepresentation; From b5086e278be6c00da543c38c86ca4fe5f60c97cf Mon Sep 17 00:00:00 2001 From: zen Date: Sun, 19 Oct 2014 18:12:40 +0300 Subject: [PATCH 09/95] [fix] typo --- .../FEMDefaultAssignmentContext.m | 2 +- .../Core/Deserializer/FEMDeserializer.m | 25 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m index c3d408b..8d5dc24 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m @@ -13,7 +13,7 @@ @implementation FEMDefaultAssignmentContext { } @synthesize destinationObject = _destinationObject; -@synthesize destinationProperty = _destinationProperty; +@synthesize relationshipMapping = _relationshipMapping; @synthesize sourceRelationshipValue = _existingRelationshipValue; @synthesize targetRelationshipValue = _targetRelationshipValue; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index f4e8bfe..47c2b89 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -11,14 +11,10 @@ #import "FEMDeserializerSource.h" #import "FEMAttributeMapping+Extension.h" #import "FEMRelationshipMapping.h" -#import "FEMCache.h" #import "FEMDefaultAssignmentContext.h" #import "FEMManagedObjectDeserializerSource.h" -#import "KWExample.h" -@implementation FEMDeserializer { - id _source; -} +@implementation FEMDeserializer - (id)initWithDeserializerSource:(id)deserializerSource { NSParameterAssert(deserializerSource != nil); @@ -32,11 +28,7 @@ - (id)initWithDeserializerSource:(id)deserializerSource { #pragma mark - IMP -- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { - for (FEMAttributeMapping *attributeMapping in mapping.attributeMappings) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; - } - +- (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { @autoreleasepool { id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:representation]; @@ -62,9 +54,18 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation context.sourceRelationshipValue = [object valueForKey:relationshipMapping.property]; context.targetRelationshipValue = targetValue; - [object setValue:relationshipMapping.assignmentPolicy(context) forKey:relationshipMapping.property]; + id assignmentValue = relationshipMapping.assignmentPolicy(context); + [object setValue:assignmentValue forKey:relationshipMapping.property]; } } +} + +- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { + for (FEMAttributeMapping *attributeMapping in mapping.attributeMappings) { + [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; + } + + [self fulfillObjectRelationships:object fromRepresentation:representation usingMapping:mapping]; return object; } @@ -88,7 +89,7 @@ - (NSArray *)collectionFromRepresentation:(id)representation usingMapping:(FEMMa NSMutableArray *output = [NSMutableArray array]; for (id objectRepresentation in representation) { @autoreleasepool { - id object = [self objectFromRepresentation:objectRepresentation usingMapping:self.source.mapping]; + id object = [self objectFromRepresentation:objectRepresentation usingMapping:mapping]; [output addObject:object]; } } From e31ee71f42dbf90ac9f844073a3f6e1aad820eb0 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 16:29:57 +0300 Subject: [PATCH 10/95] Remove FEMProperty from FEMAttribute --- FastEasyMapping.xcodeproj/project.pbxproj | 32 +++---------------- .../Core/Mapping/Attribute/FEMAttribute.h | 5 ++- .../Core/Mapping/Attribute/FEMAttribute.m | 3 ++ .../Source/Core/Mapping/FEMProperty.h | 10 ------ FastEasyMapping/Source/FastEasyMapping.h | 1 - 5 files changed, 12 insertions(+), 39 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Mapping/FEMProperty.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 2635db7..07bee14 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -13,11 +13,8 @@ 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */; }; 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; - 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; - 1D6A37C793D545632C8A850E /* FEMRelationshipMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3CDC5401F7A121CDBE70 /* FEMRelationshipMapping.h */; }; - 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; @@ -78,7 +75,6 @@ 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7645386941DA79C1E53A /* NSArray+FEMPropertyRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 69ED702FCEC21C111D4518AC /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7E9FFEE19DA64FCD4858 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757059F6C7A26468D880 /* NSArray+FEMPropertyRepresentation.m */; }; 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED779509541DFE7A36679D /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -133,11 +129,8 @@ 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; - - 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; - 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttributeMapping.h; sourceTree = ""; }; - + 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContextPrivate.h; sourceTree = ""; }; @@ -145,14 +138,9 @@ 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMExcludableCollection.h; sourceTree = ""; }; 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; - 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContext.h; sourceTree = ""; }; - 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; - - 1D6A3CA591E94D2729ED3DA0 /* FEMAssignmentPolicyMetadata.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicyMetadata.m; sourceTree = ""; }; 1D6A3CDC5401F7A121CDBE70 /* FEMRelationshipMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipMapping.h; sourceTree = ""; }; - 1D6A3DEA59A87E175360FBFC /* FEMAssignmentPolicyMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicyMetadata.h; sourceTree = ""; }; - + 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; @@ -239,7 +227,6 @@ 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMTypeIntrospection.h; sourceTree = ""; }; 69ED7E718033F733C45E7416 /* Phone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Phone.h; sourceTree = ""; }; 69ED7E9D5D47846FEFCA62F5 /* FingerNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FingerNative.m; sourceTree = ""; }; - 69ED7E9FFEE19DA64FCD4858 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectMapping.h; sourceTree = ""; }; 69ED7EC086EF5CE3263C6D8D /* FEMObjectMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectMappingSpec.m; sourceTree = ""; }; 69ED7EC1199D47734B9812E7 /* Alien.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Alien.json; sourceTree = ""; }; @@ -497,7 +484,6 @@ 69ED7C716C176C89DA2C9636 /* Object */, 69ED7C6CCD04878CED1E5BAE /* Attribute */, 69ED74A3F93755AF6DBD3662 /* Relationship */, - 69ED7E9FFEE19DA64FCD4858 /* FEMProperty.h */, 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */, 69ED779509541DFE7A36679D /* FEMMapping.h */, ); @@ -625,14 +611,10 @@ 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, - 69ED702FCEC21C111D4518AC /* FEMProperty.h in Headers */, 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, - 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, - 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, 1D6A37C793D545632C8A850E /* FEMRelationshipMapping.h in Headers */, - ); runOnlyForDeploymentPostprocessing = 0; }; @@ -745,16 +727,12 @@ files = ( 69ED7C04B0D06A2E75D9CDDD /* FEMObjectMapping.m in Sources */, 69ED7687DEAC011EE09F5D1A /* FEMManagedObjectMapping.m in Sources */, - - 69ED7299E71FA1B0B34E9764 /* FEMAttributeMapping.m in Sources */, - 69ED70D8C859F4A0BDE4DCF8 /* FEMAttributeMapping+Extension.m in Sources */, - 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationshipMapping.m in Sources */, - 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */, - ADC5B81E194E0F8900F07712 /* FEMAssignmentPolicyMetadata.m in Sources */, 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */, 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */, - + 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */, + 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */, + 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, 69ED776944D5FF7D7166F975 /* FEMObjectDeserializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h index 66ee1de..6f64895 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h @@ -5,11 +5,14 @@ #import "FEMProperty.h" #import "FEMTypes.h" -@interface FEMAttribute : NSObject +@interface FEMAttribute : NSObject - (id)mapValue:(id)value; - (id)reverseMapValue:(id)value; +@property (nonatomic, copy) NSString *property; +@property (nonatomic, copy) NSString *keyPath; + - (id)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; + (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m index 1ab22d8..c0c17dc 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m @@ -17,6 +17,9 @@ - (id)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath map:(FEM self = [super init]; if (self) { + self.property = property; + self.keyPath = keyPath; + _property = [property copy]; [self setKeyPath:keyPath]; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h deleted file mode 100644 index 2f2d140..0000000 --- a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h +++ /dev/null @@ -1,10 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import - -@protocol FEMProperty - -@property (nonatomic, copy, readonly) NSString *property; -@property (nonatomic, copy) NSString *keyPath; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index 7ef47c2..f9adcc5 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -3,7 +3,6 @@ #ifndef _FASTEASYMAPPING_ #define _FASTEASYMAPPING_ -#import "FEMProperty.h" #import "FEMAttribute.h" #import "FEMAttributeMapping.h" From 111d866037be0ad24dae4754c43d08b4cfa77f56 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 16:54:45 +0300 Subject: [PATCH 11/95] twf --- FastEasyMapping.xcodeproj/project.pbxproj | 12 ---- .../Core/Mapping/Attribute/FEMAttribute.h | 1 - .../Source/Core/Mapping/FEMMapping.h | 27 ++++---- .../Source/Core/Mapping/FEMMapping.m | 69 ++++++++----------- .../Mapping/Object/FEMManagedObjectMapping.h | 13 +--- .../Mapping/Object/FEMManagedObjectMapping.m | 62 ----------------- .../Core/Mapping/Object/FEMObjectMapping.h | 26 +++---- .../Core/Mapping/Object/FEMObjectMapping.m | 42 ----------- .../Mapping/Relationship/FEMRelationship.h | 6 +- .../Relationship/FEMRelationshipMapping.h | 38 ---------- 10 files changed, 61 insertions(+), 235 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.m delete mode 100644 FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.m delete mode 100644 FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 07bee14..369532d 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; - 1D6A37C793D545632C8A850E /* FEMRelationshipMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3CDC5401F7A121CDBE70 /* FEMRelationshipMapping.h */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; @@ -83,12 +82,10 @@ 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED770C14BAB15CA7926116 /* NSObject+FEMKVCExtension.m */; }; 69ED756EBF9D955A7B6A580A /* FEMCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7D24C1EE78C03CAB9C9B /* FEMCache.m */; }; 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */; }; - 69ED7687DEAC011EE09F5D1A /* FEMManagedObjectMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED790F30E4E551B1416E60 /* FEMManagedObjectMapping.m */; }; 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; 69ED776944D5FF7D7166F975 /* FEMObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */; }; 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */; }; 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; - 69ED7C04B0D06A2E75D9CDDD /* FEMObjectMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7972B98B6046006A3F97 /* FEMObjectMapping.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -139,7 +136,6 @@ 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContext.h; sourceTree = ""; }; - 1D6A3CDC5401F7A121CDBE70 /* FEMRelationshipMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipMapping.h; sourceTree = ""; }; 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; @@ -199,11 +195,9 @@ 69ED78A3F1B154B04AA09ABB /* Male.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Male.json; sourceTree = ""; }; 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; 69ED78FBF03886650959C5AE /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = ""; }; - 69ED790F30E4E551B1416E60 /* FEMManagedObjectMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectMapping.m; sourceTree = ""; }; 69ED793ABFE3F8A13E1E3D30 /* PersonWithDifferentNaming.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithDifferentNaming.json; sourceTree = ""; }; 69ED794EEC7B9F51E50AC8FA /* AddressNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddressNative.h; sourceTree = ""; }; 69ED796AD9048CFCF07439D0 /* Native.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Native.json; sourceTree = ""; }; - 69ED7972B98B6046006A3F97 /* FEMObjectMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectMapping.m; sourceTree = ""; }; 69ED799D533AED10DCFB4106 /* MappingProviderNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MappingProviderNative.m; sourceTree = ""; }; 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectDeserializer.m; sourceTree = ""; }; 69ED79AD80703DC44EFCC7EE /* Person.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person.json; sourceTree = ""; }; @@ -462,7 +456,6 @@ children = ( 69ED7C1A1592194E312212F9 /* FEMRelationship.h */, 69ED757758DA67B4E8247495 /* FEMRelationship.m */, - 1D6A3CDC5401F7A121CDBE70 /* FEMRelationshipMapping.h */, ); path = Relationship; sourceTree = ""; @@ -553,9 +546,7 @@ isa = PBXGroup; children = ( 69ED70753A27735A60785078 /* FEMObjectMapping.h */, - 69ED7972B98B6046006A3F97 /* FEMObjectMapping.m */, 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */, - 69ED790F30E4E551B1416E60 /* FEMManagedObjectMapping.m */, ); path = Object; sourceTree = ""; @@ -614,7 +605,6 @@ 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, - 1D6A37C793D545632C8A850E /* FEMRelationshipMapping.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -725,8 +715,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 69ED7C04B0D06A2E75D9CDDD /* FEMObjectMapping.m in Sources */, - 69ED7687DEAC011EE09F5D1A /* FEMManagedObjectMapping.m in Sources */, 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */, 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */, 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h index 6f64895..621a0f9 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h @@ -2,7 +2,6 @@ #import -#import "FEMProperty.h" #import "FEMTypes.h" @interface FEMAttribute : NSObject diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 0188197..f46a3d2 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -5,7 +5,6 @@ #import "FEMAttribute.h" #import "FEMAttributeMapping.h" #import "FEMRelationship.h" -#import "FEMRelationshipMapping.h" @interface FEMMapping : NSObject { @protected @@ -13,11 +12,19 @@ NSMutableDictionary *_relationshipMap; } +- (instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); ++ (instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); + +- (instancetype)initWithObjectClass:(Class)objectClass NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER; + +@property (nonatomic, readonly) Class objectClass; +@property (nonatomic, copy, readonly) NSString *entityName; + @property (nonatomic, copy) NSString *rootPath; -- (id)initWithRootPath:(NSString *)rootPath; @property (nonatomic, copy) NSString *primaryKey; -@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyMapping; +@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyAttribute; @property (nonatomic, strong, readonly) NSArray *attributes; - (void)addAttribute:(FEMAttribute *)attribute; @@ -42,18 +49,8 @@ @end -@interface FEMMapping (Deprecated) - -- (void)addAttributeMappingFromArray:(NSArray *)attributes __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping addAttributesFromArray:] instead"))); -- (void)addAttributeMappingDictionary:(NSDictionary *)attributesToKeyPath __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping addAttributesDictionary:] instead"))); -- (void)addAttributeMappingOfProperty:(NSString *)property atKeypath:(NSString *)keypath __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping addAttributeWithProperty:keyPath:] instead"))); - -@property (nonatomic, strong, readonly) NSArray *attributeMappings __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping attributes] instead"))); -- (void)addAttributeMapping:(FEMAttributeMapping *)attributeMapping __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping addAttribute:] instead"))); -- (FEMAttributeMapping *)attributeMappingForProperty:(NSString *)property __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping attributeForProperty:] instead"))); +@interface FEMMapping (Obsolete) -@property (nonatomic, strong, readonly) NSArray *relationshipMappings __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping relationships] instead"))); -- (void)addRelationshipMapping:(FEMRelationshipMapping *)relationshipMapping __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping addRelationship:] instead"))); -- (FEMRelationshipMapping *)relationshipMappingForProperty:(NSString *)property __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMMapping relationshipForProperty:] instead"))); +- (id)initWithRootPath:(NSString *)rootPath __attribute__((obsoleted)); @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 3f98eda..1a8cacf 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -22,13 +22,22 @@ - (id)init { return self; } -- (id)initWithRootPath:(NSString *)rootPath { - self = [self init]; - if (self) { - _rootPath = [rootPath copy]; - } +- (instancetype)initWithObjectClass:(Class)objectClass { + self = [self init]; + if (self) { + _objectClass = objectClass; + } - return self; + return self; +} + +- (instancetype)initWithEntityName:(NSString *)entityName { + self = [self init]; + if (self) { + _entityName = [entityName copy]; + } + + return self; } #pragma mark - Attribute Mapping @@ -52,6 +61,9 @@ - (void)addPropertyMapping:(id)propertyMapping toMap:(NSMutableDict } - (void)addAttribute:(FEMAttribute *)attribute { + + + [self addPropertyMapping:attribute toMap:_attributeMap]; } @@ -79,6 +91,12 @@ - (NSArray *)relationships { return [_relationshipMap allValues]; } +#pragma mark - + +- (FEMAttribute *)primaryKeyAttribute { + return _attributeMap[self.primaryKey]; +} + #pragma mark - Description - (NSString *)description { @@ -145,42 +163,11 @@ - (id)representationFromExternalRepresentation:(id)externalRepresentation { @end -@implementation FEMMapping (Deprecated) - -- (void)addAttributeMappingFromArray:(NSArray *)attributes { - [self addAttributesFromArray:attributes]; -} - -- (void)addAttributeMappingDictionary:(NSDictionary *)attributesToKeyPath { - [self addAttributesDictionary:attributesToKeyPath]; -} - -- (void)addAttributeMappingOfProperty:(NSString *)property atKeypath:(NSString *)keypath { - [self addAttributeWithProperty:property keyPath:keypath]; -} - -- (NSArray *)attributeMappings { - return self.attributes; -} - -- (void)addAttributeMapping:(FEMAttributeMapping *)attributeMapping { - [self addAttribute:attributeMapping]; -} - -- (FEMAttributeMapping *)attributeMappingForProperty:(NSString *)property { - return [self attributeForProperty:property]; -} - -- (NSArray *)relationshipMappings { - return self.relationships; -} - -- (void)addRelationshipMapping:(FEMRelationshipMapping *)relationshipMapping { - [self addRelationship:relationshipMapping]; -} +@implementation FEMMapping (Obsolete) -- (FEMRelationshipMapping *)relationshipMappingForProperty:(NSString *)property { - return [self relationshipForProperty:property]; +- (id)initWithRootPath:(NSString *)rootPath __attribute__((obsoleted)) { + @throw @"Obsolete"; + return nil; } @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 26060be..0c406cd 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -12,25 +12,18 @@ #import "FEMMapping.h" @interface FEMManagedObjectMapping : FEMMapping +@end -@property (nonatomic, copy, readonly) NSString *entityName; -@property (nonatomic, copy) NSString *primaryKey; -@property (nonatomic, strong, readonly) FEMAttribute *primaryKeyAttribute; +@interface FEMManagedObjectMapping (Deprecated) + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName; + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; + configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; - (id)initWithEntityName:(NSString *)entityName; - (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath; @end - -@interface FEMManagedObjectMapping (Deprecated) - -@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyMapping __attribute__((deprecated("will become obsolete in 0.6.0; use -[FEMManagedObjectMapping primaryKeyAttribute] instead"))); - -@end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.m b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.m deleted file mode 100644 index ab503c6..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.m +++ /dev/null @@ -1,62 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMManagedObjectMapping.h" -#import "FEMAttribute.h" - -@implementation FEMManagedObjectMapping - -#pragma mark - Init - -- (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath { - self = [self initWithRootPath:rootPath]; - if (self) { - _entityName = [entityName copy]; - } - return self; -} - -- (id)initWithEntityName:(NSString *)entityName { - return [self initWithEntityName:entityName rootPath:nil]; -} - -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { - FEMManagedObjectMapping *mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:entityName]; - configuration(mapping); - return mapping; -} - -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { - FEMManagedObjectMapping *mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:entityName - rootPath:rootPath]; - configuration(mapping); - return mapping; -} - -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName { - return [[self alloc] initWithEntityName:entityName rootPath:nil]; -} - -#pragma mark - Properties - -- (FEMAttribute *)primaryKeyAttribute { - return _attributeMap[self.primaryKey]; -} - -#pragma mark - Description - -- (NSString *)description { - NSString *descriptionFormat = [super description]; - return [NSString stringWithFormat:descriptionFormat, @"Entity:%@", self.entityName]; -} - -@end - -@implementation FEMManagedObjectMapping (Deprecated) - -- (FEMAttributeMapping *)primaryKeyMapping { - return self.primaryKeyAttribute; -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index cb20923..9a291a4 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -3,16 +3,18 @@ #import #import "FEMMapping.h" -@interface FEMObjectMapping : FEMMapping +@class FEMObjectMapping; +// +//@interface FEMObjectMapping : FEMMapping +// +//@property (nonatomic, readonly) Class objectClass; +// +//- (id)initWithObjectClass:(Class)objectClass; +//- (id)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath; +// +//+ (instancetype)mappingForClass:(Class)objectClass configuration:(void (^)(FEMObjectMapping *mapping))configuration; +//+ (instancetype)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMObjectMapping *mapping))configuration; +// +//@end -@property (nonatomic, readonly) Class objectClass; - -- (id)initWithObjectClass:(Class)objectClass; -- (id)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath; - -+ (instancetype)mappingForClass:(Class)objectClass configuration:(void (^)(FEMObjectMapping *mapping))configuration; -+ (instancetype)mappingForClass:(Class)objectClass - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration; - -@end \ No newline at end of file +@compatibility_alias FEMObjectMapping FEMMapping; diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.m b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.m deleted file mode 100644 index f7c95f0..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.m +++ /dev/null @@ -1,42 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMObjectMapping.h" - -@implementation FEMObjectMapping - -#pragma mark - Init - -- (id)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath { - self = [self initWithRootPath:rootPath]; - if (self) { - _objectClass = objectClass; - } - return self; -} - -- (id)initWithObjectClass:(Class)objectClass { - return [self initWithObjectClass:objectClass rootPath:nil]; -} - -+ (instancetype)mappingForClass:(Class)objectClass configuration:(void (^)(FEMObjectMapping *mapping))configuration { - FEMObjectMapping *mapping = [[self alloc] initWithObjectClass:objectClass]; - configuration(mapping); - return mapping; -} - -+ (instancetype)mappingForClass:(Class)objectClass - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration { - FEMObjectMapping *mapping = [[self alloc] initWithObjectClass:objectClass rootPath:rootPath]; - configuration(mapping); - return mapping; -} - -#pragma mark - Description - -- (NSString *)description { - NSString *descriptionFormat = [super description]; - return [NSString stringWithFormat:descriptionFormat, @"Object Class:%@", NSStringFromClass(self.objectClass)]; -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h index b448638..37769a3 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h @@ -2,12 +2,14 @@ #import -#import "FEMProperty.h" #import "FEMAssignmentPolicy.h" @class FEMMapping; -@interface FEMRelationship : NSObject +@interface FEMRelationship : NSObject + +@property (nonatomic, copy) NSString *property; +@property (nonatomic, copy) NSString *keyPath; @property (nonatomic, copy) FEMAssignmentPolicy assignmentPolicy; diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h deleted file mode 100644 index 5223c76..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// FEMRelationshipMapping.h -// FastEasyMapping -// -// Created by zen on 03/12/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -#import "FEMRelationship.h" - -/** -* @discussion -* FEMRelationshipMapping has been renamed to FEMRelationship -*/ - -@interface FEMRelationshipMapping - -+ (instancetype)mappingOfProperty:(NSString *)property objectMapping:(FEMMapping *)objectMapping; -+ (instancetype)mappingOfProperty:(NSString *)property - toKeyPath:(NSString *)keyPath - objectMapping:(FEMMapping *)objectMapping; - -@end - -@interface FEMRelationshipMapping (Deprecated) - -+ (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPath configuration:(void (^)(FEMRelationshipMapping *mapping))configuration __attribute__((deprecated("will become obsolete in 0.5.0; use + [FEMRelationshipMapping mappingOfProperty:toKeyPath:configuration:] instead"))); -+ (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPath objectMapping:(FEMMapping *)objectMapping __attribute__((deprecated("will become obsolete in 0.5.0; use + [FEMRelationshipMapping mappingOfProperty:toKeyPath:objectMapping:] instead"))); - -@end - -@interface FEMRelationshipMapping (Extension) - -- (id)representationFromExternalRepresentation:(id)externalRepresentation; - -@end - -@compatibility_alias FEMRelationshipMapping FEMRelationship; From 3042a2c8bb1f6c29113706927e6d4f61f1045ed3 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 17:18:20 +0300 Subject: [PATCH 12/95] Add FEMProperty back --- FastEasyMapping.xcodeproj/project.pbxproj | 25 +++--- .../xcschemes/FastEasyMapping.xcscheme | 2 +- .../Assignment Policy/FEMAssignmentContext.h | 4 +- .../FEMAssignmentContextPrivate.h | 8 +- .../Core/Deserializer/FEMDeserializer.m | 32 ++++--- .../Core/Deserializer/FEMObjectDeserializer.m | 85 ------------------- .../Core/Mapping/Attribute/FEMAttribute.h | 6 +- .../Core/Mapping/Attribute/FEMAttribute.m | 3 - .../Source/Core/Mapping/FEMProperty.h | 13 +++ .../Core/Mapping/Object/FEMObjectMapping.h | 1 - .../Mapping/Relationship/FEMRelationship.h | 6 +- 11 files changed, 54 insertions(+), 131 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m create mode 100644 FastEasyMapping/Source/Core/Mapping/FEMProperty.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 369532d..9e93bbd 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */; }; + 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; @@ -74,22 +75,21 @@ 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7645386941DA79C1E53A /* NSArray+FEMPropertyRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757059F6C7A26468D880 /* NSArray+FEMPropertyRepresentation.m */; }; 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED779509541DFE7A36679D /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED769040647781DD8B196D /* NSObject+FEMKVCExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED770C14BAB15CA7926116 /* NSObject+FEMKVCExtension.m */; }; 69ED756EBF9D955A7B6A580A /* FEMCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7D24C1EE78C03CAB9C9B /* FEMCache.m */; }; 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */; }; 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; - 69ED776944D5FF7D7166F975 /* FEMObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */; }; 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */; }; - 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; + AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; + AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; + AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -127,6 +127,7 @@ 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttributeMapping.h; sourceTree = ""; }; + 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; @@ -199,7 +200,6 @@ 69ED794EEC7B9F51E50AC8FA /* AddressNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddressNative.h; sourceTree = ""; }; 69ED796AD9048CFCF07439D0 /* Native.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Native.json; sourceTree = ""; }; 69ED799D533AED10DCFB4106 /* MappingProviderNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MappingProviderNative.m; sourceTree = ""; }; - 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectDeserializer.m; sourceTree = ""; }; 69ED79AD80703DC44EFCC7EE /* Person.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person.json; sourceTree = ""; }; 69ED79F44DC116BCA2287E90 /* Car.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Car.h; sourceTree = ""; }; 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMTypes.h; sourceTree = ""; }; @@ -479,6 +479,7 @@ 69ED74A3F93755AF6DBD3662 /* Relationship */, 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */, 69ED779509541DFE7A36679D /* FEMMapping.h */, + 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */, ); path = Mapping; sourceTree = ""; @@ -555,7 +556,6 @@ isa = PBXGroup; children = ( 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */, - 69ED79ACE44B6BFB58B0B3F5 /* FEMObjectDeserializer.m */, 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */, 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */, ); @@ -605,6 +605,7 @@ 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, + 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -653,7 +654,7 @@ 2CF8097018C3AD5700C07899 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0630; ORGANIZATIONNAME = Yalantis; TargetAttributes = { 2CF8098718C3AD5700C07899 = { @@ -715,14 +716,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */, - 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */, - 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */, - 69ED7299E71FA1B0B34E9764 /* FEMAttribute.m in Sources */, - 69ED70D8C859F4A0BDE4DCF8 /* FEMAttribute+Extension.m in Sources */, - 69ED7A9D4C100F6C8EEEDC03 /* FEMRelationship.m in Sources */, + AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */, + AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */, + AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, - 69ED776944D5FF7D7166F975 /* FEMObjectDeserializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, diff --git a/FastEasyMapping.xcodeproj/xcshareddata/xcschemes/FastEasyMapping.xcscheme b/FastEasyMapping.xcodeproj/xcshareddata/xcschemes/FastEasyMapping.xcscheme index 8305808..b24f4be 100644 --- a/FastEasyMapping.xcodeproj/xcshareddata/xcschemes/FastEasyMapping.xcscheme +++ b/FastEasyMapping.xcodeproj/xcshareddata/xcschemes/FastEasyMapping.xcscheme @@ -1,6 +1,6 @@ @required @property (nonatomic, readonly) id destinationObject; -@property (nonatomic, readonly) FEMRelationshipMapping *relationshipMapping; +@property (nonatomic, readonly) FEMRelationship *relationship; @property (nonatomic, readonly) id sourceRelationshipValue; @property (nonatomic, readonly) id targetRelationshipValue; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h index 99b4b33..6aee0af 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h @@ -8,10 +8,10 @@ @protocol FEMAssignmentContextPrivate @required -@property (nonatomic, strong, readwrite) id destinationObject; -@property (nonatomic, readwrite) FEMRelationshipMapping *relationshipMapping; +@property (nonatomic, strong) id destinationObject; +@property (nonatomic) FEMRelationship *relationship; -@property (nonatomic, strong, readwrite) id sourceRelationshipValue; -@property (nonatomic, strong, readwrite) id targetRelationshipValue; +@property (nonatomic, strong) id sourceRelationshipValue; +@property (nonatomic, strong) id targetRelationshipValue; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 47c2b89..4d61012 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -9,8 +9,8 @@ #import "FEMTypeIntrospection.h" #import "NSArray+FEMPropertyRepresentation.h" #import "FEMDeserializerSource.h" -#import "FEMAttributeMapping+Extension.h" -#import "FEMRelationshipMapping.h" +#import "FEMAttribute+Extension.h" +#import "FEMRelationship.h" #import "FEMDefaultAssignmentContext.h" #import "FEMManagedObjectDeserializerSource.h" @@ -26,36 +26,44 @@ - (id)initWithDeserializerSource:(id)deserializerSource { return self; } +#pragma mark - Utility + +- (id)extractRelationshipRepresentation:(FEMRelationship *)relationship fromExternalRepresentation:(id)externalRepresentation { + if (relationship.keyPath) return [externalRepresentation valueForKeyPath:relationship.keyPath]; + + return externalRepresentation; +} + #pragma mark - IMP - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { - for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { + for (FEMRelationship *relationship in mapping.relationships) { @autoreleasepool { - id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:representation]; + id relationshipRepresentation = [self extractRelationshipRepresentation:relationship fromExternalRepresentation:representation]; if (relationshipRepresentation == nil) continue; id targetValue = nil; if (relationshipRepresentation != NSNull.null) { - if (relationshipMapping.isToMany) { + if (relationship.isToMany) { targetValue = [self collectionFromRepresentation:relationshipRepresentation - usingMapping:relationshipMapping.objectMapping]; + usingMapping:relationship.objectMapping]; - objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); + objc_property_t property = class_getProperty([object class], [relationship.property UTF8String]); targetValue = [targetValue fem_propertyRepresentation:property]; } else { targetValue = [self objectFromRepresentation:relationshipRepresentation - usingMapping:relationshipMapping.objectMapping]; + usingMapping:relationship.objectMapping]; } } id context = [self.source newAssignmentContext]; context.destinationObject = object; - context.relationshipMapping = relationshipMapping; - context.sourceRelationshipValue = [object valueForKey:relationshipMapping.property]; + context.relationshipMapping = relationship; + context.sourceRelationshipValue = [object valueForKey:relationship.property]; context.targetRelationshipValue = targetValue; - id assignmentValue = relationshipMapping.assignmentPolicy(context); - [object setValue:assignmentValue forKey:relationshipMapping.property]; + id assignmentValue = relationship.assignmentPolicy(context); + [object setValue:assignmentValue forKey:relationship.property]; } } } diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m deleted file mode 100644 index 5251553..0000000 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m +++ /dev/null @@ -1,85 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMObjectDeserializer.h" - -#import "FEMTypeIntrospection.h" -#import "FEMAttribute.h" -#import -#import "FEMDeserializer.h" -#import "NSArray+FEMPropertyRepresentation.h" -#import "FEMAttribute+Extension.h" -#import "FEMObjectMapping.h" -#import "FEMRelationship.h" - -@implementation FEMObjectDeserializer - -+ (id)deserializeObjectRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { - id object = [[mapping.objectClass alloc] init]; - return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; -} - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; - return [self deserializeObjectRepresentation:representation usingMapping:mapping]; -} - -+ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { - for (FEMAttribute *attributeMapping in mapping.attributes) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; - } - - for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { - id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:representation]; - if (relationshipRepresentation == nil) continue; - - FEMObjectMapping *objectMapping = (FEMObjectMapping *)relationshipMapping.objectMapping; - NSAssert( - [objectMapping isKindOfClass:FEMObjectMapping.class], - @"%@ expect %@ for %@.objectMapping", - NSStringFromClass(self), - NSStringFromClass(FEMObjectMapping.class), - NSStringFromClass(FEMRelationship.class) - ); - - id targetValue = nil; - if (relationshipRepresentation != NSNull.null) { - if (relationshipMapping.isToMany) { - targetValue = [self deserializeCollectionRepresentation:relationshipRepresentation - usingMapping:objectMapping]; - - objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); - targetValue = [targetValue fem_propertyRepresentation:property]; - } else { - targetValue = [self deserializeObjectRepresentation:relationshipRepresentation - usingMapping:objectMapping]; - } - - } - - [object setValue:targetValue forKeyPath:relationshipMapping.property]; - } - - return object; -} - -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; - return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; -} - -+ (NSArray *)deserializeCollectionRepresentation:(NSArray *)representation usingMapping:(FEMObjectMapping *)mapping { - NSMutableArray *output = [NSMutableArray array]; - for (NSDictionary *objectRepresentation in representation) { - @autoreleasepool { - [output addObject:[self deserializeObjectRepresentation:objectRepresentation usingMapping:mapping]]; - } - } - return [output copy]; -} - -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSArray *representation = [mapping representationFromExternalRepresentation:externalRepresentation]; - return [self deserializeCollectionRepresentation:representation usingMapping:mapping]; -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h index 621a0f9..1185879 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h @@ -3,15 +3,13 @@ #import #import "FEMTypes.h" +#import "FEMProperty.h" -@interface FEMAttribute : NSObject +@interface FEMAttribute : NSObject - (id)mapValue:(id)value; - (id)reverseMapValue:(id)value; -@property (nonatomic, copy) NSString *property; -@property (nonatomic, copy) NSString *keyPath; - - (id)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; + (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m index c0c17dc..689a593 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m @@ -20,9 +20,6 @@ - (id)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath map:(FEM self.property = property; self.keyPath = keyPath; - _property = [property copy]; - [self setKeyPath:keyPath]; - FEMMapBlock passthroughMap = ^(id value) { return value; }; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h new file mode 100644 index 0000000..3ddd0d2 --- /dev/null +++ b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h @@ -0,0 +1,13 @@ +// +// Created by zen on 12/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation; + +@protocol FEMProperty + +@property (nonatomic, copy) NSString *property; +@property (nonatomic, copy) NSString *keyPath; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index 9a291a4..11fa058 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -3,7 +3,6 @@ #import #import "FEMMapping.h" -@class FEMObjectMapping; // //@interface FEMObjectMapping : FEMMapping // diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h index 37769a3..b586065 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h @@ -3,13 +3,11 @@ #import #import "FEMAssignmentPolicy.h" +#import "FEMProperty.h" @class FEMMapping; -@interface FEMRelationship : NSObject - -@property (nonatomic, copy) NSString *property; -@property (nonatomic, copy) NSString *keyPath; +@interface FEMRelationship : NSObject @property (nonatomic, copy) FEMAssignmentPolicy assignmentPolicy; From a30f0a9802a9828b8a7c8b302bdfbf1ba2194e77 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 17:24:37 +0300 Subject: [PATCH 13/95] Add deserializer store --- FastEasyMapping.xcodeproj/project.pbxproj | 42 ++++++++++++------- .../Assignment Policy/FEMAssignmentContext.h | 2 + .../Core/Deserializer/FEMDeserializer.m | 12 +++--- .../Source/Core/Mapping/FEMMapping.m | 2 +- .../{Source => Store}/FEMDeserializerSource.h | 2 +- .../FEMManagedObjectStore.h} | 2 +- .../FEMManagedObjectStore.m} | 6 +-- .../Source/Core/Store/FEMObjectStore.h | 23 ++++++++++ .../Source/Core/Store/FEMObjectStore.m | 13 ++++++ 9 files changed, 76 insertions(+), 28 deletions(-) rename FastEasyMapping/Source/Core/{Source => Store}/FEMDeserializerSource.h (97%) rename FastEasyMapping/Source/Core/{Source/FEMManagedObjectDeserializerSource.h => Store/FEMManagedObjectStore.h} (82%) rename FastEasyMapping/Source/Core/{Source/FEMManagedObjectDeserializerSource.m => Store/FEMManagedObjectStore.m} (94%) create mode 100644 FastEasyMapping/Source/Core/Store/FEMObjectStore.h create mode 100644 FastEasyMapping/Source/Core/Store/FEMObjectStore.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 9e93bbd..0d73f70 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -7,16 +7,19 @@ objects = { /* Begin PBXBuildFile section */ + 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; - 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */; }; + 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; + 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; + 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; }; 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */; }; @@ -117,9 +120,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectStore.m; sourceTree = ""; }; + 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectStore.h; sourceTree = ""; }; 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; + 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectStore.m; sourceTree = ""; }; 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDefaultAssignmentContext.h; sourceTree = ""; }; - 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializerSource.m; sourceTree = ""; }; + 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectStore.h; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMDefaultAssignmentContext.m; sourceTree = ""; }; @@ -128,7 +134,6 @@ 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttributeMapping.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; - 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializerSource.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContextPrivate.h; sourceTree = ""; }; @@ -137,7 +142,7 @@ 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContext.h; sourceTree = ""; }; - 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; + 1D6A3D8BC461265BD6E7959C /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; @@ -265,16 +270,6 @@ path = Collection; sourceTree = ""; }; - 1D6A356C1E80A3B922952414 /* Source */ = { - isa = PBXGroup; - children = ( - 1D6A3D943B11B0FD2B16CEBD /* FEMDeserializerSource.h */, - 1D6A330228855ACC71C62EE6 /* FEMManagedObjectDeserializerSource.m */, - 1D6A37E9BA094025471222F5 /* FEMManagedObjectDeserializerSource.h */, - ); - path = Source; - sourceTree = ""; - }; 1D6A3A11394959655882C6B7 /* Assignment Policy */ = { isa = PBXGroup; children = ( @@ -288,6 +283,18 @@ path = "Assignment Policy"; sourceTree = ""; }; + 1D6A3B055A492274473025DA /* Store */ = { + isa = PBXGroup; + children = ( + 1D6A3D8BC461265BD6E7959C /* FEMDeserializerSource.h */, + 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */, + 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */, + 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */, + 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */, + ); + path = Store; + sourceTree = ""; + }; 2CF8096F18C3AD5700C07899 = { isa = PBXGroup; children = ( @@ -446,7 +453,7 @@ 69ED7C8732A1C26BF1CF78CD /* Deserializer */, 69ED7CB4B4B9CD8DDF958D64 /* Cache */, 1D6A3A11394959655882C6B7 /* Assignment Policy */, - 1D6A356C1E80A3B922952414 /* Source */, + 1D6A3B055A492274473025DA /* Store */, ); path = Core; sourceTree = ""; @@ -606,6 +613,7 @@ 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, + 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -728,6 +736,7 @@ 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */, + 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -761,7 +770,8 @@ 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */, 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */, 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */, - 1D6A34F8104F36BDC1CE4C00 /* FEMManagedObjectDeserializerSource.m in Sources */, + 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */, + 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h index 88315aa..4d0e158 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h @@ -5,6 +5,8 @@ @import Foundation; +@class FEMRelationship; + @protocol FEMAssignmentContext @required diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 4d61012..0bf3ccc 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -12,7 +12,7 @@ #import "FEMAttribute+Extension.h" #import "FEMRelationship.h" #import "FEMDefaultAssignmentContext.h" -#import "FEMManagedObjectDeserializerSource.h" +#import "FEMManagedObjectStore.h" @implementation FEMDeserializer @@ -58,7 +58,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * id context = [self.source newAssignmentContext]; context.destinationObject = object; - context.relationshipMapping = relationship; + context.relationship = relationship; context.sourceRelationshipValue = [object valueForKey:relationship.property]; context.targetRelationshipValue = targetValue; @@ -69,7 +69,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { - for (FEMAttributeMapping *attributeMapping in mapping.attributeMappings) { + for (FEMAttributeMapping *attributeMapping in mapping.attributes) { [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; } @@ -126,7 +126,7 @@ - (NSArray *)deserializeCollection { + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping externalRepresentation:externalRepresentation managedObjectContext:context]; FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; @@ -135,7 +135,7 @@ + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresenta } + (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { - FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping externalRepresentation:externalRepresentation managedObjectContext:object.managedObjectContext]; FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; @@ -146,7 +146,7 @@ + (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDiction + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - FEMManagedObjectDeserializerSource *source = [[FEMManagedObjectDeserializerSource alloc] initWithMapping:mapping + FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping externalRepresentation:externalRepresentation managedObjectContext:context]; FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 1a8cacf..a3a5731 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -5,7 +5,7 @@ #import "FEMAttributeMapping.h" #import "FEMRelationshipMapping.h" #import "FEMDeserializer.h" -#import "FEMManagedObjectDeserializerSource.h" +#import "FEMManagedObjectStore.h" #import "FEMAssignmentContextPrivate.h" @implementation FEMMapping diff --git a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h similarity index 97% rename from FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h rename to FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h index 5df1a11..1895724 100644 --- a/FastEasyMapping/Source/Core/Source/FEMDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h @@ -3,7 +3,7 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -@import Foundation; +@import Foundation.h; @protocol FEMAssignmentContextPrivate; diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h similarity index 82% rename from FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h rename to FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h index 7e3e0eb..1146175 100644 --- a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.h +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h @@ -7,7 +7,7 @@ @class FEMManagedObjectMapping, NSManagedObjectContext; -@interface FEMManagedObjectDeserializerSource : NSObject +@interface FEMManagedObjectStore : NSObject - (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping externalRepresentation:(id)externalRepresentation diff --git a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m similarity index 94% rename from FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m rename to FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index af8d271..1bfdfb5 100644 --- a/FastEasyMapping/Source/Core/Source/FEMManagedObjectDeserializerSource.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -3,15 +3,15 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -#import "FEMManagedObjectDeserializerSource.h" +#import "FEMManagedObjectStore.h" -@import CoreData; +@import CoreData.h; #import "FEMManagedObjectMapping.h" #import "FEMCache.h" #import "FEMDefaultAssignmentContext.h" -@implementation FEMManagedObjectDeserializerSource { +@implementation FEMManagedObjectStore { FEMCache *_cache; NSManagedObjectContext *_managedObjectContext; diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h new file mode 100644 index 0000000..ed88cce --- /dev/null +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -0,0 +1,23 @@ +// +// Created by zen on 12/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation.h; + +@class FEMMapping; + +@protocol FEMAssignmentContextPrivate; + +@interface FEMObjectStore : NSObject + +- (id)newObjectForMapping:(FEMMapping *)mapping; +- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; +- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; + +- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping; + +- (id)newAssignmentContext; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m new file mode 100644 index 0000000..8baaab0 --- /dev/null +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -0,0 +1,13 @@ +// +// Created by zen on 12/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +#import "FEMObjectStore.h" +#import "FEMMapping.h" +#import "FEMAssignmentContextPrivate.h" + +@implementation FEMObjectStore { + +} +@end \ No newline at end of file From 1cb17d19db0d2d82171efba5a67338b45def2785 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:06:15 +0300 Subject: [PATCH 14/95] Update mapping --- .../Source/Core/Mapping/FEMMapping.h | 7 +--- .../Source/Core/Mapping/FEMMapping.m | 35 +++++-------------- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index f46a3d2..72e137b 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -14,6 +14,7 @@ - (instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); + (instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); +- (id)initWithRootPath:(NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); - (instancetype)initWithObjectClass:(Class)objectClass NS_DESIGNATED_INITIALIZER; - (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER; @@ -47,10 +48,4 @@ - (id)representationFromExternalRepresentation:(id)externalRepresentation; -@end - -@interface FEMMapping (Obsolete) - -- (id)initWithRootPath:(NSString *)rootPath __attribute__((obsoleted)); - @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index a3a5731..d6adced 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -2,29 +2,16 @@ #import "FEMMapping.h" -#import "FEMAttributeMapping.h" -#import "FEMRelationshipMapping.h" -#import "FEMDeserializer.h" -#import "FEMManagedObjectStore.h" -#import "FEMAssignmentContextPrivate.h" - @implementation FEMMapping #pragma mark - Init -- (id)init { - self = [super init]; - if (self) { - _attributeMap = [NSMutableDictionary new]; - _relationshipMap = [NSMutableDictionary new]; - } - - return self; -} - - (instancetype)initWithObjectClass:(Class)objectClass { - self = [self init]; + self = [super init]; if (self) { + _attributeMap = [NSMutableDictionary new]; + _relationshipMap = [NSMutableDictionary new]; + _objectClass = objectClass; } @@ -32,8 +19,11 @@ - (instancetype)initWithObjectClass:(Class)objectClass { } - (instancetype)initWithEntityName:(NSString *)entityName { - self = [self init]; + self = [super init]; if (self) { + _attributeMap = [NSMutableDictionary new]; + _relationshipMap = [NSMutableDictionary new]; + _entityName = [entityName copy]; } @@ -161,13 +151,4 @@ - (id)representationFromExternalRepresentation:(id)externalRepresentation { return self.rootPath ? [externalRepresentation valueForKeyPath:self.rootPath] : externalRepresentation; } -@end - -@implementation FEMMapping (Obsolete) - -- (id)initWithRootPath:(NSString *)rootPath __attribute__((obsoleted)) { - @throw @"Obsolete"; - return nil; -} - @end \ No newline at end of file From 960f810d277cd642b2fbdb20e43398854b161833 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:06:35 +0300 Subject: [PATCH 15/95] Add Object Store --- .../Core/Deserializer/FEMDeserializer.h | 38 ++-- .../Core/Deserializer/FEMDeserializer.m | 183 +++++++++--------- .../Source/Core/Store/FEMManagedObjectStore.h | 10 +- .../Source/Core/Store/FEMManagedObjectStore.m | 10 +- .../Source/Core/Store/FEMObjectStore.h | 3 +- FastEasyMappingTests/Specs/FEMCacheSpec.m | 30 +-- .../Specs/FEMManagedObjectDeserializerSpec.m | 108 +++++------ 7 files changed, 187 insertions(+), 195 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 6aff757..8bb396e 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -2,38 +2,38 @@ #import -@protocol FEMDeserializerSource; - -@class FEMManagedObjectMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; +@class FEMObjectStore, FEMMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; @interface FEMDeserializer : NSObject -@property (nonatomic, strong, readonly) id source; -- (id)initWithDeserializerSource:(id)deserializerSource; +@property (nonatomic, strong, readonly) FEMObjectStore *store; +- (id)initWithStore:(FEMObjectStore *)store; -- (id)deserializeObject; +- (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; -- (NSArray *)deserializeCollection; +@end -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context; +@interface FEMDeserializer (Shortcut) -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping; ++ (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; ++ (id)fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; /** Get an array of managed objects from an external representation. If the objectMapping has - a primary key existing objects will be updated. This method is slow and it doesn't - delete obsolete objects, use - syncArrayOfObjectsFromExternalRepresentation:withMapping:fetchRequest:inManagedObjectContext: - instead. - */ +a primary key existing objects will be updated. This method is slow and it doesn't +delete obsolete objects, use +syncArrayOfObjectsFromExternalRepresentation:withMapping:fetchRequest:inManagedObjectContext: +instead. +*/ + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context; + usingMapping:(FEMMapping *)mapping + context:(NSManagedObjectContext *)context; + (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping + usingMapping:(FEMMapping *)mapping predicate:(NSPredicate *)predicate context:(NSManagedObjectContext *)context; + @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 0bf3ccc..9bfa145 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -2,25 +2,23 @@ #import "FEMDeserializer.h" -#import +@import CoreData; #import "FEMManagedObjectMapping.h" -#import "FEMAttributeMapping.h" #import "FEMTypeIntrospection.h" #import "NSArray+FEMPropertyRepresentation.h" -#import "FEMDeserializerSource.h" #import "FEMAttribute+Extension.h" -#import "FEMRelationship.h" +#import "FEMObjectStore.h" #import "FEMDefaultAssignmentContext.h" #import "FEMManagedObjectStore.h" @implementation FEMDeserializer -- (id)initWithDeserializerSource:(id)deserializerSource { - NSParameterAssert(deserializerSource != nil); +- (id)initWithStore:(FEMObjectStore *)store { + NSParameterAssert(store != nil); self = [super init]; if (self) { - _source = deserializerSource; + _store = store; } return self; @@ -28,35 +26,35 @@ - (id)initWithDeserializerSource:(id)deserializerSource { #pragma mark - Utility -- (id)extractRelationshipRepresentation:(FEMRelationship *)relationship fromExternalRepresentation:(id)externalRepresentation { - if (relationship.keyPath) return [externalRepresentation valueForKeyPath:relationship.keyPath]; - - return externalRepresentation; +- (id)extractRootFromRepresentation:(id)representation keyPath:(NSString *)keyPath { + if (keyPath.length > 0) { + return [representation valueForKeyPath:keyPath]; + } + + return representation; } -#pragma mark - IMP +#pragma mark - Deserialization IMP - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { for (FEMRelationship *relationship in mapping.relationships) { @autoreleasepool { - id relationshipRepresentation = [self extractRelationshipRepresentation:relationship fromExternalRepresentation:representation]; + id relationshipRepresentation = [self extractRootFromRepresentation:representation keyPath:relationship.keyPath]; if (relationshipRepresentation == nil) continue; id targetValue = nil; if (relationshipRepresentation != NSNull.null) { if (relationship.isToMany) { - targetValue = [self collectionFromRepresentation:relationshipRepresentation - usingMapping:relationship.objectMapping]; + targetValue = [self collectionFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; objc_property_t property = class_getProperty([object class], [relationship.property UTF8String]); targetValue = [targetValue fem_propertyRepresentation:property]; } else { - targetValue = [self objectFromRepresentation:relationshipRepresentation - usingMapping:relationship.objectMapping]; + targetValue = [self objectFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; } } - id context = [self.source newAssignmentContext]; + id context = [self.store newAssignmentContext]; context.destinationObject = object; context.relationship = relationship; context.sourceRelationshipValue = [object valueForKey:relationship.property]; @@ -68,7 +66,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } } -- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { +- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { for (FEMAttributeMapping *attributeMapping in mapping.attributes) { [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; } @@ -78,26 +76,26 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation return object; } -- (id)objectFromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { - id object = [self.source registeredObjectForRepresentation:representation mapping:mapping]; +- (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + id object = [self.store registeredObjectForRepresentation:representation mapping:mapping]; if (!object) { - object = [self.source newObjectForMapping:mapping]; + object = [self.store newObjectForMapping:mapping]; } - [self fulfillObject:object fromRepresentation:representation usingMapping:mapping]; + [self fulfillObject:object fromRepresentation:representation mapping:mapping]; - if ([self.source shouldRegisterObject:object forMapping:mapping]) { - [self.source registerObject:object forMapping:mapping]; + if ([self.store canRegisterObject:object forMapping:mapping]) { + [self.store registerObject:object forMapping:mapping]; } return object; } -- (NSArray *)collectionFromRepresentation:(id)representation usingMapping:(FEMMapping *)mapping { - NSMutableArray *output = [NSMutableArray array]; +- (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { + NSMutableArray *output = [[NSMutableArray alloc] initWithCapacity:representation.count]; for (id objectRepresentation in representation) { @autoreleasepool { - id object = [self objectFromRepresentation:objectRepresentation usingMapping:mapping]; + id object = [self objectFromRepresentation:objectRepresentation mapping:mapping]; [output addObject:object]; } } @@ -106,86 +104,83 @@ - (NSArray *)collectionFromRepresentation:(id)representation usingMapping:(FEMMa #pragma mark - Public -- (id)deserializeObject { - id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; - return [self objectFromRepresentation:representation usingMapping:self.source.mapping]; -} -- (id)fulfillObject:(id)object { - id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; - return [self fulfillObject:object fromRepresentation:representation usingMapping:self.source.mapping]; +- (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + return [self objectFromRepresentation:root mapping:mapping]; } -- (NSArray *)deserializeCollection { - id representation = [self.source.mapping representationFromExternalRepresentation:self.source.externalRepresentation]; - return [self collectionFromRepresentation:representation usingMapping:self.source.mapping]; +- (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + return [self fulfillObject:object fromRepresentation:root mapping:mapping]; } -#pragma mark - Deserialization - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - managedObjectContext:context]; - FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; - - return [deserializer deserializeObject]; +- (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { + id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + return [self collectionFromRepresentation:root mapping:mapping]; } -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { - FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - managedObjectContext:object.managedObjectContext]; - FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; +@end - return [deserializer fulfillObject:object]; -} +@implementation FEMDeserializer (Shortcut) -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - managedObjectContext:context]; - FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithDeserializerSource:source]; - - return [deserializer deserializeCollection]; -} - -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context { -// NSParameterAssert(mapping.primaryKey != nil); +//+ (id)deserializeObjectFromRepresentation:(NSDictionary *)representation +// mapping:(FEMMapping *)mapping +// context:(NSManagedObjectContext *)context { +// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:context]; +// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; // -// FEMAttributeMapping *primaryKeyMapping = [mapping primaryKeyMapping]; +// return [deserializer deserializeObject]; +//} // -// NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; -// [request setPredicate:predicate]; +//+ (id)fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { +// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:object.managedObjectContext]; +// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; // -// NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; -// NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; -// NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects -// forKeys:initialObjectsKeys]; +// return [deserializer fulfillObject:object]; +//} // -// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; -// FEMCacheSetCurrent(cache); -// NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation -// usingMapping:mapping -// context:context]; -// FEMCacheRemoveCurrent(); +//+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation +// usingMapping:(FEMManagedObjectMapping *)mapping +// context:(NSManagedObjectContext *)context { +// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:context]; +// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; // -// NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; -// [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; +// return [deserializer deserializeCollection]; +//} // -// for (NSManagedObject *object in initialObjectsMap.allValues) { -// [context deleteObject:object]; -// } -// -// return output; - return nil; -} +//+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation +// usingMapping:(FEMManagedObjectMapping *)mapping +// predicate:(NSPredicate *)predicate +// context:(NSManagedObjectContext *)context { +//// NSParameterAssert(mapping.primaryKey != nil); +//// +//// FEMAttributeMapping *primaryKeyMapping = [mapping primaryKeyMapping]; +//// +//// NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; +//// [request setPredicate:predicate]; +//// +//// NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; +//// NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; +//// NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects +//// forKeys:initialObjectsKeys]; +//// +//// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; +//// FEMCacheSetCurrent(cache); +//// NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation +//// usingMapping:mapping +//// context:context]; +//// FEMCacheRemoveCurrent(); +//// +//// NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; +//// [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; +//// +//// for (NSManagedObject *object in initialObjectsMap.allValues) { +//// [context deleteObject:object]; +//// } +//// +//// return output; +// return nil; +//} @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h index 1146175..4e53c01 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h @@ -3,14 +3,12 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -#import "FEMDeserializerSource.h" +#import "FEMObjectStore.h" -@class FEMManagedObjectMapping, NSManagedObjectContext; +@class NSManagedObjectContext; -@interface FEMManagedObjectStore : NSObject +@interface FEMManagedObjectStore : FEMObjectStore -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping - externalRepresentation:(id)externalRepresentation - managedObjectContext:(NSManagedObjectContext *)managedObjectContext; +- (instancetype)initWithContext:(NSManagedObjectContext *)context; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 1bfdfb5..08b6cb7 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -5,7 +5,7 @@ #import "FEMManagedObjectStore.h" -@import CoreData.h; +@import CoreData; #import "FEMManagedObjectMapping.h" #import "FEMCache.h" @@ -23,12 +23,10 @@ @implementation FEMManagedObjectStore { #pragma mark - Init -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping externalRepresentation:(id)externalRepresentation managedObjectContext:(NSManagedObjectContext *)managedObjectContext { +- (instancetype)initWithContext:(NSManagedObjectContext *)context { self = [super init]; if (self) { - _mapping = mapping; - _externalRepresentation = externalRepresentation; - _managedObjectContext = managedObjectContext; + _managedObjectContext = context; _cache = [[FEMCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; } @@ -55,7 +53,7 @@ - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { return [_cache existingObjectsForMapping:mapping]; } -- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping { +- (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping { return mapping.primaryKey != nil && [object isInserted]; } diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index ed88cce..73b1e63 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -12,11 +12,12 @@ @interface FEMObjectStore : NSObject - (id)newObjectForMapping:(FEMMapping *)mapping; + - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; - (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; -- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping; +- (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping; - (id)newAssignmentContext; diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 9c4577e..1beba69 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -86,9 +86,9 @@ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] beNil]; - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation + mapping:mapping + context:context]; [cache addExistingObject:car usingMapping:mapping]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] equal:car]; @@ -97,9 +97,9 @@ it(@"should return registered object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation + mapping:mapping + context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [[[context objectRegisteredForID:car.objectID] should] equal:car]; @@ -110,9 +110,9 @@ it(@"should return saved object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation + mapping:mapping + context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [context MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:context]) should] equal:@1]; @@ -148,18 +148,18 @@ }); it(@"should return nil for missing nested object", ^{ - [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + [FEMDeserializer deserializeObjectFromRepresentation:representation + mapping:mapping + context:context]; id missingObjectRepresentation = @{@"id": @2}; [[[cache existingObjectForRepresentation:missingObjectRepresentation mapping:carMapping] should] beNil]; }); it(@"should return existing nested object", ^{ - Person *person = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Person *person = [FEMDeserializer deserializeObjectFromRepresentation:representation + mapping:mapping + context:context]; [[[cache existingObjectForRepresentation:representation[@"car"] mapping:carMapping] should] equal:person.car]; }); }); diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index 9cecedf..7eb7fd0 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -45,9 +45,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMapping] + context:moc]; }); specify(^{ @@ -82,9 +82,9 @@ @"year" : @"2013" }; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; }); specify(^{ @@ -124,9 +124,9 @@ oldCar.model = @""; externalRepresentation = @{@"id" : @(1), @"model" : @"i30",}; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; }); specify(^{ @@ -153,9 +153,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithRootKeyMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carWithRootKeyMapping] + context:moc]; externalRepresentation = [externalRepresentation objectForKey:@"car"]; }); @@ -179,9 +179,9 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carNestedAttributesMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carNestedAttributesMapping] + context:moc]; }); specify(^{ @@ -205,9 +205,9 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithDateMapping] - context:moc]; + car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider carWithDateMapping] + context:moc]; }); specify(^{ @@ -245,9 +245,9 @@ expectedCar.year = @"2013"; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; + person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider personMapping] + context:moc]; }); specify(^{ @@ -270,9 +270,9 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; + person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation + mapping:[MappingProvider personMapping] + context:moc]; }); specify(^{ @@ -314,7 +314,7 @@ beforeAll(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; FEMManagedObjectMapping *mapping = [MappingProvider personMapping]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:moc]; + person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation mapping:mapping context:moc]; }); context(@"to-one", ^{ @@ -356,9 +356,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyAssign; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -366,9 +366,9 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; + Person *person_v2 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v2 + mapping:mapping + context:moc]; [[person_v1 should] equal:person_v2]; Car *car_v2 = person_v1.car; @@ -383,9 +383,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectMerge; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -393,9 +393,9 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; + Person *person_v2 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v2 + mapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[person_v1 should] equal:person_v2]; @@ -411,9 +411,9 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectReplace; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; Car *car_v1 = person_v1.car; [moc MR_saveToPersistentStoreAndWait]; @@ -421,8 +421,8 @@ [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; [FEMDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping]; + fromRepresentation:externalRepresentation_v1 + mapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -450,19 +450,19 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionMerge; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; NSSet *phones_1 = person_v1.phones; [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - + [FEMDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping]; + fromRepresentation:externalRepresentation_v2 + mapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@3]; @@ -476,19 +476,19 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionReplace; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; + Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; NSSet *phones_1 = person_v1.phones; [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - + [FEMDeserializer fillObject:person_v1 - fromExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping]; + fromRepresentation:externalRepresentation_v2 + mapping:mapping]; [moc MR_saveToPersistentStoreAndWait]; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; From 4d493cb16de8aa1b04f6e9c988c7a80a40fd5162 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:10:25 +0300 Subject: [PATCH 16/95] Add representation utility for root extracting --- FastEasyMapping.xcodeproj/project.pbxproj | 10 ++++++++++ .../Source/Utility/FEMRepresentationUtility.h | 8 ++++++++ .../Source/Utility/FEMRepresentationUtility.m | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 FastEasyMapping/Source/Utility/FEMRepresentationUtility.h create mode 100644 FastEasyMapping/Source/Utility/FEMRepresentationUtility.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 0d73f70..2e387bf 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -13,7 +13,9 @@ 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; + 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; @@ -25,6 +27,7 @@ 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; + 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; 2C11898E18D07356005D8D91 /* FEMManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2C375F1318CCD3FB00FCB8EA /* EasyMappingCoreDataExample.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */; }; 2C375F1418CCD3FB00FCB8EA /* Car.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED767EE6E89A487714CDF8 /* Car.m */; }; @@ -125,6 +128,7 @@ 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectStore.m; sourceTree = ""; }; 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDefaultAssignmentContext.h; sourceTree = ""; }; + 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRepresentationUtility.m; sourceTree = ""; }; 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectStore.h; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; @@ -145,6 +149,7 @@ 1D6A3D8BC461265BD6E7959C /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; + 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRepresentationUtility.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = EasyMappingCoreDataExample.xcdatamodel; sourceTree = ""; }; 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FastEasyMappingTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -349,6 +354,8 @@ 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */, 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */, 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */, + 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */, + 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */, ); path = Utility; sourceTree = ""; @@ -614,6 +621,7 @@ 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -737,6 +745,7 @@ ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */, 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, + 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -772,6 +781,7 @@ 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */, 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */, 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */, + 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h new file mode 100644 index 0000000..9c8bdb9 --- /dev/null +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h @@ -0,0 +1,8 @@ +// +// Created by zen on 12/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation; + +FOUNDATION_EXTERN id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m new file mode 100644 index 0000000..f53e22c --- /dev/null +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -0,0 +1,14 @@ +// +// Created by zen on 12/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +#import "FEMRepresentationUtility.h" + +id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { + if (keyPath.length > 0) { + return [representation valueForKeyPath:keyPath]; + } + + return representation; +} \ No newline at end of file From 542105b725b6eb227953b461e142ebd1a8148b65 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:11:03 +0300 Subject: [PATCH 17/95] Simplify deserialiser's root extraction by representation utility --- .../Core/Deserializer/FEMDeserializer.m | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 9bfa145..5cf7ae1 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -11,6 +11,8 @@ #import "FEMObjectStore.h" #import "FEMDefaultAssignmentContext.h" #import "FEMManagedObjectStore.h" +#import "FEMRepresentationUtility.h" +#import "KWExample.h" @implementation FEMDeserializer @@ -24,22 +26,12 @@ - (id)initWithStore:(FEMObjectStore *)store { return self; } -#pragma mark - Utility - -- (id)extractRootFromRepresentation:(id)representation keyPath:(NSString *)keyPath { - if (keyPath.length > 0) { - return [representation valueForKeyPath:keyPath]; - } - - return representation; -} - #pragma mark - Deserialization IMP - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { for (FEMRelationship *relationship in mapping.relationships) { @autoreleasepool { - id relationshipRepresentation = [self extractRootFromRepresentation:representation keyPath:relationship.keyPath]; + id relationshipRepresentation = FEMRepresentationRootForKeyPath(representation, relationship.keyPath); if (relationshipRepresentation == nil) continue; id targetValue = nil; @@ -106,17 +98,17 @@ - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEM - (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); return [self objectFromRepresentation:root mapping:mapping]; } - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); return [self fulfillObject:object fromRepresentation:root mapping:mapping]; } - (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { - id root = [self extractRootFromRepresentation:representation keyPath:mapping.rootPath]; + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); return [self collectionFromRepresentation:root mapping:mapping]; } From 885a4f5d50f9b38f0a6e92b56c1cf94ae2f2c7b2 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:11:19 +0300 Subject: [PATCH 18/95] Remove Cache thread storage --- FastEasyMapping/Source/Core/Cache/FEMCache.h | 4 ---- FastEasyMapping/Source/Core/Cache/FEMCache.m | 22 +------------------ .../Source/Core/Store/FEMObjectStore.h | 2 +- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.h b/FastEasyMapping/Source/Core/Cache/FEMCache.h index 529addb..eb54885 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.h +++ b/FastEasyMapping/Source/Core/Cache/FEMCache.h @@ -4,10 +4,6 @@ @class FEMCache, FEMManagedObjectMapping, NSManagedObjectContext; -OBJC_EXTERN FEMCache *FEMCacheGetCurrent(); -OBJC_EXTERN void FEMCacheSetCurrent(FEMCache *cache); -OBJC_EXTERN void FEMCacheRemoveCurrent(); - @interface FEMCache : NSObject @property (nonatomic, strong, readonly) NSManagedObjectContext *context; diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.m b/FastEasyMapping/Source/Core/Cache/FEMCache.m index 725a1ba..d72b150 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMCache.m @@ -10,26 +10,6 @@ @class FEMCache; -NSString *const EMKLookupCacheCurrentKey = @"com.yalantis.FastEasyMapping.cache"; - -FEMCache *FEMCacheGetCurrent() { - return [[NSThread currentThread] threadDictionary][EMKLookupCacheCurrentKey]; -} - -void FEMCacheSetCurrent(FEMCache *cache) { - NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary]; - NSCParameterAssert(cache); - NSCParameterAssert(!threadDictionary[EMKLookupCacheCurrentKey]); - - threadDictionary[EMKLookupCacheCurrentKey] = cache; -} - -void FEMCacheRemoveCurrent() { - NSMutableDictionary *threadDictionary = [[NSThread currentThread] threadDictionary]; - NSCParameterAssert(threadDictionary[EMKLookupCacheCurrentKey]); - [threadDictionary removeObjectForKey:EMKLookupCacheCurrentKey]; -} - @implementation FEMCache { NSManagedObjectContext *_context; @@ -74,7 +54,7 @@ - (void)inspectObjectRepresentation:(id)objectRepresentation usingMapping:(FEMMa } } - for (FEMRelationshipMapping *relationshipMapping in mapping.relationshipMappings) { + for (FEMRelationship *relationshipMapping in mapping.relationships) { id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:objectRepresentation]; if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { [self inspectRepresentation:relationshipRepresentation diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 73b1e63..4e51e9c 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -3,7 +3,7 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation.h; +@import Foundation; @class FEMMapping; From 8477730acca48b06a1bb4af67ac6e14b580b85ee Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 12 May 2015 18:23:58 +0300 Subject: [PATCH 19/95] Rename FEMCache to FEMManagedObjectCache --- FastEasyMapping.xcodeproj/project.pbxproj | 16 ++++----- .../{FEMCache.h => FEMManagedObjectCache.h} | 4 +-- .../{FEMCache.m => FEMManagedObjectCache.m} | 33 ++++++++++--------- .../Core/Deserializer/FEMDeserializer.m | 2 +- .../Source/Core/Store/FEMManagedObjectStore.m | 6 ++-- FastEasyMappingTests/Specs/FEMCacheSpec.m | 12 +++---- 6 files changed, 37 insertions(+), 36 deletions(-) rename FastEasyMapping/Source/Core/Cache/{FEMCache.h => FEMManagedObjectCache.h} (86%) rename FastEasyMapping/Source/Core/Cache/{FEMCache.m => FEMManagedObjectCache.m} (80%) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 2e387bf..515481a 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -85,13 +85,13 @@ 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED779509541DFE7A36679D /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED769040647781DD8B196D /* NSObject+FEMKVCExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED770C14BAB15CA7926116 /* NSObject+FEMKVCExtension.m */; }; - 69ED756EBF9D955A7B6A580A /* FEMCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7D24C1EE78C03CAB9C9B /* FEMCache.m */; }; + 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7D24C1EE78C03CAB9C9B /* FEMManagedObjectCache.m */; }; 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */; }; 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; - 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; @@ -223,9 +223,9 @@ 69ED7C1B2AB96554F9FDF10B /* FEMSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMSerializer.h; sourceTree = ""; }; 69ED7CB8A80C99BF8D7413F6 /* FastEasyMappingTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.info; path = "FastEasyMappingTests-Info.plist"; sourceTree = ""; }; 69ED7CF6DFFBDF7A0BF32AFC /* NativeChild.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = NativeChild.json; sourceTree = ""; }; - 69ED7D24C1EE78C03CAB9C9B /* FEMCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCache.m; sourceTree = ""; }; + 69ED7D24C1EE78C03CAB9C9B /* FEMManagedObjectCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectCache.m; sourceTree = ""; }; 69ED7D96C7E8C393B9DEB695 /* Female.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Female.json; sourceTree = ""; }; - 69ED7DE30D50997F9408F36E /* FEMCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMCache.h; sourceTree = ""; }; + 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectCache.h; sourceTree = ""; }; 69ED7DE7AE4C126B96E6BD93 /* Person.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Person.h; sourceTree = ""; }; 69ED7E3F8292CA5FAB383E45 /* PhoneNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PhoneNative.m; sourceTree = ""; }; 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMTypeIntrospection.h; sourceTree = ""; }; @@ -579,8 +579,8 @@ 69ED7CB4B4B9CD8DDF958D64 /* Cache */ = { isa = PBXGroup; children = ( - 69ED7D24C1EE78C03CAB9C9B /* FEMCache.m */, - 69ED7DE30D50997F9408F36E /* FEMCache.h */, + 69ED7D24C1EE78C03CAB9C9B /* FEMManagedObjectCache.m */, + 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */, ); path = Cache; sourceTree = ""; @@ -614,7 +614,7 @@ ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, - 69ED7E8934131F087C5492A3 /* FEMCache.h in Headers */, + 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, @@ -739,7 +739,7 @@ 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, - 69ED756EBF9D955A7B6A580A /* FEMCache.m in Sources */, + 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.h b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h similarity index 86% rename from FastEasyMapping/Source/Core/Cache/FEMCache.h rename to FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h index eb54885..701c498 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.h +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h @@ -2,9 +2,9 @@ #import -@class FEMCache, FEMManagedObjectMapping, NSManagedObjectContext; +@class FEMManagedObjectCache, FEMManagedObjectMapping, NSManagedObjectContext; -@interface FEMCache : NSObject +@interface FEMManagedObjectCache : NSObject @property (nonatomic, strong, readonly) NSManagedObjectContext *context; diff --git a/FastEasyMapping/Source/Core/Cache/FEMCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m similarity index 80% rename from FastEasyMapping/Source/Core/Cache/FEMCache.m rename to FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index d72b150..90addf0 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -1,16 +1,18 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project -#import "FEMCache.h" +#import "FEMManagedObjectCache.h" #import "FEMManagedObjectMapping.h" #import "FEMRelationship.h" #import "FEMAttribute.h" #import "FEMAttribute+Extension.h" +#import "FEMRepresentationUtility.h" +#import "FEMObjectMapping.h" #import -@class FEMCache; +@class FEMManagedObjectCache; -@implementation FEMCache { +@implementation FEMManagedObjectCache { NSManagedObjectContext *_context; NSMutableDictionary *_lookupKeysMap; @@ -35,7 +37,7 @@ - (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping _lookupObjectsMap = [NSMutableDictionary new]; [self prepareMappingLookupStructure:mapping]; - [self inspectExternalRepresentation:externalRepresentation usingMapping:mapping]; + [self inspectExternalRepresentation:externalRepresentation mapping:mapping]; } return self; @@ -43,7 +45,7 @@ - (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping #pragma mark - Inspection -- (void)inspectObjectRepresentation:(id)objectRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { +- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMManagedObjectMapping *)mapping { if (mapping.primaryKey) { FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; NSParameterAssert(primaryKeyMapping); @@ -55,21 +57,20 @@ - (void)inspectObjectRepresentation:(id)objectRepresentation usingMapping:(FEMMa } for (FEMRelationship *relationshipMapping in mapping.relationships) { - id relationshipRepresentation = [relationshipMapping representationFromExternalRepresentation:objectRepresentation]; + id relationshipRepresentation = FEMRepresentationRootForKeyPath(objectRepresentation, relationshipMapping.keyPath); if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { - [self inspectRepresentation:relationshipRepresentation - usingMapping:(FEMManagedObjectMapping *)relationshipMapping.objectMapping]; + [self inspectRepresentation:relationshipRepresentation mapping:relationshipMapping.objectMapping]; } } } -- (void)inspectRepresentation:(id)representation usingMapping:(FEMManagedObjectMapping *)mapping { +- (void)inspectRepresentation:(id)representation mapping:(FEMObjectMapping *)mapping { if ([representation isKindOfClass:NSArray.class]) { for (id objectRepresentation in representation) { - [self inspectObjectRepresentation:objectRepresentation usingMapping:mapping]; + [self inspectObjectRepresentation:objectRepresentation mapping:mapping]; } } else if ([representation isKindOfClass:NSDictionary.class]) { - [self inspectObjectRepresentation:representation usingMapping:mapping]; + [self inspectObjectRepresentation:representation mapping:mapping]; } else { NSAssert( NO, @@ -79,23 +80,23 @@ - (void)inspectRepresentation:(id)representation usingMapping:(FEMManagedObjectM } } -- (void)inspectExternalRepresentation:(id)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { +- (void)inspectExternalRepresentation:(id)externalRepresentation mapping:(FEMManagedObjectMapping *)mapping { id representation = [mapping representationFromExternalRepresentation:externalRepresentation]; - [self inspectRepresentation:representation usingMapping:mapping]; + [self inspectRepresentation:representation mapping:mapping]; } -- (void)collectEntityNames:(NSMutableSet *)namesCollection usingMapping:(FEMManagedObjectMapping *)mapping { +- (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMManagedObjectMapping *)mapping { [namesCollection addObject:mapping.entityName]; for (FEMRelationship *relationshipMapping in mapping.relationships) { - [self collectEntityNames:namesCollection usingMapping:(FEMManagedObjectMapping *)relationshipMapping.objectMapping]; + [self collectEntityNames:namesCollection mapping:relationshipMapping.objectMapping]; } } - (void)prepareMappingLookupStructure:(FEMManagedObjectMapping *)mapping { NSMutableSet *entityNames = [NSMutableSet new]; - [self collectEntityNames:entityNames usingMapping:mapping]; + [self collectEntityNames:entityNames mapping:mapping]; for (NSString *entityName in entityNames) { _lookupKeysMap[entityName] = [NSMutableSet new]; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 5cf7ae1..12289d4 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -157,7 +157,7 @@ @implementation FEMDeserializer (Shortcut) //// NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects //// forKeys:initialObjectsKeys]; //// -//// FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; +//// FEMManagedObjectCache *cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; //// FEMCacheSetCurrent(cache); //// NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation //// usingMapping:mapping diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 08b6cb7..df13012 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -8,11 +8,11 @@ @import CoreData; #import "FEMManagedObjectMapping.h" -#import "FEMCache.h" +#import "FEMManagedObjectCache.h" #import "FEMDefaultAssignmentContext.h" @implementation FEMManagedObjectStore { - FEMCache *_cache; + FEMManagedObjectCache *_cache; NSManagedObjectContext *_managedObjectContext; FEMManagedObjectMapping *_mapping; @@ -28,7 +28,7 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { if (self) { _managedObjectContext = context; - _cache = [[FEMCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; + _cache = [[FEMManagedObjectCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; } return self; diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 1beba69..11c22b2 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -9,7 +9,7 @@ #import "Person.h" #import "FEMManagedObjectMapping.h" -#import "FEMCache.h" +#import "FEMManagedObjectCache.h" #import "MappingProvider.h" #import "Car.h" @@ -41,7 +41,7 @@ id representation = [CMFixture buildUsingFixture:@"Car"]; id mapping = [MappingProvider carMapping]; - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping + FEMManagedObjectCache *cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; @@ -52,7 +52,7 @@ describe(@"object retrieval", ^{ __block NSDictionary *representation = nil; __block FEMManagedObjectMapping *mapping = nil; - __block FEMCache *cache = nil; + __block FEMManagedObjectCache *cache = nil; beforeEach(^{ representation = @{ @"id": @1, @@ -61,7 +61,7 @@ }; mapping = [MappingProvider carMappingWithPrimaryKey]; - cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; + cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; }); afterEach(^{ mapping = nil; @@ -127,7 +127,7 @@ }); describe(@"nested object retrieval", ^{ - __block FEMCache *cache = nil; + __block FEMManagedObjectCache *cache = nil; __block NSDictionary *representation = nil; __block FEMManagedObjectMapping *mapping = nil; __block FEMManagedObjectMapping *carMapping = nil; @@ -136,7 +136,7 @@ representation = [CMFixture buildUsingFixture:@"PersonWithCar_1"]; mapping = [MappingProvider personWithCarMapping]; - cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; + cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; carMapping = (id) [mapping relationshipForProperty:@"car"].objectMapping; }); From 70ba18d04002b49b3bf4bf2619756d70f21a35e7 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:14:39 +0300 Subject: [PATCH 20/95] Introduce FEMRelationshipAssignmentContext + Delegate --- FastEasyMapping.xcodeproj/project.pbxproj | 28 +++++------ .../Assignment Policy/FEMAssignmentContext.h | 21 -------- .../FEMAssignmentContextPrivate.h | 17 ------- .../Assignment Policy/FEMAssignmentPolicy.h | 4 +- .../Assignment Policy/FEMAssignmentPolicy.m | 16 +++--- .../FEMDefaultAssignmentContext.h | 16 ------ .../FEMDefaultAssignmentContext.m | 34 ------------- ...EMRelationshipAssignmentContext+Internal.h | 18 +++++++ .../FEMRelationshipAssignmentContext.h | 31 ++++++++++++ .../FEMRelationshipAssignmentContext.m | 49 +++++++++++++++++++ .../Source/Core/Store/FEMObjectStore.h | 16 +++--- .../Source/Core/Store/FEMObjectStore.m | 34 ++++++++++++- 12 files changed, 164 insertions(+), 120 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h delete mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h create mode 100644 FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 515481a..046569d 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -10,15 +10,17 @@ 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; + 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; - 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; - 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */; }; + 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; + 1D6A3846E3E87F496676A2A6 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; + 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; }; @@ -126,29 +128,27 @@ 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectStore.m; sourceTree = ""; }; 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectStore.h; sourceTree = ""; }; 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; + 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRelationshipAssignmentContext.m; sourceTree = ""; }; 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectStore.m; sourceTree = ""; }; - 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDefaultAssignmentContext.h; sourceTree = ""; }; 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRepresentationUtility.m; sourceTree = ""; }; 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectStore.h; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; - 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMDefaultAssignmentContext.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttributeMapping.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; + 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipAssignmentContext.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; - 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContextPrivate.h; sourceTree = ""; }; 1D6A3ACBBC8E66609F169E94 /* Person_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_2.json; sourceTree = ""; }; 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMExcludableCollection.h; sourceTree = ""; }; 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; - 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentContext.h; sourceTree = ""; }; - 1D6A3D8BC461265BD6E7959C /* FEMDeserializerSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMDeserializerSource.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; + 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FEMRelationshipAssignmentContext+Internal.h"; sourceTree = ""; }; 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRepresentationUtility.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = EasyMappingCoreDataExample.xcdatamodel; sourceTree = ""; }; @@ -280,10 +280,9 @@ children = ( 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */, 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */, - 1D6A3C9FDCCD85AD33CDD0C5 /* FEMAssignmentContext.h */, - 1D6A3ACA014382204282A5EF /* FEMAssignmentContextPrivate.h */, - 1D6A33D580E7519EC8A8A7D7 /* FEMDefaultAssignmentContext.m */, - 1D6A322DB97A232A2A2FB6DD /* FEMDefaultAssignmentContext.h */, + 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */, + 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */, + 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */, ); path = "Assignment Policy"; sourceTree = ""; @@ -291,7 +290,6 @@ 1D6A3B055A492274473025DA /* Store */ = { isa = PBXGroup; children = ( - 1D6A3D8BC461265BD6E7959C /* FEMDeserializerSource.h */, 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */, 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */, 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */, @@ -617,11 +615,12 @@ 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, - 1D6A36BB7D0E7D8E55831947 /* FEMDefaultAssignmentContext.h in Headers */, 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, + 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, + 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -743,9 +742,9 @@ 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, - 1D6A375B1323707A0551C1C9 /* FEMDefaultAssignmentContext.m in Sources */, 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, + 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -782,6 +781,7 @@ 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */, 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */, 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */, + 1D6A3846E3E87F496676A2A6 /* FEMRelationshipAssignmentContext.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h deleted file mode 100644 index 4d0e158..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContext.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -@import Foundation; - -@class FEMRelationship; - -@protocol FEMAssignmentContext - -@required -@property (nonatomic, readonly) id destinationObject; -@property (nonatomic, readonly) FEMRelationship *relationship; - -@property (nonatomic, readonly) id sourceRelationshipValue; -@property (nonatomic, readonly) id targetRelationshipValue; - -- (void)deleteRelationshipObject:(id)object; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h deleted file mode 100644 index 6aee0af..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentContextPrivate.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -#import "FEMAssignmentContext.h" - -@protocol FEMAssignmentContextPrivate - -@required -@property (nonatomic, strong) id destinationObject; -@property (nonatomic) FEMRelationship *relationship; - -@property (nonatomic, strong) id sourceRelationshipValue; -@property (nonatomic, strong) id targetRelationshipValue; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index f49ec33..ff03d41 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -5,9 +5,9 @@ @import Foundation; -@protocol FEMAssignmentContext; +@class FEMRelationshipAssignmentContext; -typedef id (^FEMAssignmentPolicy)(id context); +typedef id (^FEMAssignmentPolicy)(FEMRelationshipAssignmentContext *context); OBJC_EXTERN FEMAssignmentPolicy FEMAssignmentPolicyAssign; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index b4e2ab5..c8a7444 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -5,19 +5,19 @@ #import "FEMAssignmentPolicy.h" -#import "FEMAssignmentContext.h" +#import "FEMRelationshipAssignmentContext.h" #import "FEMExcludableCollection.h" #import "FEMMergeableCollection.h" -FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id (id context) { +FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id(FEMRelationshipAssignmentContext *context) { return context.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id (id context) { +FEMAssignmentPolicy FEMAssignmentPolicyObjectMerge = ^id(FEMRelationshipAssignmentContext *context) { return context.targetRelationshipValue ?: context.sourceRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id (id context) { +FEMAssignmentPolicy FEMAssignmentPolicyCollectionMerge = ^id(FEMRelationshipAssignmentContext *context) { if (!context.targetRelationshipValue) return context.sourceRelationshipValue; NSCAssert( @@ -30,7 +30,7 @@ return [context.targetRelationshipValue collectionByMergingObjects:context.sourceRelationshipValue]; }; -FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id (id context) { +FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace = ^id(FEMRelationshipAssignmentContext *context) { if (context.sourceRelationshipValue && ![context.sourceRelationshipValue isEqual:context.targetRelationshipValue]) { [context deleteRelationshipObject:context.sourceRelationshipValue]; } @@ -38,18 +38,18 @@ return context.targetRelationshipValue; }; -FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id (id context) { +FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace = ^id(FEMRelationshipAssignmentContext *context) { if (!context.sourceRelationshipValue) return context.targetRelationshipValue; if (context.targetRelationshipValue) { NSCAssert( - [context.sourceRelationshipValue conformsToProtocol:@ protocol(FEMExcludableCollection)], + [context.sourceRelationshipValue conformsToProtocol:@protocol(FEMExcludableCollection)], @"Collection %@ should support protocol %@", NSStringFromClass([context.targetRelationshipValue class]), NSStringFromProtocol(@protocol(FEMExcludableCollection)) ); - id objectsToDelete = [(id)context.sourceRelationshipValue collectionByExcludingObjects:context.targetRelationshipValue]; + id objectsToDelete = [(id ) context.sourceRelationshipValue collectionByExcludingObjects:context.targetRelationshipValue]; for (id object in objectsToDelete) { [context deleteRelationshipObject:object]; } diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h deleted file mode 100644 index 91e13a0..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Created by zen on 15/06/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -@import Foundation; - -#import "FEMAssignmentContextPrivate.h" - -@class NSManagedObjectContext; - -@interface FEMDefaultAssignmentContext : NSObject - -- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m deleted file mode 100644 index 8d5dc24..0000000 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMDefaultAssignmentContext.m +++ /dev/null @@ -1,34 +0,0 @@ -// -// Created by zen on 15/06/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -#import "FEMDefaultAssignmentContext.h" -#import "FEMAssignmentContext.h" - -@import CoreData; - -@implementation FEMDefaultAssignmentContext { - NSManagedObjectContext *_managedObjectContext; -} - -@synthesize destinationObject = _destinationObject; -@synthesize relationshipMapping = _relationshipMapping; -@synthesize sourceRelationshipValue = _existingRelationshipValue; -@synthesize targetRelationshipValue = _targetRelationshipValue; - -#pragma mark - Init - -- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext { - self = [super init]; - if (self) { - _managedObjectContext = managedObjectContext; - } - - return self; -} - -- (void)deleteRelationshipObject:(id)object { - [_managedObjectContext deleteObject:object]; -} -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h new file mode 100644 index 0000000..3b07880 --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h @@ -0,0 +1,18 @@ +// +// Created by zen on 13/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation; + +#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 \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h new file mode 100644 index 0000000..139324a --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h @@ -0,0 +1,31 @@ +// +// Created by zen on 13/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation; + +@class FEMRelationship, FEMObjectStore, FEMRelationshipAssignmentContext; + +@protocol FEMRelationshipAssignmentContextDelegate +@required + +- (void)assignmentContext:(FEMRelationshipAssignmentContext *)context deletedObject:(id)object; + +@end + + +@interface FEMRelationshipAssignmentContext: NSObject + +@property (nonatomic, unsafe_unretained, readonly) FEMObjectStore *store; +- (instancetype)initWithStore:(FEMObjectStore *)store; + +@property (nonatomic, strong, readonly) id destinationObject; +@property (nonatomic, strong, readonly) FEMRelationship *relationship; + +@property (nonatomic, strong, readonly) id sourceRelationshipValue; +@property (nonatomic, strong, readonly) id targetRelationshipValue; + +- (void)deleteRelationshipObject:(id)object; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.m new file mode 100644 index 0000000..ce895aa --- /dev/null +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.m @@ -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 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 \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 4e51e9c..907d792 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -5,20 +5,22 @@ @import Foundation; +#import "FEMRelationshipAssignmentContext.h" + @class FEMMapping; -@protocol FEMAssignmentContextPrivate; +@interface FEMObjectStore : NSObject -@interface FEMObjectStore : NSObject +- (NSArray *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction; - (id)newObjectForMapping:(FEMMapping *)mapping; +- (FEMRelationshipAssignmentContext *)newAssignmentContext; -- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; -- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; -- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; - +- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping; - (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping; +- (BOOL)deleteRegisteredObject:(id)object forMapping:(FEMMapping *)mapping; -- (id)newAssignmentContext; +- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; +- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m index 8baaab0..56577b2 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -6,8 +6,40 @@ #import "FEMObjectStore.h" #import "FEMMapping.h" #import "FEMAssignmentContextPrivate.h" +#import "FEMRelationshipAssignmentContext.h" -@implementation FEMObjectStore { +@implementation FEMObjectStore +- (NSArray *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { + return nil; } + +- (id)newObjectForMapping:(FEMMapping *)mapping { + return [[mapping.objectClass alloc] init]; +} + +- (id)newAssignmentContext { + return +} + +- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping { + +} + +- (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping { + +} + +- (BOOL)deleteRegisteredObject:(id)object forMapping:(FEMMapping *)mapping { + +} + +- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { + +} + +- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { + +} + @end \ No newline at end of file From aab092ef1b710fae1e47e1e81e1bc1bad00ef9c2 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:14:53 +0300 Subject: [PATCH 21/95] Minor naming improvement on Cache --- .../Source/Core/Cache/FEMManagedObjectCache.h | 17 ++++++----------- .../Source/Core/Cache/FEMManagedObjectCache.m | 17 ++++++++--------- FastEasyMappingTests/Specs/FEMCacheSpec.m | 10 +++++----- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h index 701c498..7a9e9f4 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.h @@ -2,23 +2,18 @@ #import -@class FEMManagedObjectCache, FEMManagedObjectMapping, NSManagedObjectContext; +@class FEMMapping, NSManagedObjectContext; @interface FEMManagedObjectCache : NSObject @property (nonatomic, strong, readonly) NSManagedObjectContext *context; -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping - externalRepresentation:(id)externalRepresentation - context:(NSManagedObjectContext *)context; +- (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)representation context:(NSManagedObjectContext *)context; -#pragma mark - +- (id)existingObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMMapping *)mapping; -- (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObjectMapping *)mapping; -- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMManagedObjectMapping *)mapping; - -- (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping; - -- (NSDictionary *)existingObjectsForMapping:(FEMManagedObjectMapping *)mapping; +- (void)addExistingObject:(id)object mapping:(FEMMapping *)mapping; +- (NSDictionary *)existingObjectsForMapping:(FEMMapping *)mapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index 90addf0..aada143 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -7,6 +7,7 @@ #import "FEMAttribute+Extension.h" #import "FEMRepresentationUtility.h" #import "FEMObjectMapping.h" +#import "FEMMapping.h" #import @@ -22,11 +23,9 @@ @implementation FEMManagedObjectCache { #pragma mark - Init -- (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping - externalRepresentation:(id)externalRepresentation - context:(NSManagedObjectContext *)context { +- (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)representation context:(NSManagedObjectContext *)context { NSParameterAssert(mapping); - NSParameterAssert(externalRepresentation); + NSParameterAssert(representation); NSParameterAssert(context); self = [self init]; @@ -37,7 +36,7 @@ - (instancetype)initWithMapping:(FEMManagedObjectMapping *)mapping _lookupObjectsMap = [NSMutableDictionary new]; [self prepareMappingLookupStructure:mapping]; - [self inspectExternalRepresentation:externalRepresentation mapping:mapping]; + [self inspectExternalRepresentation:representation mapping:mapping]; } return self; @@ -131,7 +130,7 @@ - (NSMutableDictionary *)cachedObjectsForMapping:(FEMManagedObjectMapping *)mapp return entityObjectsMap; } -- (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObjectMapping *)mapping { +- (id)existingObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { NSDictionary *entityObjectsMap = [self cachedObjectsForMapping:mapping]; id primaryKeyValue = [mapping.primaryKeyAttribute mappedValueFromRepresentation:representation]; @@ -140,13 +139,13 @@ - (id)existingObjectForRepresentation:(id)representation mapping:(FEMManagedObje return entityObjectsMap[primaryKeyValue]; } -- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMManagedObjectMapping *)mapping { +- (id)existingObjectForPrimaryKey:(id)primaryKey mapping:(FEMMapping *)mapping { NSDictionary *entityObjectsMap = [self cachedObjectsForMapping:mapping]; return entityObjectsMap[primaryKey]; } -- (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)mapping { +- (void)addExistingObject:(id)object mapping:(FEMMapping *)mapping { NSParameterAssert(mapping.primaryKey); NSParameterAssert(object); @@ -157,7 +156,7 @@ - (void)addExistingObject:(id)object usingMapping:(FEMManagedObjectMapping *)map entityObjectsMap[primaryKeyValue] = object; } -- (NSDictionary *)existingObjectsForMapping:(FEMManagedObjectMapping *)mapping { +- (NSDictionary *)existingObjectsForMapping:(FEMMapping *)mapping { return [[self cachedObjectsForMapping:mapping] copy]; } diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 11c22b2..34c11b7 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -42,8 +42,8 @@ id mapping = [MappingProvider carMapping]; FEMManagedObjectCache *cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping - externalRepresentation:representation - context:context]; + representation:representation + context:context]; [[cache.context should] equal:context]; }); @@ -61,7 +61,7 @@ }; mapping = [MappingProvider carMappingWithPrimaryKey]; - cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; + cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:context]; }); afterEach(^{ mapping = nil; @@ -90,7 +90,7 @@ mapping:mapping context:context]; - [cache addExistingObject:car usingMapping:mapping]; + [cache addExistingObject:car mapping:mapping]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] equal:car]; }); @@ -136,7 +136,7 @@ representation = [CMFixture buildUsingFixture:@"PersonWithCar_1"]; mapping = [MappingProvider personWithCarMapping]; - cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:representation context:context]; + cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:context]; carMapping = (id) [mapping relationshipForProperty:@"car"].objectMapping; }); From 305c65cf9637f7ea741561e3fa81bfb64c3ea537 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:15:29 +0300 Subject: [PATCH 22/95] Delete deserializer source --- .../Core/Deserializer/FEMDeserializer.m | 28 +++++++++++++----- .../Source/Core/Store/FEMDeserializerSource.h | 29 ------------------- .../Source/Core/Store/FEMManagedObjectStore.m | 6 ++-- 3 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 12289d4..3dcc2db 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -10,9 +10,7 @@ #import "FEMAttribute+Extension.h" #import "FEMObjectStore.h" #import "FEMDefaultAssignmentContext.h" -#import "FEMManagedObjectStore.h" #import "FEMRepresentationUtility.h" -#import "KWExample.h" @implementation FEMDeserializer @@ -98,18 +96,32 @@ - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEM - (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - return [self objectFromRepresentation:root mapping:mapping]; + __block id object = nil; + [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + object = [self objectFromRepresentation:root mapping:mapping]; + }]; + + return object; } - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - return [self fulfillObject:object fromRepresentation:root mapping:mapping]; + [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + [self fulfillObject:object fromRepresentation:root mapping:mapping]; + }]; + + return object; } - (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - return [self collectionFromRepresentation:root mapping:mapping]; + __block NSArray *objects = nil; + [self.store performMappingTransaction:representation mapping:mapping transaction:^{ + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + objects = [self collectionFromRepresentation:root mapping:mapping]; + }]; + + return objects; } @end diff --git a/FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h b/FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h deleted file mode 100644 index 1895724..0000000 --- a/FastEasyMapping/Source/Core/Store/FEMDeserializerSource.h +++ /dev/null @@ -1,29 +0,0 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -@import Foundation.h; - -@protocol FEMAssignmentContextPrivate; - -@class FEMMapping, FEMDeserializer; - -@protocol FEMDeserializerSource - -@required - -@property (nonatomic, strong, readonly) FEMMapping *mapping; -@property (nonatomic, strong, readonly) id externalRepresentation; - -- (id)newObjectForMapping:(FEMMapping *)mapping; - -- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; -- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; -- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; - -- (BOOL)shouldRegisterObject:(id)object forMapping:(FEMMapping *)mapping; - -- (id)newAssignmentContext; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index df13012..04a6678 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -28,7 +28,7 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { if (self) { _managedObjectContext = context; - _cache = [[FEMManagedObjectCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; +// _cache = [[FEMManagedObjectCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; } return self; @@ -45,8 +45,8 @@ - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping * return [_cache existingObjectForRepresentation:representation mapping:mapping]; } -- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping { - return [_cache addExistingObject:object usingMapping:mapping]; +- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping { + return [_cache addExistingObject:object mapping:mapping]; } - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { From b9c95e7d28b8de794ccc34e004efb7e2afe9e741 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:40:42 +0300 Subject: [PATCH 23/95] Use FEMRelationshipAssignmentContext in deserialiser --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 3dcc2db..c91aeaa 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -9,7 +9,7 @@ #import "NSArray+FEMPropertyRepresentation.h" #import "FEMAttribute+Extension.h" #import "FEMObjectStore.h" -#import "FEMDefaultAssignmentContext.h" +#import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" @implementation FEMDeserializer @@ -44,7 +44,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } } - id context = [self.store newAssignmentContext]; + FEMRelationshipAssignmentContext *context = [self.store newAssignmentContext]; context.destinationObject = object; context.relationship = relationship; context.sourceRelationshipValue = [object valueForKey:relationship.property]; From 867b5c575770a8a0cd796f65027fa3e818da21cb Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:41:06 +0300 Subject: [PATCH 24/95] Nothing special here --- .../Mapping/Object/FEMManagedObjectMapping.h | 5 ++- .../Core/Mapping/Object/FEMObjectMapping.h | 4 +++ .../Source/Core/Store/FEMManagedObjectStore.h | 3 ++ .../Source/Core/Store/FEMManagedObjectStore.m | 33 ++++++++++++++----- .../Source/Core/Store/FEMObjectStore.h | 5 ++- .../Source/Core/Store/FEMObjectStore.m | 31 +++++++++-------- 6 files changed, 52 insertions(+), 29 deletions(-) diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 0c406cd..9b60d4b 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -11,10 +11,9 @@ #import "FEMTypes.h" #import "FEMMapping.h" -@interface FEMManagedObjectMapping : FEMMapping -@end +@compatibility_alias FEMManagedObjectMapping FEMMapping; -@interface FEMManagedObjectMapping (Deprecated) +@interface FEMMapping (FEMManagedObjectMapping_Deprecated) + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName; + (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index 11fa058..284b7ee 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -17,3 +17,7 @@ //@end @compatibility_alias FEMObjectMapping FEMMapping; + +@interface FEMMapping (FEMObjectMapping_Deprecated) + +@end diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h index 4e53c01..7b77948 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h @@ -10,5 +10,8 @@ @interface FEMManagedObjectStore : FEMObjectStore - (instancetype)initWithContext:(NSManagedObjectContext *)context; +@property (nonatomic, strong, readonly) NSManagedObjectContext *context; + +@property (nonatomic) BOOL saveContextOnCommit; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 04a6678..6fcf04a 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -9,7 +9,10 @@ #import "FEMManagedObjectMapping.h" #import "FEMManagedObjectCache.h" -#import "FEMDefaultAssignmentContext.h" + +__attribute__((always_inline)) void validateMapping(FEMMapping *mapping) { + NSCAssert(mapping.entityName != nil, @"Entity name can't be nil. Please, use -[FEMMapping initWithEntityName:]"); +} @implementation FEMManagedObjectStore { FEMManagedObjectCache *_cache; @@ -24,11 +27,10 @@ @implementation FEMManagedObjectStore { #pragma mark - Init - (instancetype)initWithContext:(NSManagedObjectContext *)context { + NSParameterAssert(context != nil); self = [super init]; if (self) { - _managedObjectContext = context; - -// _cache = [[FEMManagedObjectCache alloc] initWithMapping:_mapping externalRepresentation:externalRepresentation context:_managedObjectContext]; + _context = context; } return self; @@ -37,28 +39,41 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { #pragma mark - FEMDeserializerSource - (id)newObjectForMapping:(FEMMapping *)mapping { - NSString *entityName = [(FEMManagedObjectMapping *)mapping entityName]; + validateMapping(mapping); + + NSString *entityName = [mapping entityName]; return [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:_managedObjectContext]; } - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { + validateMapping(mapping); + return [_cache existingObjectForRepresentation:representation mapping:mapping]; } -- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping { - return [_cache addExistingObject:object mapping:mapping]; +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping { + validateMapping(mapping); + + [_cache addExistingObject:object mapping:mapping]; } - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { + validateMapping(mapping); + return [_cache existingObjectsForMapping:mapping]; } - (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping { + validateMapping(mapping); + return mapping.primaryKey != nil && [object isInserted]; } -- (id)newAssignmentContext { - return [[FEMDefaultAssignmentContext alloc] initWithManagedObjectContext:_managedObjectContext]; +#pragma mark - FEMRelationshipAssignmentContextDelegate + +- (void)assignmentContext:(FEMRelationshipAssignmentContext *)context deletedObject:(id)object { + NSAssert([object isKindOfClass:NSManagedObject.class], @"Wrong class"); + [self.context deleteObject:object]; } @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 907d792..4619662 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -11,14 +11,13 @@ @interface FEMObjectStore : NSObject -- (NSArray *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction; +- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction; - (id)newObjectForMapping:(FEMMapping *)mapping; - (FEMRelationshipAssignmentContext *)newAssignmentContext; -- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping; +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; - (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping; -- (BOOL)deleteRegisteredObject:(id)object forMapping:(FEMMapping *)mapping; - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m index 56577b2..41b3036 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -5,41 +5,44 @@ #import "FEMObjectStore.h" #import "FEMMapping.h" -#import "FEMAssignmentContextPrivate.h" -#import "FEMRelationshipAssignmentContext.h" @implementation FEMObjectStore -- (NSArray *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { +- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { + transaction(); return nil; } - (id)newObjectForMapping:(FEMMapping *)mapping { - return [[mapping.objectClass alloc] init]; + id object = [[mapping.objectClass alloc] init]; + return object; } -- (id)newAssignmentContext { - return +- (FEMRelationshipAssignmentContext *)newAssignmentContext { + FEMRelationshipAssignmentContext *context = [[FEMRelationshipAssignmentContext alloc] initWithStore:self]; + return context; } -- (BOOL)registerObject:(id)object forMapping:(FEMMapping *)mapping { - +- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping { + // no-op } - (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping { - -} - -- (BOOL)deleteRegisteredObject:(id)object forMapping:(FEMMapping *)mapping { - + return mapping.primaryKeyAttribute != nil; } - (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping { - + return nil; } - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { + return nil; +} + +#pragma mark - FEMRelationshipAssignmentContextDelegate +- (void)assignmentContext:(FEMRelationshipAssignmentContext *)context deletedObject:(id)object { + // no-op } @end \ No newline at end of file From 34651a7ed3dca23c3760b8a6c53f2e9be9d6f46f Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:52:18 +0300 Subject: [PATCH 25/95] Add extended inits to FEMMapping --- .../Core/Deserializer/FEMObjectDeserializer.h | 2 -- .../Source/Core/Mapping/FEMMapping.h | 5 +++++ .../Source/Core/Mapping/FEMMapping.m | 18 +++++++++++++++++ .../Mapping/Object/FEMManagedObjectMapping.h | 3 --- .../Core/Mapping/Object/FEMObjectMapping.h | 20 +++++++------------ .../Specs/FEMManagedObjectDeserializerSpec.m | 2 +- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h index 388d528..8f0a07b 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h @@ -8,9 +8,7 @@ @interface FEMObjectDeserializer : NSObject + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; - + (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; - + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 72e137b..bb94458 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -16,8 +16,13 @@ + (instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); - (id)initWithRootPath:(NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); + - (instancetype)initWithObjectClass:(Class)objectClass NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath; + - (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER; +- (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath; + @property (nonatomic, readonly) Class objectClass; @property (nonatomic, copy, readonly) NSString *entityName; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index d6adced..4d075b2 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -18,6 +18,15 @@ - (instancetype)initWithObjectClass:(Class)objectClass { return self; } +- (instancetype)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath { + self = [self initWithObjectClass:objectClass]; + if (self) { + self.rootPath = rootPath; + } + + return nil; +} + - (instancetype)initWithEntityName:(NSString *)entityName { self = [super init]; if (self) { @@ -30,6 +39,15 @@ - (instancetype)initWithEntityName:(NSString *)entityName { return self; } +- (instancetype)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath { + self = [self initWithEntityName:entityName]; + if (self) { + self.rootPath = rootPath; + } + + return nil; +} + #pragma mark - Attribute Mapping - (void)addPropertyMapping:(id)propertyMapping toMap:(NSMutableDictionary *)map { diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 9b60d4b..3432220 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -22,7 +22,4 @@ rootPath:(NSString *)rootPath configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; -- (id)initWithEntityName:(NSString *)entityName; -- (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath; - @end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index 284b7ee..4985fa4 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -3,21 +3,15 @@ #import #import "FEMMapping.h" -// -//@interface FEMObjectMapping : FEMMapping -// -//@property (nonatomic, readonly) Class objectClass; -// -//- (id)initWithObjectClass:(Class)objectClass; -//- (id)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath; -// -//+ (instancetype)mappingForClass:(Class)objectClass configuration:(void (^)(FEMObjectMapping *mapping))configuration; -//+ (instancetype)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMObjectMapping *mapping))configuration; -// -//@end - @compatibility_alias FEMObjectMapping FEMMapping; @interface FEMMapping (FEMObjectMapping_Deprecated) ++ (instancetype)mappingForClass:(Class)objectClass + configuration:(void (^)(FEMObjectMapping *mapping))configuration; + ++ (instancetype)mappingForClass:(Class)objectClass + rootPath:(NSString *)rootPath + configuration:(void (^)(FEMObjectMapping *mapping))configuration; + @end diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index 7eb7fd0..d46c9ac 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -9,7 +9,7 @@ #import "Car.h" #import "FEMDeserializer.h" -#import "FEMRelationshipMapping.h" +#import "FEMRelationship.h" #import "FEMManagedObjectDeserializer.h" #import "FEMRelationship.h" From def87333d70abe109c15a5d99e279a1383281f0d Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 13:52:30 +0300 Subject: [PATCH 26/95] Update FEMManagedObjectMapping spec --- FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m index 0a90454..d800f7d 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m @@ -25,7 +25,7 @@ __block FEMManagedObjectMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] init]; + mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Temp"]; }); specify(^{ @@ -43,7 +43,7 @@ __block FEMManagedObjectMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] init]; + mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Temp"]; }); specify(^{ From 82c425278717cf6b50ef3e169dffaa031606e0f3 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 14:08:00 +0300 Subject: [PATCH 27/95] Implemented backward compatibility for FEMObjectMapping & FEMManagedObjectMapping --- FastEasyMapping.xcodeproj/project.pbxproj | 20 ++++- .../FEMManagedObjectDeserializer.h | 35 ++++++++ .../Core/Deserializer/FEMObjectDeserializer.m | 85 +++++++++++++++++++ .../Source/Core/Mapping/FEMMapping.m | 47 +++++++++- .../Mapping/Object/FEMManagedObjectMapping.h | 12 +-- .../Core/Mapping/Object/FEMObjectMapping.h | 4 +- 6 files changed, 190 insertions(+), 13 deletions(-) create mode 100644 FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h create mode 100644 FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 046569d..39abfbe 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -76,7 +76,6 @@ 2CF809A418C3AE9A00C07899 /* FEMAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED724125F45703B27BFC0C /* FEMAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A518C3AE9A00C07899 /* FEMRelationship.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1A1592194E312212F9 /* FEMRelationship.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1B2AB96554F9FDF10B /* FEMSerializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 2CF809A818C3AE9A00C07899 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AA18C3AE9A00C07899 /* FastEasyMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED77A829DD1436A5A2CA1B /* FastEasyMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -98,6 +97,10 @@ AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; + AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; }; + AD52DF7E1B03657900E46915 /* FEMManagedObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */; }; + AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; }; + AD52DF801B03657900E46915 /* FEMObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -158,7 +161,6 @@ 2CF8098818C3AD5700C07899 /* FastEasyMappingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FastEasyMappingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2CF8098918C3AD5700C07899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 2CF8098C18C3AD5700C07899 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectDeserializer.h; sourceTree = ""; }; 69ED70753A27735A60785078 /* FEMObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectMapping.h; sourceTree = ""; }; 69ED70F7239A59402E626302 /* Cars.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Cars.json; sourceTree = ""; }; 69ED70FD89800BB41C8894FE /* MappingProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MappingProvider.h; sourceTree = ""; }; @@ -238,6 +240,10 @@ 69ED7FE4AD3F8C3BD25B5825 /* CarWithRoot.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = CarWithRoot.json; sourceTree = ""; }; 69ED7FF7736562A674D3696D /* PlaneNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlaneNative.h; sourceTree = ""; }; 95A8DE2E9CC533DA840A0845 /* Pods-FastEasyMappingTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.release.xcconfig"; sourceTree = ""; }; + AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializer.h; sourceTree = ""; }; + AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializer.m; sourceTree = ""; }; + AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectDeserializer.h; sourceTree = ""; }; + AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectDeserializer.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -567,9 +573,12 @@ 69ED7C8732A1C26BF1CF78CD /* Deserializer */ = { isa = PBXGroup; children = ( - 69ED7039B8922439BE9D1B8C /* FEMObjectDeserializer.h */, 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */, 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */, + AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */, + AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */, + AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */, + AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */, ); path = Deserializer; sourceTree = ""; @@ -605,12 +614,12 @@ 2CF809A418C3AE9A00C07899 /* FEMAttribute.h in Headers */, 2CF809A518C3AE9A00C07899 /* FEMRelationship.h in Headers */, 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */, - 2CF809A818C3AE9A00C07899 /* FEMObjectDeserializer.h in Headers */, 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */, 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */, 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, + AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, @@ -619,6 +628,7 @@ 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, + AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */, 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, ); @@ -735,8 +745,10 @@ AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */, AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, + AD52DF801B03657900E46915 /* FEMObjectDeserializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, + AD52DF7E1B03657900E46915 /* FEMManagedObjectDeserializer.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h new file mode 100644 index 0000000..21beef2 --- /dev/null +++ b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h @@ -0,0 +1,35 @@ +// For License please refer to LICENSE file in the root of FastEasyMapping project + +#import + +#import "FEMDeserializer.h" +#import "FEMManagedObjectMapping.h" + +@class NSManagedObject, NSFetchRequest, NSManagedObjectContext; + +@compatibility_alias FEMManagedObjectDeserializer FEMDeserializer; + +@interface FEMManagedObjectDeserializer (BackwardCompatibility) + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation + usingMapping:(FEMManagedObjectMapping *)mapping + context:(NSManagedObjectContext *)context; + ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping; + +/** Get an array of managed objects from an external representation. If the objectMapping has + a primary key existing objects will be updated. This method is slow and it doesn't + delete obsolete objects, use + syncArrayOfObjectsFromExternalRepresentation:withMapping:fetchRequest:inManagedObjectContext: + instead. + */ ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation + usingMapping:(FEMManagedObjectMapping *)mapping + context:(NSManagedObjectContext *)context; + ++ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation + usingMapping:(FEMManagedObjectMapping *)mapping + predicate:(NSPredicate *)predicate + context:(NSManagedObjectContext *)context; + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m new file mode 100644 index 0000000..c727fbd --- /dev/null +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m @@ -0,0 +1,85 @@ +// For License please refer to LICENSE file in the root of FastEasyMapping project + +#import "FEMObjectDeserializer.h" + +#import "FEMTypeIntrospection.h" +#import "FEMAttribute.h" +#import +#import "FEMManagedObjectDeserializer.h" +#import "NSArray+FEMPropertyRepresentation.h" +#import "FEMAttribute+Extension.h" +#import "FEMObjectMapping.h" +#import "FEMRelationship.h" + +@implementation FEMObjectDeserializer + ++ (id)deserializeObjectRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { + id object = [[mapping.objectClass alloc] init]; + return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; +} + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + return [self deserializeObjectRepresentation:representation usingMapping:mapping]; +} + ++ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { + for (FEMAttribute *attributeMapping in mapping.attributes) { + [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; + } + + for (FEMRelationship *relationshipMapping in mapping.relationships) { + id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:representation]; + if (relationshipRepresentation == nil) continue; + + FEMObjectMapping *objectMapping = (FEMObjectMapping *)relationshipMapping.objectMapping; + NSAssert( + [objectMapping isKindOfClass:FEMObjectMapping.class], + @"%@ expect %@ for %@.objectMapping", + NSStringFromClass(self), + NSStringFromClass(FEMObjectMapping.class), + NSStringFromClass(FEMRelationship.class) + ); + + id targetValue = nil; + if (relationshipRepresentation != NSNull.null) { + if (relationshipMapping.isToMany) { + targetValue = [self deserializeCollectionRepresentation:relationshipRepresentation + usingMapping:objectMapping]; + + objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); + targetValue = [targetValue fem_propertyRepresentation:property]; + } else { + targetValue = [self deserializeObjectRepresentation:relationshipRepresentation + usingMapping:objectMapping]; + } + + } + + [object setValue:targetValue forKeyPath:relationshipMapping.property]; + } + + return object; +} + ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; +} + ++ (NSArray *)deserializeCollectionRepresentation:(NSArray *)representation usingMapping:(FEMObjectMapping *)mapping { + NSMutableArray *output = [NSMutableArray array]; + for (NSDictionary *objectRepresentation in representation) { + @autoreleasepool { + [output addObject:[self deserializeObjectRepresentation:objectRepresentation usingMapping:mapping]]; + } + } + return [output copy]; +} + ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + NSArray *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; + return [self deserializeCollectionRepresentation:representation usingMapping:mapping]; +} + +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 4d075b2..308fda6 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -1,6 +1,8 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMMapping.h" +#import "FEMManagedObjectMapping.h" +#import "FEMObjectMapping.h" @implementation FEMMapping @@ -169,4 +171,47 @@ - (id)representationFromExternalRepresentation:(id)externalRepresentation { return self.rootPath ? [externalRepresentation valueForKeyPath:self.rootPath] : externalRepresentation; } -@end \ No newline at end of file +@end + +@implementation FEMMapping (FEMManagedObjectMapping_Deprecated) + ++ (instancetype)mappingForEntityName:(NSString *)entityName { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName]; + return mapping; +} + ++ (instancetype)mappingForEntityName:(NSString *)entityName + configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName]; + configuration(mapping); + return mapping; +} + ++ (instancetype)mappingForEntityName:(NSString *)entityName + rootPath:(NSString *)rootPath + configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName rootPath:rootPath]; + configuration(mapping); + return mapping; +} + +@end + +@implementation FEMMapping (FEMObjectMapping_Deprecated) + ++ (instancetype)mappingForClass:(Class)objectClass + configuration:(void (^)(FEMObjectMapping *mapping))configuration { + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:objectClass]; + configuration(mapping); + return mapping; +} + ++ (instancetype)mappingForClass:(Class)objectClass + rootPath:(NSString *)rootPath + configuration:(void (^)(FEMObjectMapping *mapping))configuration { + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:objectClass rootPath:rootPath]; + configuration(mapping); + return mapping; +} + +@end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 3432220..93f19a1 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -15,11 +15,11 @@ @interface FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName; -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration; ++ (instancetype)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (instancetype)mappingForEntityName:(NSString *)entityName + configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (instancetype)mappingForEntityName:(NSString *)entityName + rootPath:(NSString *)rootPath + configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index 4985fa4..ee38a0b 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -8,10 +8,10 @@ @interface FEMMapping (FEMObjectMapping_Deprecated) + (instancetype)mappingForClass:(Class)objectClass - configuration:(void (^)(FEMObjectMapping *mapping))configuration; + configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); + (instancetype)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration; + configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end From 269a409796ac988ccd6ba4a596c9db958594f3c0 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:06:09 +0300 Subject: [PATCH 28/95] Implement backward compatibility for FEMObjectDeserializer & FEMManagedObjectDeserializer --- FastEasyMapping.xcodeproj/project.pbxproj | 8 - .../Core/Deserializer/FEMDeserializer.h | 27 +-- .../Core/Deserializer/FEMDeserializer.m | 158 ++++++++------- .../FEMManagedObjectDeserializer.h | 22 +-- .../FEMManagedObjectDeserializer.m | 186 ------------------ .../Core/Deserializer/FEMObjectDeserializer.h | 28 ++- .../Core/Deserializer/FEMObjectDeserializer.m | 85 -------- .../Core/Mapping/Object/FEMObjectMapping.h | 1 - 8 files changed, 118 insertions(+), 397 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m delete mode 100644 FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 39abfbe..bc5d2cb 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -98,9 +98,7 @@ AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; }; - AD52DF7E1B03657900E46915 /* FEMManagedObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */; }; AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; }; - AD52DF801B03657900E46915 /* FEMObjectDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -241,9 +239,7 @@ 69ED7FF7736562A674D3696D /* PlaneNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlaneNative.h; sourceTree = ""; }; 95A8DE2E9CC533DA840A0845 /* Pods-FastEasyMappingTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.release.xcconfig"; sourceTree = ""; }; AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectDeserializer.h; sourceTree = ""; }; - AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializer.m; sourceTree = ""; }; AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectDeserializer.h; sourceTree = ""; }; - AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectDeserializer.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -576,9 +572,7 @@ 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */, 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */, AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */, - AD52DF7A1B03657900E46915 /* FEMManagedObjectDeserializer.m */, AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */, - AD52DF7C1B03657900E46915 /* FEMObjectDeserializer.m */, ); path = Deserializer; sourceTree = ""; @@ -745,10 +739,8 @@ AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */, AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, - AD52DF801B03657900E46915 /* FEMObjectDeserializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, - AD52DF7E1B03657900E46915 /* FEMManagedObjectDeserializer.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 8bb396e..2ac7f70 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -9,31 +9,20 @@ @property (nonatomic, strong, readonly) FEMObjectStore *store; - (id)initWithStore:(FEMObjectStore *)store; -- (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; -- (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; +- (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; @end -@interface FEMDeserializer (Shortcut) +@interface FEMDeserializer (Extension) -+ (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; -+ (id)fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; ++ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; ++ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; -/** Get an array of managed objects from an external representation. If the objectMapping has -a primary key existing objects will be updated. This method is slow and it doesn't -delete obsolete objects, use -syncArrayOfObjectsFromExternalRepresentation:withMapping:fetchRequest:inManagedObjectContext: -instead. -*/ -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMMapping *)mapping - context:(NSManagedObjectContext *)context; - -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context; ++ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; ++ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; ++ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index c91aeaa..4ad9d35 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -11,6 +11,9 @@ #import "FEMObjectStore.h" #import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" +#import "FEMManagedObjectStore.h" +#import "KWExample.h" +#import "FEMObjectMapping.h" @implementation FEMDeserializer @@ -24,7 +27,7 @@ - (id)initWithStore:(FEMObjectStore *)store { return self; } -#pragma mark - Deserialization IMP +#pragma mark - Deserialization - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { for (FEMRelationship *relationship in mapping.relationships) { @@ -35,12 +38,12 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * id targetValue = nil; if (relationshipRepresentation != NSNull.null) { if (relationship.isToMany) { - targetValue = [self collectionFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; + targetValue = [self _collectionFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; objc_property_t property = class_getProperty([object class], [relationship.property UTF8String]); targetValue = [targetValue fem_propertyRepresentation:property]; } else { - targetValue = [self objectFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; + targetValue = [self _objectFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; } } @@ -56,7 +59,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } } -- (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { +- (id)_fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { for (FEMAttributeMapping *attributeMapping in mapping.attributes) { [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; } @@ -66,13 +69,13 @@ - (id)fulfillObject:(id)object fromRepresentation:(NSDictionary *)representation return object; } -- (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { +- (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { id object = [self.store registeredObjectForRepresentation:representation mapping:mapping]; if (!object) { object = [self.store newObjectForMapping:mapping]; } - [self fulfillObject:object fromRepresentation:representation mapping:mapping]; + [self _fillObject:object fromRepresentation:representation mapping:mapping]; if ([self.store canRegisterObject:object forMapping:mapping]) { [self.store registerObject:object forMapping:mapping]; @@ -81,11 +84,11 @@ - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMappin return object; } -- (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { +- (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { NSMutableArray *output = [[NSMutableArray alloc] initWithCapacity:representation.count]; for (id objectRepresentation in representation) { @autoreleasepool { - id object = [self objectFromRepresentation:objectRepresentation mapping:mapping]; + id object = [self _objectFromRepresentation:objectRepresentation mapping:mapping]; [output addObject:object]; } } @@ -95,11 +98,11 @@ - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEM #pragma mark - Public -- (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { +- (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { __block id object = nil; [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - object = [self objectFromRepresentation:root mapping:mapping]; + object = [self _objectFromRepresentation:root mapping:mapping]; }]; return object; @@ -108,17 +111,17 @@ - (id)deserializeObjectFromRepresentation:(NSDictionary *)representation mapping - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - [self fulfillObject:object fromRepresentation:root mapping:mapping]; + [self _fillObject:object fromRepresentation:root mapping:mapping]; }]; return object; } -- (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { +- (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { __block NSArray *objects = nil; [self.store performMappingTransaction:representation mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - objects = [self collectionFromRepresentation:root mapping:mapping]; + objects = [self _collectionFromRepresentation:root mapping:mapping]; }]; return objects; @@ -126,65 +129,74 @@ - (NSArray *)deserializeCollectionFromRepresentation:(NSArray *)representation m @end -@implementation FEMDeserializer (Shortcut) - -//+ (id)deserializeObjectFromRepresentation:(NSDictionary *)representation -// mapping:(FEMMapping *)mapping -// context:(NSManagedObjectContext *)context { -// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:context]; -// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; -// -// return [deserializer deserializeObject]; -//} -// -//+ (id)fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { -// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:object.managedObjectContext]; -// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; -// -// return [deserializer fulfillObject:object]; -//} -// -//+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation -// usingMapping:(FEMManagedObjectMapping *)mapping -// context:(NSManagedObjectContext *)context { -// FEMManagedObjectStore *source = [[FEMManagedObjectStore alloc] initWithContext:context]; -// FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:source]; -// -// return [deserializer deserializeCollection]; -//} -// -//+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation -// usingMapping:(FEMManagedObjectMapping *)mapping -// predicate:(NSPredicate *)predicate -// context:(NSManagedObjectContext *)context { -//// NSParameterAssert(mapping.primaryKey != nil); -//// -//// FEMAttributeMapping *primaryKeyMapping = [mapping primaryKeyMapping]; -//// -//// NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; -//// [request setPredicate:predicate]; -//// -//// NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; -//// NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; -//// NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects -//// forKeys:initialObjectsKeys]; -//// -//// FEMManagedObjectCache *cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; -//// FEMCacheSetCurrent(cache); -//// NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation -//// usingMapping:mapping -//// context:context]; -//// FEMCacheRemoveCurrent(); -//// -//// NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; -//// [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; -//// -//// for (NSManagedObject *object in initialObjectsMap.allValues) { -//// [context deleteObject:object]; -//// } -//// -//// return output; -// return nil; -//} +@implementation FEMDeserializer (Extension) + ++ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { + FEMManagedObjectStore *store = [[FEMManagedObjectStore alloc] initWithContext:context]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; + return [deserializer objectFromRepresentation:representation mapping:mapping]; +} + ++ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + FEMObjectStore *store = [[FEMObjectStore alloc] init]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; + return [deserializer objectFromRepresentation:representation mapping:mapping]; +} + ++ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + FEMObjectStore *store = nil; + if ([object isKindOfClass:NSManagedObject.class]) { + store = [[FEMManagedObjectStore alloc] initWithContext:[(NSManagedObject *)object managedObjectContext]]; + } else { + store = [[FEMObjectStore alloc] init]; + } + + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; + return [deserializer _fillObject:object fromRepresentation:representation mapping:mapping]; +}; + ++ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { + FEMManagedObjectStore *store = [[FEMManagedObjectStore alloc] initWithContext:context]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; + return [deserializer collectionFromRepresentation:representation mapping:mapping]; +} + ++ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { + FEMObjectStore *store = [[FEMObjectStore alloc] init]; + FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; + return [deserializer collectionFromRepresentation:representation mapping:mapping]; +} + +@end + +@implementation FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { + return [self objectFromRepresentation:externalRepresentation mapping:mapping context:context]; +} + ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { + return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; +} + ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { + return [self collectionFromRepresentation:externalRepresentation mapping:mapping context:context]; +} + +@end + +@implementation FEMDeserializer (FEMObjectDeserializer_Deprecated) + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + return [self objectFromRepresentation:externalRepresentation mapping:mapping]; +} + ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; +} + ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { + return [self collectionFromRepresentation:externalRepresentation mapping:mapping]; +} @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h index 21beef2..5d2d750 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h @@ -9,27 +9,15 @@ @compatibility_alias FEMManagedObjectDeserializer FEMDeserializer; -@interface FEMManagedObjectDeserializer (BackwardCompatibility) +@interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context; - -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping; - -/** Get an array of managed objects from an external representation. If the objectMapping has - a primary key existing objects will be updated. This method is slow and it doesn't - delete obsolete objects, use - syncArrayOfObjectsFromExternalRepresentation:withMapping:fetchRequest:inManagedObjectContext: - instead. - */ -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context; ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); + (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context; + context:(NSManagedObjectContext *)context __attribute__((unavailable)); @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m deleted file mode 100644 index 28e21cf..0000000 --- a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.m +++ /dev/null @@ -1,186 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMManagedObjectDeserializer.h" - -#import - -#import "FEMManagedObjectMapping.h" -#import "FEMAttribute.h" -#import "FEMTypeIntrospection.h" -#import "NSArray+FEMPropertyRepresentation.h" -#import "FEMAttribute+Extension.h" -#import "FEMRelationship.h" -#import "FEMCache.h" -#import "FEMAssignmentPolicyMetadata.h" - -@implementation FEMManagedObjectDeserializer - -#pragma mark - Deserialization - -+ (id)_deserializeObjectRepresentation:(NSDictionary *)representation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { - id object = [FEMCacheGetCurrent() existingObjectForRepresentation:representation mapping:mapping]; - if (!object) { - object = [NSEntityDescription insertNewObjectForEntityForName:mapping.entityName inManagedObjectContext:context]; - } - - [self _fillObject:object fromRepresentation:representation usingMapping:mapping]; - - if ([object isInserted] && mapping.primaryKey) { - [FEMCacheGetCurrent() addExistingObject:object usingMapping:mapping]; - } - - return object; -} - -+ (id)_deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - id objectRepresentation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self _deserializeObjectRepresentation:objectRepresentation usingMapping:mapping context:context]; -} - - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:context]; - FEMCacheSetCurrent(cache); - id object = [self _deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:context]; - FEMCacheRemoveCurrent(); - - return object; -} - -+ (id)_fillObject:(NSManagedObject *)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMManagedObjectMapping *)mapping { - for (FEMAttribute *attributeMapping in mapping.attributes) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; - } - - NSManagedObjectContext *context = object.managedObjectContext; - for (FEMRelationship *relationshipMapping in mapping.relationships) { - id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:representation]; - // skip missing key - if (relationshipRepresentation == nil) continue; - - FEMManagedObjectMapping *objectMapping = (FEMManagedObjectMapping *)relationshipMapping.objectMapping; - NSAssert( - [objectMapping isKindOfClass:FEMManagedObjectMapping.class], - @"%@ expect %@ for %@.objectMapping", - NSStringFromClass(self), - NSStringFromClass(FEMManagedObjectMapping.class), - NSStringFromClass(FEMRelationship.class) - ); - - FEMAssignmentPolicyMetadata *metadata = [FEMAssignmentPolicyMetadata new]; - [metadata setContext:context]; - [metadata setExistingValue:[object valueForKey:relationshipMapping.property]]; - - if (relationshipRepresentation != NSNull.null) { - if (relationshipMapping.isToMany) { - NSArray *targetValue = [self _deserializeCollectionRepresentation:relationshipRepresentation - usingMapping:objectMapping - context:context]; - - objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); - [metadata setTargetValue:[targetValue fem_propertyRepresentation:property]]; - } else { - id targetValue = [self _deserializeObjectRepresentation:relationshipRepresentation - usingMapping:objectMapping - context:context]; - metadata.targetValue = targetValue; - } - } else { - metadata.targetValue = nil; - } - - [object setValue:relationshipMapping.assignmentPolicy(metadata) forKey:relationshipMapping.property]; - } - - return object; -} - -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:object.managedObjectContext]; - FEMCacheSetCurrent(cache); - - id objectRepresentation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - id output = [self _fillObject:object fromRepresentation:objectRepresentation usingMapping:mapping]; - FEMCacheRemoveCurrent(); - - return output; -} - -+ (NSArray *)_deserializeCollectionRepresentation:(NSArray *)representation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - NSMutableArray *output = [NSMutableArray array]; - for (id objectRepresentation in representation) { - @autoreleasepool { - [output addObject:[self _deserializeObjectRepresentation:objectRepresentation - usingMapping:mapping - context:context]]; - } - } - return [output copy]; -} - -+ (NSArray *)_deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - id representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self _deserializeCollectionRepresentation:representation usingMapping:mapping context:context]; -} - -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - context:(NSManagedObjectContext *)context { - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping - externalRepresentation:externalRepresentation - context:context]; - FEMCacheSetCurrent(cache); - NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:mapping - context:context]; - FEMCacheRemoveCurrent(); - - return output; -} - -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context { - NSParameterAssert(mapping.primaryKey != nil); - - FEMAttribute *primaryKeyMapping = [mapping primaryKeyAttribute]; - - NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:mapping.entityName]; - [request setPredicate:predicate]; - - NSArray *initialObjects = [context executeFetchRequest:request error:NULL]; - NSArray *initialObjectsKeys = [initialObjects valueForKey:primaryKeyMapping.property]; - NSMutableDictionary *initialObjectsMap = [[NSMutableDictionary alloc] initWithObjects:initialObjects - forKeys:initialObjectsKeys]; - - FEMCache *cache = [[FEMCache alloc] initWithMapping:mapping externalRepresentation:externalRepresentation context:context]; - FEMCacheSetCurrent(cache); - NSArray *output = [self _deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:mapping - context:context]; - FEMCacheRemoveCurrent(); - - NSDictionary *existingObjectsMap = [cache existingObjectsForMapping:mapping]; - [initialObjectsMap removeObjectsForKeys:existingObjectsMap.allKeys]; - - for (NSManagedObject *object in initialObjectsMap.allValues) { - [context deleteObject:object]; - } - - return output; -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h index 8f0a07b..878d9f9 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h @@ -1,14 +1,26 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project -#import -#import +#import "FEMDeserializer.h" +#import "FEMObjectMapping.h" -@class FEMObjectMapping; +@compatibility_alias FEMObjectDeserializer FEMDeserializer; -@interface FEMObjectDeserializer : NSObject +@interface FEMDeserializer (FEMObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping; ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); -@end \ No newline at end of file +@end + +//+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { +//return [self objectFromRepresentation:externalRepresentation mapping:mapping]; +//} +// +//+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { +//return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; +//} +// +//+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { +//return [self collectionFromRepresentation:externalRepresentation mapping:mapping]; +//} diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m deleted file mode 100644 index c727fbd..0000000 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.m +++ /dev/null @@ -1,85 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMObjectDeserializer.h" - -#import "FEMTypeIntrospection.h" -#import "FEMAttribute.h" -#import -#import "FEMManagedObjectDeserializer.h" -#import "NSArray+FEMPropertyRepresentation.h" -#import "FEMAttribute+Extension.h" -#import "FEMObjectMapping.h" -#import "FEMRelationship.h" - -@implementation FEMObjectDeserializer - -+ (id)deserializeObjectRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { - id object = [[mapping.objectClass alloc] init]; - return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; -} - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self deserializeObjectRepresentation:representation usingMapping:mapping]; -} - -+ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMObjectMapping *)mapping { - for (FEMAttribute *attributeMapping in mapping.attributes) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; - } - - for (FEMRelationship *relationshipMapping in mapping.relationships) { - id relationshipRepresentation = [relationshipMapping extractRootFromExternalRepresentation:representation]; - if (relationshipRepresentation == nil) continue; - - FEMObjectMapping *objectMapping = (FEMObjectMapping *)relationshipMapping.objectMapping; - NSAssert( - [objectMapping isKindOfClass:FEMObjectMapping.class], - @"%@ expect %@ for %@.objectMapping", - NSStringFromClass(self), - NSStringFromClass(FEMObjectMapping.class), - NSStringFromClass(FEMRelationship.class) - ); - - id targetValue = nil; - if (relationshipRepresentation != NSNull.null) { - if (relationshipMapping.isToMany) { - targetValue = [self deserializeCollectionRepresentation:relationshipRepresentation - usingMapping:objectMapping]; - - objc_property_t property = class_getProperty([object class], [relationshipMapping.property UTF8String]); - targetValue = [targetValue fem_propertyRepresentation:property]; - } else { - targetValue = [self deserializeObjectRepresentation:relationshipRepresentation - usingMapping:objectMapping]; - } - - } - - [object setValue:targetValue forKeyPath:relationshipMapping.property]; - } - - return object; -} - -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSDictionary *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self fillObject:object fromRepresentation:representation usingMapping:mapping]; -} - -+ (NSArray *)deserializeCollectionRepresentation:(NSArray *)representation usingMapping:(FEMObjectMapping *)mapping { - NSMutableArray *output = [NSMutableArray array]; - for (NSDictionary *objectRepresentation in representation) { - @autoreleasepool { - [output addObject:[self deserializeObjectRepresentation:objectRepresentation usingMapping:mapping]]; - } - } - return [output copy]; -} - -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { - NSArray *representation = [mapping extractRootFromExternalRepresentation:externalRepresentation]; - return [self deserializeCollectionRepresentation:representation usingMapping:mapping]; -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index ee38a0b..b082a03 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -1,6 +1,5 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project -#import #import "FEMMapping.h" @compatibility_alias FEMObjectMapping FEMMapping; From 48a5ce8b8a9403acd8114c6cc91159a5da015e03 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:10:49 +0300 Subject: [PATCH 29/95] Remove unused utility functions --- FastEasyMapping.xcodeproj/project.pbxproj | 12 ------------ .../Source/Core/Cache/FEMManagedObjectCache.m | 4 ++-- .../Core/Deserializer/FEMObjectDeserializer.h | 14 +------------- FastEasyMapping/Source/Core/Mapping/FEMMapping.h | 2 -- FastEasyMapping/Source/Core/Mapping/FEMMapping.m | 4 ---- .../Core/Mapping/Relationship/FEMRelationship.h | 6 ------ .../Core/Mapping/Relationship/FEMRelationship.m | 10 ---------- .../Specs/FEMManagedObjectDeserializerSpec.m | 1 + 8 files changed, 4 insertions(+), 49 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index bc5d2cb..936f083 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -9,22 +9,16 @@ /* Begin PBXBuildFile section */ 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; - 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; - 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; - 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; - 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; - 1D6A3846E3E87F496676A2A6 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; }; - 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; @@ -779,13 +773,7 @@ 2C375F4018CCD40A00FCB8EA /* FEMSerializerSpec.m in Sources */, 2C375F2118CCD3FB00FCB8EA /* CarNative.m in Sources */, 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */, - 1D6A3BE38C286BBE0A0B0FEA /* FEMExcludableCollection.m in Sources */, - 1D6A33C795E9CA3D388DC1CE /* FEMMergeableCollection.m in Sources */, 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */, - 1D6A361B9A77E73A962B0007 /* FEMObjectStore.m in Sources */, - 1D6A3645DA65EDCB2A889774 /* FEMManagedObjectStore.m in Sources */, - 1D6A36A904C8D46C73BA8455 /* FEMRepresentationUtility.m in Sources */, - 1D6A3846E3E87F496676A2A6 /* FEMRelationshipAssignmentContext.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index aada143..1c42bfb 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -8,6 +8,7 @@ #import "FEMRepresentationUtility.h" #import "FEMObjectMapping.h" #import "FEMMapping.h" +#import "FEMRepresentationUtility.h" #import @@ -80,8 +81,7 @@ - (void)inspectRepresentation:(id)representation mapping:(FEMObjectMapping *)map } - (void)inspectExternalRepresentation:(id)externalRepresentation mapping:(FEMManagedObjectMapping *)mapping { - id representation = [mapping representationFromExternalRepresentation:externalRepresentation]; - + id representation = FEMRepresentationRootForKeyPath(externalRepresentation, mapping.rootPath); [self inspectRepresentation:representation mapping:mapping]; } diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h index 878d9f9..f268608 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h @@ -11,16 +11,4 @@ + (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); -@end - -//+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { -//return [self objectFromRepresentation:externalRepresentation mapping:mapping]; -//} -// -//+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { -//return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; -//} -// -//+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { -//return [self collectionFromRepresentation:externalRepresentation mapping:mapping]; -//} +@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index bb94458..934d5e8 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -51,6 +51,4 @@ - (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; -- (id)representationFromExternalRepresentation:(id)externalRepresentation; - @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 308fda6..257aa96 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -167,10 +167,6 @@ - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString [self addRelationship:relationshipMapping]; } -- (id)representationFromExternalRepresentation:(id)externalRepresentation { - return self.rootPath ? [externalRepresentation valueForKeyPath:self.rootPath] : externalRepresentation; -} - @end @implementation FEMMapping (FEMManagedObjectMapping_Deprecated) diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h index b586065..90db382 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h @@ -35,10 +35,4 @@ toKeyPath:(NSString *)keyPath objectMapping:(FEMMapping *)objectMapping; -@end - -@interface FEMRelationship (Extension) - -- (id)extractRootFromExternalRepresentation:(id)externalRepresentation; - @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m index bd1e4f8..f9618b8 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m @@ -88,14 +88,4 @@ + (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPa return [self mappingOfProperty:property toKeyPath:keyPath objectMapping:objectMapping]; } -@end - -@implementation FEMRelationship (Extension) - -- (id)representationFromExternalRepresentation:(id)externalRepresentation { - if (self.keyPath) return [externalRepresentation valueForKeyPath:self.keyPath]; - - return externalRepresentation; -} - @end \ No newline at end of file diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index d46c9ac..c0f63e5 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -12,6 +12,7 @@ #import "FEMRelationship.h" #import "FEMManagedObjectDeserializer.h" +#import "FEMObjectDeserializer.h" #import "FEMRelationship.h" #import "FEMMapping.h" From 8d49642ffdc29cb77fa85a046c5d6a6c20607549 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:18:46 +0300 Subject: [PATCH 30/95] Update compatibility aliases --- FastEasyMapping.xcodeproj/project.pbxproj | 4 ---- .../Source/Core/Deserializer/FEMDeserializer.m | 4 ++-- .../Core/Mapping/Attribute/FEMAttributeMapping.h | 15 --------------- FastEasyMapping/Source/Core/Mapping/FEMMapping.h | 3 +-- .../Core/Mapping/Object/FEMManagedObjectMapping.h | 4 ++-- .../Source/Core/Mapping/Object/FEMObjectMapping.h | 4 ++-- Podfile.lock | 14 +++++++------- 7 files changed, 14 insertions(+), 34 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 936f083..a003e70 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -20,7 +20,6 @@ 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; }; 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; - 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; @@ -132,7 +131,6 @@ 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; - 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttributeMapping.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipAssignmentContext.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; @@ -546,7 +544,6 @@ 69ED7141C706CAC006EADE5A /* FEMAttribute.m */, 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */, 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */, - 1D6A37509AEB445D0EE5964D /* FEMAttributeMapping.h */, ); path = Attribute; sourceTree = ""; @@ -612,7 +609,6 @@ 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, - 1D6A3CA9D3524975D1940D9F /* FEMAttributeMapping.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 4ad9d35..74f5786 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -60,8 +60,8 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } - (id)_fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - for (FEMAttributeMapping *attributeMapping in mapping.attributes) { - [attributeMapping setMappedValueToObject:object fromRepresentation:representation]; + for (FEMAttribute *attribute in mapping.attributes) { + [attribute setMappedValueToObject:object fromRepresentation:representation]; } [self fulfillObjectRelationships:object fromRepresentation:representation usingMapping:mapping]; diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h deleted file mode 100644 index 45f2274..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// FEMAttributeMapping.h -// FastEasyMapping -// -// Created by zen on 03/12/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// - -#import "FEMAttribute.h" - -/** -* @discussion -* FEMAttributeMapping has been renamed to FEMAttribute -*/ -@compatibility_alias FEMAttributeMapping FEMAttribute; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 934d5e8..ed6fcb2 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -3,7 +3,6 @@ #import #import "FEMAttribute.h" -#import "FEMAttributeMapping.h" #import "FEMRelationship.h" @interface FEMMapping : NSObject { @@ -30,7 +29,7 @@ @property (nonatomic, copy) NSString *rootPath; @property (nonatomic, copy) NSString *primaryKey; -@property (nonatomic, strong, readonly) FEMAttributeMapping *primaryKeyAttribute; +@property (nonatomic, strong, readonly) FEMAttribute *primaryKeyAttribute; @property (nonatomic, strong, readonly) NSArray *attributes; - (void)addAttribute:(FEMAttribute *)attribute; diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 93f19a1..defbf7e 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -17,9 +17,9 @@ + (instancetype)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); + (instancetype)mappingForEntityName:(NSString *)entityName - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); + configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); + (instancetype)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath - configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); + configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index b082a03..1e1606a 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -7,10 +7,10 @@ @interface FEMMapping (FEMObjectMapping_Deprecated) + (instancetype)mappingForClass:(Class)objectClass - configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); + configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); + (instancetype)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); + configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end diff --git a/Podfile.lock b/Podfile.lock index c5a6b9e..03754de 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -8,7 +8,7 @@ PODS: - libextobjc/RuntimeExtensions - libextobjc/RuntimeExtensions (0.4) - MagicalRecord (2.2): - - MagicalRecord/Core + - MagicalRecord/Core (= 2.2) - MagicalRecord/Core (2.2) - Mantle (1.0): - libextobjc/EXTKeyPathCoding @@ -20,10 +20,10 @@ DEPENDENCIES: - MagicalRecord (~> 2.2) SPEC CHECKSUMS: - CMFactory: 1e487af934fe202ab92262ce1e17df1397751152 - Kiwi: 54bece5b35564d9b8e03c608d926f1a22fcfc589 - libextobjc: ba42e4111f433273a886cd54f0ddaddb7f62f82f - MagicalRecord: 2b471584fc9e3137f3d0a56967917baa4979e224 - Mantle: f2d736d1537b770bb65a6807cef4009257d971b2 + CMFactory: 535c1473e91f4d0d13cb290de2144faa75a882a3 + Kiwi: 4c3988bd551f80f6ca0009f302f7c1a2e3777bf2 + libextobjc: f2802d4262f6885570df9799747409ceb1de602c + MagicalRecord: f8a56bb87ab6552f20c4bb8681a1958a197ea3cd + Mantle: 3fbcca07bdfe76c54a08c241689a60d34d08e783 -COCOAPODS: 0.34.2 +COCOAPODS: 0.36.4 From 0f07e571e986620b927c412df156d10c6595505f Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:20:26 +0300 Subject: [PATCH 31/95] Update global header --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m | 1 - FastEasyMapping/Source/FastEasyMapping.h | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 74f5786..a633e30 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -12,7 +12,6 @@ #import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" #import "FEMManagedObjectStore.h" -#import "KWExample.h" #import "FEMObjectMapping.h" @implementation FEMDeserializer diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index f9adcc5..4842f8b 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -3,11 +3,9 @@ #ifndef _FASTEASYMAPPING_ #define _FASTEASYMAPPING_ +#import "FEMProperty.h" #import "FEMAttribute.h" -#import "FEMAttributeMapping.h" - #import "FEMRelationship.h" -#import "FEMRelationshipMapping.h" #import "FEMMapping.h" #import "FEMObjectMapping.h" @@ -15,10 +13,11 @@ #import "FEMDeserializer.h" #import "FEMObjectDeserializer.h" +#import "FEMManagedObjectDeserializer.h" #import "FEMSerializer.h" +#import "FEMRelationshipAssignmentContext.h" #import "FEMAssignmentPolicy.h" -#import "FEMDefaultAssignmentContext.h" #import "FEMTypes.h" From b6727d9db701d1d8572fb3809d01675a8ac2922a Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:31:28 +0300 Subject: [PATCH 32/95] Replace @import by #import directive to iOS 6 compatibility --- FastEasyMapping.xcodeproj/project.pbxproj | 30 ++++++++++--------- .../Assignment Policy/FEMAssignmentPolicy.h | 2 +- ...EMRelationshipAssignmentContext+Internal.h | 2 +- .../FEMRelationshipAssignmentContext.h | 2 +- .../Core/Deserializer/FEMDeserializer.m | 2 +- .../Source/Core/Mapping/FEMProperty.h | 2 +- .../Source/Core/Store/FEMManagedObjectStore.m | 2 +- .../Source/Core/Store/FEMObjectStore.h | 2 +- .../Collection/FEMExcludableCollection.h | 2 +- .../Collection/FEMMergeableCollection.h | 2 +- .../Source/Utility/FEMRepresentationUtility.h | 2 +- 11 files changed, 26 insertions(+), 24 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index a003e70..6b9bfaf 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -9,16 +9,16 @@ /* Begin PBXBuildFile section */ 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; - 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; }; + 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; - 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; }; - 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; }; + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; - 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; }; + 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; - 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; }; + 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; @@ -90,8 +90,9 @@ AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; - AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; }; - AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; }; + AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AD52DF811B037B1400E46915 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -600,21 +601,21 @@ 2CF809A518C3AE9A00C07899 /* FEMRelationship.h in Headers */, 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */, 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */, + AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */, 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */, 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */, + AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, + 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, + 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, + 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, - AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, - 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, - 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, - 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, - 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, - AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */, - 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, + 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -753,6 +754,7 @@ 2C375F1318CCD3FB00FCB8EA /* EasyMappingCoreDataExample.xcdatamodel in Sources */, 2C375F3F18CCD40A00FCB8EA /* FEMObjectDeserializerSpec.m in Sources */, 2C375F1418CCD3FB00FCB8EA /* Car.m in Sources */, + AD52DF811B037B1400E46915 /* FEMMapping.m in Sources */, 2C375F1518CCD3FB00FCB8EA /* Phone.m in Sources */, 2C375F1618CCD3FB00FCB8EA /* Person.m in Sources */, 2C375F1718CCD3FB00FCB8EA /* NativeChild.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index ff03d41..3747d6a 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -3,7 +3,7 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -@import Foundation; +#import @class FEMRelationshipAssignmentContext; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h index 3b07880..0ddd910 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext+Internal.h @@ -3,7 +3,7 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation; +#import #import "FEMRelationshipAssignmentContext.h" diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h index 139324a..b82914b 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h @@ -3,7 +3,7 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation; +#import @class FEMRelationship, FEMObjectStore, FEMRelationshipAssignmentContext; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index a633e30..13f6235 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -2,7 +2,7 @@ #import "FEMDeserializer.h" -@import CoreData; +#import #import "FEMManagedObjectMapping.h" #import "FEMTypeIntrospection.h" diff --git a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h index 3ddd0d2..cbb6fa0 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h @@ -3,7 +3,7 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation; +#import @protocol FEMProperty diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 6fcf04a..c3c2d5a 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -5,7 +5,7 @@ #import "FEMManagedObjectStore.h" -@import CoreData; +#import #import "FEMManagedObjectMapping.h" #import "FEMManagedObjectCache.h" diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 4619662..93ed00f 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -3,7 +3,7 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation; +#import #import "FEMRelationshipAssignmentContext.h" diff --git a/FastEasyMapping/Source/Extensions/Collection/FEMExcludableCollection.h b/FastEasyMapping/Source/Extensions/Collection/FEMExcludableCollection.h index b1f3788..98d8d3f 100644 --- a/FastEasyMapping/Source/Extensions/Collection/FEMExcludableCollection.h +++ b/FastEasyMapping/Source/Extensions/Collection/FEMExcludableCollection.h @@ -3,7 +3,7 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -@import Foundation; +#import @protocol FEMExcludableCollection @required diff --git a/FastEasyMapping/Source/Extensions/Collection/FEMMergeableCollection.h b/FastEasyMapping/Source/Extensions/Collection/FEMMergeableCollection.h index f01036b..70999b8 100644 --- a/FastEasyMapping/Source/Extensions/Collection/FEMMergeableCollection.h +++ b/FastEasyMapping/Source/Extensions/Collection/FEMMergeableCollection.h @@ -3,7 +3,7 @@ // Copyright (c) 2014 Yalantis. All rights reserved. // -@import Foundation; +#import @protocol FEMMergeableCollection @required diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h index 9c8bdb9..d8942fb 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h @@ -3,6 +3,6 @@ // Copyright (c) 2015 Yalantis. All rights reserved. // -@import Foundation; +#import FOUNDATION_EXTERN id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath); \ No newline at end of file From b4a099748eabcbd66679670f0026e21772f8d110 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:52:17 +0300 Subject: [PATCH 33/95] Replace FEMManagedObjectMapping by FEMMapping --- .../Source/Core/Cache/FEMManagedObjectCache.m | 26 +++++-------- .../Mapping/Object/FEMManagedObjectMapping.h | 9 ++--- .../Core/Mapping/Object/FEMObjectMapping.h | 10 ++--- FastEasyMappingTests/Specs/FEMCacheSpec.m | 8 ++-- .../Specs/FEMManagedObjectDeserializerSpec.m | 8 ++-- .../Specs/FEMManagedObjectMappingSpec.m | 38 +++++++++---------- 6 files changed, 45 insertions(+), 54 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index 1c42bfb..b7ed650 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -1,18 +1,12 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMManagedObjectCache.h" -#import "FEMManagedObjectMapping.h" -#import "FEMRelationship.h" -#import "FEMAttribute.h" -#import "FEMAttribute+Extension.h" -#import "FEMRepresentationUtility.h" -#import "FEMObjectMapping.h" -#import "FEMMapping.h" -#import "FEMRepresentationUtility.h" #import -@class FEMManagedObjectCache; +#import "FEMMapping.h" +#import "FEMAttribute+Extension.h" +#import "FEMRepresentationUtility.h" @implementation FEMManagedObjectCache { NSManagedObjectContext *_context; @@ -45,7 +39,7 @@ - (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)represe #pragma mark - Inspection -- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMManagedObjectMapping *)mapping { +- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMMapping *)mapping { if (mapping.primaryKey) { FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; NSParameterAssert(primaryKeyMapping); @@ -64,7 +58,7 @@ - (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMManaged } } -- (void)inspectRepresentation:(id)representation mapping:(FEMObjectMapping *)mapping { +- (void)inspectRepresentation:(id)representation mapping:(FEMMapping *)mapping { if ([representation isKindOfClass:NSArray.class]) { for (id objectRepresentation in representation) { [self inspectObjectRepresentation:objectRepresentation mapping:mapping]; @@ -80,12 +74,12 @@ - (void)inspectRepresentation:(id)representation mapping:(FEMObjectMapping *)map } } -- (void)inspectExternalRepresentation:(id)externalRepresentation mapping:(FEMManagedObjectMapping *)mapping { +- (void)inspectExternalRepresentation:(id)externalRepresentation mapping:(FEMMapping *)mapping { id representation = FEMRepresentationRootForKeyPath(externalRepresentation, mapping.rootPath); [self inspectRepresentation:representation mapping:mapping]; } -- (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMManagedObjectMapping *)mapping { +- (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMMapping *)mapping { [namesCollection addObject:mapping.entityName]; for (FEMRelationship *relationshipMapping in mapping.relationships) { @@ -93,7 +87,7 @@ - (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMManagedOb } } -- (void)prepareMappingLookupStructure:(FEMManagedObjectMapping *)mapping { +- (void)prepareMappingLookupStructure:(FEMMapping *)mapping { NSMutableSet *entityNames = [NSMutableSet new]; [self collectEntityNames:entityNames mapping:mapping]; @@ -102,7 +96,7 @@ - (void)prepareMappingLookupStructure:(FEMManagedObjectMapping *)mapping { } } -- (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMManagedObjectMapping *)mapping { +- (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMMapping *)mapping { NSSet *lookupValues = _lookupKeysMap[mapping.entityName]; if (lookupValues.count == 0) return [NSMutableDictionary dictionary]; @@ -120,7 +114,7 @@ - (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMManagedObjectMapping return output; } -- (NSMutableDictionary *)cachedObjectsForMapping:(FEMManagedObjectMapping *)mapping { +- (NSMutableDictionary *)cachedObjectsForMapping:(FEMMapping *)mapping { NSMutableDictionary *entityObjectsMap = _lookupObjectsMap[mapping.entityName]; if (!entityObjectsMap) { entityObjectsMap = [self fetchExistingObjectsForMapping:mapping]; diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index defbf7e..2a510ec 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -15,11 +15,8 @@ @interface FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (instancetype)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (instancetype)mappingForEntityName:(NSString *)entityName - configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (instancetype)mappingForEntityName:(NSString *)entityName - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); ++ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index 1e1606a..dd46f5f 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -6,11 +6,11 @@ @interface FEMMapping (FEMObjectMapping_Deprecated) -+ (instancetype)mappingForClass:(Class)objectClass - configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); ++ (FEMObjectMapping *)mappingForClass:(Class)objectClass + configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); -+ (instancetype)mappingForClass:(Class)objectClass - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); ++ (FEMObjectMapping *)mappingForClass:(Class)objectClass + rootPath:(NSString *)rootPath + configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 34c11b7..221d923 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -8,7 +8,7 @@ #import #import "Person.h" -#import "FEMManagedObjectMapping.h" +#import "FEMMapping.h" #import "FEMManagedObjectCache.h" #import "MappingProvider.h" #import "Car.h" @@ -51,7 +51,7 @@ describe(@"object retrieval", ^{ __block NSDictionary *representation = nil; - __block FEMManagedObjectMapping *mapping = nil; + __block FEMMapping *mapping = nil; __block FEMManagedObjectCache *cache = nil; beforeEach(^{ representation = @{ @@ -129,8 +129,8 @@ describe(@"nested object retrieval", ^{ __block FEMManagedObjectCache *cache = nil; __block NSDictionary *representation = nil; - __block FEMManagedObjectMapping *mapping = nil; - __block FEMManagedObjectMapping *carMapping = nil; + __block FEMMapping *mapping = nil; + __block FEMMapping *carMapping = nil; beforeEach(^{ representation = [CMFixture buildUsingFixture:@"PersonWithCar_1"]; diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index c0f63e5..db3f22a 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -16,7 +16,7 @@ #import "FEMRelationship.h" #import "FEMMapping.h" -#import "FEMManagedObjectMapping.h" +#import "FEMMapping.h" #import "Phone.h" SPEC_BEGIN(FEMManagedObjectDeserializerSpec) @@ -314,7 +314,7 @@ beforeAll(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; - FEMManagedObjectMapping *mapping = [MappingProvider personMapping]; + FEMMapping *mapping = [MappingProvider personMapping]; person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation mapping:mapping context:moc]; }); @@ -334,7 +334,7 @@ describe(@"relationship assignment policy", ^{ __block NSDictionary *externalRepresentation_v1 = nil; __block NSDictionary *externalRepresentation_v2 = nil; - __block FEMManagedObjectMapping *mapping = nil; + __block FEMMapping *mapping = nil; __block FEMRelationship *relationshipMapping = nil; context(@"to-one", ^{ @@ -501,7 +501,7 @@ describe(@"synchronization", ^{ __block Car *car; __block NSDictionary *externalRepresentation; - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ externalRepresentation = @{ diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m index d800f7d..78e6acf 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m @@ -2,30 +2,30 @@ #import "Kiwi.h" #import "Person.h" -#import "FEMManagedObjectMapping.h" +#import "FEMMapping.h" -SPEC_BEGIN(FEMManagedObjectMappingSpec) +SPEC_BEGIN(FEMMappingSpec) -describe(@"FEMManagedObjectMapping", ^{ +describe(@"FEMMapping", ^{ describe(@"class methods", ^{ specify(^{ - [[FEMManagedObjectMapping should] respondToSelector:@selector(mappingForEntityName:configuration:)]; + [[FEMMapping should] respondToSelector:@selector(mappingForEntityName:configuration:)]; }); specify(^{ - [[FEMManagedObjectMapping should] respondToSelector:@selector(mappingForEntityName:rootPath:configuration:)]; + [[FEMMapping should] respondToSelector:@selector(mappingForEntityName:rootPath:configuration:)]; }); }); describe(@"constructors", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Temp"]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Temp"]; }); specify(^{ @@ -40,10 +40,10 @@ describe(@"properties", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Temp"]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Temp"]; }); specify(^{ @@ -65,11 +65,11 @@ describe(@".mappingForClass:configuration:", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [FEMManagedObjectMapping mappingForEntityName:@"Car" - configuration:^(FEMManagedObjectMapping *mapping) { + mapping = [FEMMapping mappingForEntityName:@"Car" + configuration:^(FEMMapping *mapping) { }]; }); @@ -86,12 +86,12 @@ describe(@".mappingForClass:rootPath:configuration:", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [FEMManagedObjectMapping mappingForEntityName:@"Car" + mapping = [FEMMapping mappingForEntityName:@"Car" rootPath:@"car" - configuration:^(FEMManagedObjectMapping *mapping) { + configuration:^(FEMMapping *mapping) { }]; }); @@ -112,10 +112,10 @@ describe(@"#initWithObjectClass:", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Car"]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; }); specify(^{ @@ -129,10 +129,10 @@ describe(@"#initWithObjectClass:rootPath:", ^{ - __block FEMManagedObjectMapping *mapping; + __block FEMMapping *mapping; beforeEach(^{ - mapping = [[FEMManagedObjectMapping alloc] initWithEntityName:@"Car" rootPath:@"car"]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Car" rootPath:@"car"]; }); specify(^{ From 6565614b3ea99a1a29b9dcd601ded64bcbeb5c60 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:53:55 +0300 Subject: [PATCH 34/95] Replace FEMObjectMapping by FEMMapping --- .../Mapping Provider/MappingProvider.m | 2 +- .../Mapping Provider/MappingProviderNative.h | 34 ++++----- .../Mapping Provider/MappingProviderNative.m | 69 ++++++++++--------- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/FastEasyMappingTests/Mapping Provider/MappingProvider.m b/FastEasyMappingTests/Mapping Provider/MappingProvider.m index 2788989..d19c7db 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProvider.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProvider.m @@ -4,7 +4,7 @@ #import "Car.h" #import "Phone.h" #import "Person.h" -#import "FEMObjectMapping.h" +#import "FEMMapping.h" #import "FEMManagedObjectMapping.h" #import "FEMAttribute.h" #import "FEMRelationship.h" diff --git a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.h b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.h index c30d7b8..f2dade7 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.h +++ b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.h @@ -2,25 +2,25 @@ #import -@class FEMObjectMapping; +@class FEMMapping; @interface MappingProviderNative : NSObject -+ (FEMObjectMapping *)carMapping; -+ (FEMObjectMapping *)carWithRootKeyMapping; -+ (FEMObjectMapping *)carNestedAttributesMapping; -+ (FEMObjectMapping *)carWithDateMapping; -+ (FEMObjectMapping *)phoneMapping; -+ (FEMObjectMapping *)personMapping; -+ (FEMObjectMapping *)personWithCarMapping; -+ (FEMObjectMapping *)personWithPhonesMapping; -+ (FEMObjectMapping *)personWithOnlyValueBlockMapping; -+ (FEMObjectMapping *)addressMapping; -+ (FEMObjectMapping *)fingerMapping; -+ (FEMObjectMapping *)nativeMapping; -+ (FEMObjectMapping *)nativeMappingWithNullPropertie; -+ (FEMObjectMapping *)planeMapping; -+ (FEMObjectMapping *)alienMapping; -+ (FEMObjectMapping *)nativeChildMapping; ++ (FEMMapping *)carMapping; ++ (FEMMapping *)carWithRootKeyMapping; ++ (FEMMapping *)carNestedAttributesMapping; ++ (FEMMapping *)carWithDateMapping; ++ (FEMMapping *)phoneMapping; ++ (FEMMapping *)personMapping; ++ (FEMMapping *)personWithCarMapping; ++ (FEMMapping *)personWithPhonesMapping; ++ (FEMMapping *)personWithOnlyValueBlockMapping; ++ (FEMMapping *)addressMapping; ++ (FEMMapping *)fingerMapping; ++ (FEMMapping *)nativeMapping; ++ (FEMMapping *)nativeMappingWithNullPropertie; ++ (FEMMapping *)planeMapping; ++ (FEMMapping *)alienMapping; ++ (FEMMapping *)nativeChildMapping; @end diff --git a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m index 872347f..a5821d7 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m @@ -12,27 +12,28 @@ #import "NativeChild.h" #import "CatNative.h" -#import "FEMObjectMapping.h" +#import "FEMMapping.h" #import "FEMAttribute.h" +#import "FEMObjectMapping.h" @implementation MappingProviderNative -+ (FEMObjectMapping *)carMapping { - return [FEMObjectMapping mappingForClass:[CarNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)carMapping { + return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model", @"year"]]; }]; } -+ (FEMObjectMapping *)carWithRootKeyMapping { - return [FEMObjectMapping mappingForClass:[CarNative class] ++ (FEMMapping *)carWithRootKeyMapping { + return [FEMMapping mappingForClass:[CarNative class] rootPath:@"car" - configuration:^(FEMObjectMapping *mapping) { + configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model", @"year"]]; }]; } -+ (FEMObjectMapping *)carNestedAttributesMapping { - return [FEMObjectMapping mappingForClass:[CarNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)carNestedAttributesMapping { + return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model"]]; [mapping addAttributesDictionary:@{ @"year" : @"information.year" @@ -40,8 +41,8 @@ + (FEMObjectMapping *)carNestedAttributesMapping { }]; } -+ (FEMObjectMapping *)carWithDateMapping { - return [FEMObjectMapping mappingForClass:[CarNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)carWithDateMapping { + return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model", @"year"]]; [mapping addAttribute:[FEMAttribute mappingOfProperty:@"createdAt" toKeyPath:@"created_at" @@ -49,8 +50,8 @@ + (FEMObjectMapping *)carWithDateMapping { }]; } -+ (FEMObjectMapping *)phoneMapping { - return [FEMObjectMapping mappingForClass:[PhoneNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)phoneMapping { + return [FEMMapping mappingForClass:[PhoneNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"number"]]; [mapping addAttributesDictionary:@{ @"DDI" : @"ddi", @@ -59,8 +60,8 @@ + (FEMObjectMapping *)phoneMapping { }]; } -+ (FEMObjectMapping *)personMapping { - return [FEMObjectMapping mappingForClass:[PersonNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)personMapping { + return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; [mapping addAttributesFromArray:@[@"name", @"email"]]; [mapping addAttribute:[FEMAttribute mappingOfProperty:@"gender" @@ -77,22 +78,22 @@ + (FEMObjectMapping *)personMapping { }]; } -+ (FEMObjectMapping *)personWithCarMapping { - return [FEMObjectMapping mappingForClass:[PersonNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)personWithCarMapping { + return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"name", @"email"]]; [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; }]; } -+ (FEMObjectMapping *)personWithPhonesMapping { - return [FEMObjectMapping mappingForClass:[PersonNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)personWithPhonesMapping { + return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"name", @"email"]]; [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; }]; } -+ (FEMObjectMapping *)personWithOnlyValueBlockMapping { - return [FEMObjectMapping mappingForClass:[PersonNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)personWithOnlyValueBlockMapping { + return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; [mapping addAttributesFromArray:@[@"name", @"email"]]; [mapping addAttribute:[FEMAttribute mappingOfProperty:@"gender" @@ -106,8 +107,8 @@ + (FEMObjectMapping *)personWithOnlyValueBlockMapping { }]; } -+ (FEMObjectMapping *)addressMapping { - return [FEMObjectMapping mappingForClass:[AddressNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)addressMapping { + return [FEMMapping mappingForClass:[AddressNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"street"]]; [mapping addAttribute:[FEMAttribute mappingOfProperty:@"location" toKeyPath:@"location" @@ -126,8 +127,8 @@ + (FEMObjectMapping *)addressMapping { }]; } -+ (FEMObjectMapping *)nativeMapping { - return [FEMObjectMapping mappingForClass:[Native class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)nativeMapping { + return [FEMMapping mappingForClass:[Native class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[ @"charProperty", @"unsignedCharProperty", @@ -149,34 +150,34 @@ + (FEMObjectMapping *)nativeMapping { }]; } -+ (FEMObjectMapping *)nativeMappingWithNullPropertie { - return [FEMObjectMapping mappingForClass:[CatNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)nativeMappingWithNullPropertie { + return [FEMMapping mappingForClass:[CatNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"age"]]; }]; } -+ (FEMObjectMapping *)planeMapping { - return [FEMObjectMapping mappingForClass:[PlaneNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)planeMapping { + return [FEMMapping mappingForClass:[PlaneNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesDictionary:@{@"flightNumber" : @"flight_number"}]; [mapping addToManyRelationshipMapping:[self personMapping] forProperty:@"persons" keyPath:@"persons"]; }]; } -+ (FEMObjectMapping *)alienMapping { - return [FEMObjectMapping mappingForClass:[AlienNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)alienMapping { + return [FEMMapping mappingForClass:[AlienNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"name"]]; [mapping addToManyRelationshipMapping:[self fingerMapping] forProperty:@"fingers" keyPath:@"fingers"]; }]; } -+ (FEMObjectMapping *)fingerMapping { - return [FEMObjectMapping mappingForClass:[FingerNative class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)fingerMapping { + return [FEMMapping mappingForClass:[FingerNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"name"]]; }]; } -+ (FEMObjectMapping *)nativeChildMapping { - return [FEMObjectMapping mappingForClass:[NativeChild class] configuration:^(FEMObjectMapping *mapping) { ++ (FEMMapping *)nativeChildMapping { + return [FEMMapping mappingForClass:[NativeChild class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"intProperty", @"boolProperty", @"childProperty"]]; }]; } From 372e2be8df87f2da2befa219ce04ab63ce34f03c Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 15:55:00 +0300 Subject: [PATCH 35/95] Replace FEMObjectDeserializer by FEMDeserializer --- .../Specs/FEMManagedObjectDeserializerSpec.m | 2 +- .../Specs/FEMObjectDeserializerSpec.m | 40 +++++++++---------- .../Specs/FEMSerializerSpec.m | 10 ++--- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index db3f22a..8ba12d5 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -12,7 +12,7 @@ #import "FEMRelationship.h" #import "FEMManagedObjectDeserializer.h" -#import "FEMObjectDeserializer.h" +#import "FEMDeserializer.h" #import "FEMRelationship.h" #import "FEMMapping.h" diff --git a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m index 54d15e6..d6997b6 100644 --- a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m @@ -14,12 +14,12 @@ #import "AlienNative.h" #import "FingerNative.h" #import "CatNative.h" -#import "FEMObjectDeserializer.h" +#import "FEMDeserializer.h" #import "FEMObjectMapping.h" -SPEC_BEGIN(FEMObjectDeserializerSpec) +SPEC_BEGIN(FEMDeserializerSpec) -describe(@"FEMObjectDeserializer", ^{ +describe(@"FEMDeserializer", ^{ describe(@".objectFromExternalRepresentation:withMapping:", ^{ @@ -30,7 +30,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative carMapping]]; }); @@ -55,7 +55,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative carWithRootKeyMapping]]; externalRepresentation = [externalRepresentation objectForKey:@"car"]; }); @@ -81,7 +81,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative carNestedAttributesMapping]]; }); @@ -106,7 +106,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative carWithDateMapping]]; }); @@ -144,7 +144,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Male"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; }); @@ -161,7 +161,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Female"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; }); @@ -178,7 +178,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Address"]; - address = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + address = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative addressMapping]]; }); @@ -211,7 +211,7 @@ expectedCar = [carFactory build]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative personMapping]]; }); @@ -240,7 +240,7 @@ [mapping addRelationshipMapping:[MappingProviderNative carMapping] forProperty:@"car" keyPath:@"vehicle"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; }); @@ -268,7 +268,7 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative personMapping]]; }); @@ -292,7 +292,7 @@ forProperty:@"phones" keyPath:@"cellphones"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; }); @@ -322,7 +322,7 @@ beforeEach(^{ FEMObjectMapping * mapping = [MappingProviderNative nativeMapping]; NSDictionary * externalRepresentation = [CMFixture buildUsingFixture:@"Native"]; - native = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + native = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; }); @@ -412,7 +412,7 @@ beforeEach(^{ FEMObjectMapping *catMapping = [MappingProviderNative nativeMappingWithNullPropertie]; NSDictionary *values = @{ @"age": [NSNull null] }; - cat = [FEMObjectDeserializer deserializeObjectExternalRepresentation:values + cat = [FEMDeserializer deserializeObjectExternalRepresentation:values usingMapping:catMapping]; }); @@ -437,7 +437,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Cars"]; - carsArray = [FEMObjectDeserializer deserializeCollectionExternalRepresentation:externalRepresentation + carsArray = [FEMDeserializer deserializeCollectionExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative carMapping]]; }); @@ -463,7 +463,7 @@ [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"stewardess" keyPath:@"stewardess"]; [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"stars" keyPath:@"stars"]; - plane = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + plane = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; }); @@ -498,7 +498,7 @@ FEMObjectMapping * mapping = [[FEMObjectMapping alloc] initWithObjectClass:[SeaplaneNative class]]; [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"passengers" keyPath:@"persons"]; - seaplane = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + seaplane = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; }); @@ -518,7 +518,7 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Alien"]; - alien = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + alien = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative alienMapping]]; }); diff --git a/FastEasyMappingTests/Specs/FEMSerializerSpec.m b/FastEasyMappingTests/Specs/FEMSerializerSpec.m index 59afc9e..39f7a65 100644 --- a/FastEasyMappingTests/Specs/FEMSerializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMSerializerSpec.m @@ -12,7 +12,7 @@ #import "NativeChild.h" #import "FEMSerializer.h" #import "FEMObjectMapping.h" -#import "FEMObjectDeserializer.h" +#import "FEMDeserializer.h" #import SPEC_BEGIN(FEMSerializerSpec) @@ -307,7 +307,7 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; representation = [FEMSerializer serializeObject:person usingMapping:mapping]; @@ -379,7 +379,7 @@ keyPath:@"cellphones"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping]; representation = [FEMSerializer serializeObject:person usingMapping:mapping]; @@ -413,7 +413,7 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Native"]; - native = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + native = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative nativeMapping]]; representation = [FEMSerializer serializeObject:native usingMapping:[MappingProviderNative nativeMapping]]; @@ -507,7 +507,7 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"NativeChild"]; - nativeChild = [FEMObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation + nativeChild = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:[MappingProviderNative nativeChildMapping]]; representation = [FEMSerializer serializeObject:nativeChild usingMapping:[MappingProviderNative nativeChildMapping]]; From 8edc2bd470b3bc38159aaa5e70cae02e8cd56a1d Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 16:13:37 +0300 Subject: [PATCH 36/95] Compatibility improvements --- .../Core/Deserializer/FEMDeserializer.h | 23 +++ .../Core/Deserializer/FEMDeserializer.m | 12 +- .../FEMManagedObjectDeserializer.h | 20 +- .../Core/Deserializer/FEMObjectDeserializer.h | 11 +- .../Source/Core/Mapping/FEMMapping.h | 18 +- .../Source/Core/Mapping/FEMMapping.m | 13 +- .../Mapping/Object/FEMManagedObjectMapping.h | 11 +- .../Core/Mapping/Object/FEMObjectMapping.h | 13 +- FastEasyMappingTests/Specs/FEMCacheSpec.m | 30 ++- .../Specs/FEMManagedObjectDeserializerSpec.m | 188 +++++++++--------- .../Specs/FEMManagedObjectMappingSpec.m | 2 + .../Specs/FEMObjectDeserializerSpec.m | 1 + .../Specs/FEMSerializerSpec.m | 1 + 13 files changed, 165 insertions(+), 178 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 2ac7f70..52fbe56 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -1,6 +1,7 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import +#import "FEMManagedObjectMapping.h" @class FEMObjectStore, FEMMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; @@ -25,4 +26,26 @@ + (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; + (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; +@end + + +@interface FEMDeserializer (FEMObjectDeserializer_Deprecated) + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); + +@end + +@interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) + ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); + ++ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation + usingMapping:(FEMMapping *)mapping + predicate:(NSPredicate *)predicate + context:(NSManagedObjectContext *)context __attribute__((unavailable)); + @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 13f6235..1867ef7 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -170,15 +170,15 @@ + (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEM @implementation FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { return [self objectFromRepresentation:externalRepresentation mapping:mapping context:context]; } -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping { ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; } -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context { ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { return [self collectionFromRepresentation:externalRepresentation mapping:mapping context:context]; } @@ -186,15 +186,15 @@ + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepr @implementation FEMDeserializer (FEMObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { return [self objectFromRepresentation:externalRepresentation mapping:mapping]; } -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; } -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping { ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping { return [self collectionFromRepresentation:externalRepresentation mapping:mapping]; } diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h index 5d2d750..2832822 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMManagedObjectDeserializer.h @@ -1,23 +1,5 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project -#import - #import "FEMDeserializer.h" -#import "FEMManagedObjectMapping.h" - -@class NSManagedObject, NSFetchRequest, NSManagedObjectContext; - -@compatibility_alias FEMManagedObjectDeserializer FEMDeserializer; - -@interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMManagedObjectMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); - -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMManagedObjectMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context __attribute__((unavailable)); -@end \ No newline at end of file +@compatibility_alias FEMManagedObjectDeserializer FEMDeserializer; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h index f268608..1fd41cb 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMObjectDeserializer.h @@ -1,14 +1,5 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMDeserializer.h" -#import "FEMObjectMapping.h" -@compatibility_alias FEMObjectDeserializer FEMDeserializer; - -@interface FEMDeserializer (FEMObjectDeserializer_Deprecated) - -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMObjectMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); - -@end \ No newline at end of file +@compatibility_alias FEMObjectDeserializer FEMDeserializer; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index ed6fcb2..47afc9f 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -50,4 +50,20 @@ - (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; -@end \ No newline at end of file +@end + +@interface FEMMapping (FEMObjectMapping_Deprecated) + ++ (FEMMapping *)mappingForClass:(Class)objectClass configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); ++ (FEMMapping *)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); + +@end + + +@interface FEMMapping (FEMManagedObjectMapping_Deprecated) + ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); + +@end diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 257aa96..b1cdcb2 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -171,19 +171,19 @@ - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString @implementation FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (instancetype)mappingForEntityName:(NSString *)entityName { ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName { FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName]; return mapping; } -+ (instancetype)mappingForEntityName:(NSString *)entityName ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName]; configuration(mapping); return mapping; } -+ (instancetype)mappingForEntityName:(NSString *)entityName ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMManagedObjectMapping *sender))configuration { FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:entityName rootPath:rootPath]; @@ -195,16 +195,13 @@ + (instancetype)mappingForEntityName:(NSString *)entityName @implementation FEMMapping (FEMObjectMapping_Deprecated) -+ (instancetype)mappingForClass:(Class)objectClass - configuration:(void (^)(FEMObjectMapping *mapping))configuration { ++ (FEMMapping *)mappingForClass:(Class)objectClass configuration:(void (^)(FEMObjectMapping *mapping))configuration { FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:objectClass]; configuration(mapping); return mapping; } -+ (instancetype)mappingForClass:(Class)objectClass - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration { ++ (FEMMapping *)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMObjectMapping *mapping))configuration { FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:objectClass rootPath:rootPath]; configuration(mapping); return mapping; diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 2a510ec..3bb97ec 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -8,15 +8,6 @@ #import -#import "FEMTypes.h" #import "FEMMapping.h" -@compatibility_alias FEMManagedObjectMapping FEMMapping; - -@interface FEMMapping (FEMManagedObjectMapping_Deprecated) - -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMManagedObjectMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMManagedObjectMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); - -@end +@compatibility_alias FEMManagedObjectMapping FEMMapping; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h index dd46f5f..58f78a8 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h @@ -2,15 +2,4 @@ #import "FEMMapping.h" -@compatibility_alias FEMObjectMapping FEMMapping; - -@interface FEMMapping (FEMObjectMapping_Deprecated) - -+ (FEMObjectMapping *)mappingForClass:(Class)objectClass - configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); - -+ (FEMObjectMapping *)mappingForClass:(Class)objectClass - rootPath:(NSString *)rootPath - configuration:(void (^)(FEMObjectMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); - -@end +@compatibility_alias FEMObjectMapping FEMMapping; \ No newline at end of file diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 221d923..65de1fd 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -14,10 +14,8 @@ #import "Car.h" #import "FEMDeserializer.h" -#import "FEMRelationshipMapping.h" - -#import "FEMManagedObjectDeserializer.h" #import "FEMRelationship.h" +#import "FEMManagedObjectDeserializer.h" SPEC_BEGIN(FEMCacheSpec) @@ -86,9 +84,9 @@ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] beNil]; - Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation - mapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [cache addExistingObject:car mapping:mapping]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] equal:car]; @@ -97,8 +95,8 @@ it(@"should return registered object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation - mapping:mapping + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; @@ -110,9 +108,9 @@ it(@"should return saved object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectFromRepresentation:representation - mapping:mapping - context:context]; + Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [context MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:context]) should] equal:@1]; @@ -148,17 +146,17 @@ }); it(@"should return nil for missing nested object", ^{ - [FEMDeserializer deserializeObjectFromRepresentation:representation - mapping:mapping - context:context]; + [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping + context:context]; id missingObjectRepresentation = @{@"id": @2}; [[[cache existingObjectForRepresentation:missingObjectRepresentation mapping:carMapping] should] beNil]; }); it(@"should return existing nested object", ^{ - Person *person = [FEMDeserializer deserializeObjectFromRepresentation:representation - mapping:mapping + Person *person = [FEMDeserializer deserializeObjectExternalRepresentation:representation + usingMapping:mapping context:context]; [[[cache existingObjectForRepresentation:representation[@"car"] mapping:carMapping] should] equal:person.car]; }); diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index 8ba12d5..e06a443 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -11,15 +11,11 @@ #import "FEMDeserializer.h" #import "FEMRelationship.h" -#import "FEMManagedObjectDeserializer.h" -#import "FEMDeserializer.h" -#import "FEMRelationship.h" - -#import "FEMMapping.h" #import "FEMMapping.h" #import "Phone.h" +#import "FEMManagedObjectDeserializer.h" -SPEC_BEGIN(FEMManagedObjectDeserializerSpec) +SPEC_BEGIN(FEMDeserializerSpec) describe(@"FEMDeserializer", ^{ __block NSManagedObjectContext *moc; @@ -46,8 +42,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carMapping] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMapping] context:moc]; }); @@ -83,8 +79,8 @@ @"year" : @"2013" }; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carMappingWithPrimaryKey] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMappingWithPrimaryKey] context:moc]; }); @@ -125,8 +121,8 @@ oldCar.model = @""; externalRepresentation = @{@"id" : @(1), @"model" : @"i30",}; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carMappingWithPrimaryKey] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carMappingWithPrimaryKey] context:moc]; }); @@ -154,8 +150,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carWithRootKeyMapping] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carWithRootKeyMapping] context:moc]; externalRepresentation = [externalRepresentation objectForKey:@"car"]; }); @@ -180,8 +176,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carNestedAttributesMapping] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carNestedAttributesMapping] context:moc]; }); @@ -206,8 +202,8 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider carWithDateMapping] + car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider carWithDateMapping] context:moc]; }); @@ -246,8 +242,8 @@ expectedCar.year = @"2013"; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider personMapping] + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider personMapping] context:moc]; }); @@ -271,8 +267,8 @@ beforeEach(^{ moc = [NSManagedObjectContext MR_defaultContext]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation - mapping:[MappingProvider personMapping] + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation + usingMapping:[MappingProvider personMapping] context:moc]; }); @@ -288,7 +284,7 @@ }); - describe(@".deserializeCollectionExternalRepresentation:usingMapping:", ^{ + describe(@".deserializeCollectionExternalRepresentation:usingusingMapping:", ^{ __block NSArray *carsArray; __block NSArray *externalRepresentation; @@ -315,7 +311,7 @@ beforeAll(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; FEMMapping *mapping = [MappingProvider personMapping]; - person = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation mapping:mapping context:moc]; + person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:moc]; }); context(@"to-one", ^{ @@ -357,8 +353,8 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyAssign; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 - mapping:mapping + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping context:moc]; [moc MR_saveToPersistentStoreAndWait]; @@ -367,8 +363,8 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v2 - mapping:mapping + Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping context:moc]; [[person_v1 should] equal:person_v2]; @@ -384,8 +380,8 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectMerge; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 - mapping:mapping + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping context:moc]; [moc MR_saveToPersistentStoreAndWait]; @@ -394,8 +390,8 @@ Car *car_v1 = person_v1.car; [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - Person *person_v2 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v2 - mapping:mapping + Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 + usingMapping:mapping context:moc]; [moc MR_saveToPersistentStoreAndWait]; @@ -412,8 +408,8 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectReplace; [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 - mapping:mapping + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping context:moc]; Car *car_v1 = person_v1.car; @@ -451,8 +447,8 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionMerge; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 - mapping:mapping + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping context:moc]; [moc MR_saveToPersistentStoreAndWait]; @@ -477,8 +473,8 @@ relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionReplace; [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectFromRepresentation:externalRepresentation_v1 - mapping:mapping + Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 + usingMapping:mapping context:moc]; [moc MR_saveToPersistentStoreAndWait]; @@ -498,64 +494,64 @@ }); }); - describe(@"synchronization", ^{ - __block Car *car; - __block NSDictionary *externalRepresentation; - __block FEMMapping *mapping; - - beforeEach(^{ - externalRepresentation = @{ - @"id": @2, - @"model": @"i30", - @"year": @"2014" - }; - - car = [Car MR_createInContext:moc]; - [car setCarID:@1]; - - mapping = [MappingProvider carMappingWithPrimaryKey]; - }); - - context(@"without predicate", ^{ - it(@"should replace all existing objects", ^{ - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - - [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:nil - context:moc]; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - Car *existingCar = [Car MR_findFirstInContext:moc]; - [[existingCar.carID should] equal:@2]; - }); - }); - - context(@"with predicate", ^{ - it(@"should replace objects specified by predicate", ^{ - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID == 1"]; - [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:predicate - context:moc]; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - Car *existingCar = [Car MR_findFirstInContext:moc]; - [[existingCar.carID should] equal:@2]; - }); - - it(@"should not replace objects not specified by predicate", ^{ - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - - NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID != 1"]; - [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] - usingMapping:mapping - predicate:predicate - context:moc]; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@2]; - }); - }); - }); +// describe(@"synchronization", ^{ +// __block Car *car; +// __block NSDictionary *externalRepresentation; +// __block FEMMapping *mapping; +// +// beforeEach(^{ +// externalRepresentation = @{ +// @"id": @2, +// @"model": @"i30", +// @"year": @"2014" +// }; +// +// car = [Car MR_createInContext:moc]; +// [car setCarID:@1]; +// +// mapping = [MappingProvider carMappingWithPrimaryKey]; +// }); + +// context(@"without predicate", ^{ +// it(@"should replace all existing objects", ^{ +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; +// +// [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] +// usingMapping:mapping +// predicate:nil +// context:moc]; +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; +// Car *existingCar = [Car MR_findFirstInContext:moc]; +// [[existingCar.carID should] equal:@2]; +// }); +// }); +// +// context(@"with predicate", ^{ +// it(@"should replace objects specified by predicate", ^{ +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; +// +// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID == 1"]; +// [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] +// usingMapping:mapping +// predicate:predicate +// context:moc]; +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; +// Car *existingCar = [Car MR_findFirstInContext:moc]; +// [[existingCar.carID should] equal:@2]; +// }); +// +// it(@"should not replace objects not specified by predicate", ^{ +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; +// +// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID != 1"]; +// [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] +// usingMapping:mapping +// predicate:predicate +// context:moc]; +// [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@2]; +// }); +// }); +// }); }); SPEC_END diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m index 78e6acf..876a010 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m @@ -3,6 +3,8 @@ #import "Kiwi.h" #import "Person.h" #import "FEMMapping.h" +#import "FEMObjectMapping.h" +#import "FEMManagedObjectMapping.h" SPEC_BEGIN(FEMMappingSpec) diff --git a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m index d6997b6..2421009 100644 --- a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m @@ -16,6 +16,7 @@ #import "CatNative.h" #import "FEMDeserializer.h" #import "FEMObjectMapping.h" +#import "FEMObjectDeserializer.h" SPEC_BEGIN(FEMDeserializerSpec) diff --git a/FastEasyMappingTests/Specs/FEMSerializerSpec.m b/FastEasyMappingTests/Specs/FEMSerializerSpec.m index 39f7a65..23e8913 100644 --- a/FastEasyMappingTests/Specs/FEMSerializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMSerializerSpec.m @@ -13,6 +13,7 @@ #import "FEMSerializer.h" #import "FEMObjectMapping.h" #import "FEMDeserializer.h" +#import "FEMObjectDeserializer.h" #import SPEC_BEGIN(FEMSerializerSpec) From 636d54d153540e9fc3b9ce425b671de4422152cf Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 16:16:50 +0300 Subject: [PATCH 37/95] Final adjustments --- .../Source/Core/Mapping/FEMMapping.h | 2 +- .../Source/Core/Mapping/FEMMapping.m | 2 +- .../Mapping Provider/MappingProvider.h | 20 +++---- .../Mapping Provider/MappingProvider.m | 58 +++++++++---------- .../Mapping Provider/MappingProviderNative.m | 6 +- .../Specs/FEMObjectMappingSpec.m | 2 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index 47afc9f..dd2a200 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -44,7 +44,7 @@ @interface FEMMapping (Shortcut) - (void)addAttributesFromArray:(NSArray *)attributes; -- (void)addAttributesDictionary:(NSDictionary *)attributesToKeyPath; +- (void)addAttributesFromDictionary:(NSDictionary *)attributesToKeyPath; - (void)addAttributeWithProperty:(NSString *)property keyPath:(NSString *)keyPath; - (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index b1cdcb2..5a186e4 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -136,7 +136,7 @@ - (NSString *)description { @implementation FEMMapping (Shortcut) -- (void)addAttributesDictionary:(NSDictionary *)attributesToKeyPath { +- (void)addAttributesFromDictionary:(NSDictionary *)attributesToKeyPath { [attributesToKeyPath enumerateKeysAndObjectsUsingBlock:^(id attribute, id keyPath, BOOL *stop) { [self addAttribute:[FEMAttribute mappingOfProperty:attribute toKeyPath:keyPath]]; }]; diff --git a/FastEasyMappingTests/Mapping Provider/MappingProvider.h b/FastEasyMappingTests/Mapping Provider/MappingProvider.h index 223da76..735d78b 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProvider.h +++ b/FastEasyMappingTests/Mapping Provider/MappingProvider.h @@ -2,19 +2,19 @@ #import -@class FEMManagedObjectMapping; +@class FEMMapping; @interface MappingProvider : NSObject -+ (FEMManagedObjectMapping *)carMappingWithPrimaryKey; -+ (FEMManagedObjectMapping *)carMapping; -+ (FEMManagedObjectMapping *)carWithRootKeyMapping; -+ (FEMManagedObjectMapping *)carNestedAttributesMapping; -+ (FEMManagedObjectMapping *)carWithDateMapping; -+ (FEMManagedObjectMapping *)phoneMapping; -+ (FEMManagedObjectMapping *)personMapping; ++ (FEMMapping *)carMappingWithPrimaryKey; ++ (FEMMapping *)carMapping; ++ (FEMMapping *)carWithRootKeyMapping; ++ (FEMMapping *)carNestedAttributesMapping; ++ (FEMMapping *)carWithDateMapping; ++ (FEMMapping *)phoneMapping; ++ (FEMMapping *)personMapping; -+ (FEMManagedObjectMapping *)personWithPhoneMapping; -+ (FEMManagedObjectMapping *)personWithCarMapping; ++ (FEMMapping *)personWithPhoneMapping; ++ (FEMMapping *)personWithCarMapping; @end diff --git a/FastEasyMappingTests/Mapping Provider/MappingProvider.m b/FastEasyMappingTests/Mapping Provider/MappingProvider.m index d19c7db..5553c4e 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProvider.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProvider.m @@ -5,48 +5,48 @@ #import "Phone.h" #import "Person.h" #import "FEMMapping.h" -#import "FEMManagedObjectMapping.h" +#import "FEMMapping.h" #import "FEMAttribute.h" #import "FEMRelationship.h" @implementation MappingProvider -+ (FEMManagedObjectMapping *)carMappingWithPrimaryKey { - FEMManagedObjectMapping *mapping = [self carMapping]; ++ (FEMMapping *)carMappingWithPrimaryKey { + FEMMapping *mapping = [self carMapping]; [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesDictionary:@{@"carID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; return mapping; } -+ (FEMManagedObjectMapping *)carMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Car" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)carMapping { + return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model", @"year"]]; }]; } -+ (FEMManagedObjectMapping *)carWithRootKeyMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Car" ++ (FEMMapping *)carWithRootKeyMapping { + return [FEMMapping mappingForEntityName:@"Car" rootPath:@"car" - configuration:^(FEMManagedObjectMapping *mapping) { + configuration:^(FEMMapping *mapping) { // [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesDictionary:@{@"carID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; [mapping addAttributesFromArray:@[@"model", @"year"]]; }]; } -+ (FEMManagedObjectMapping *)carNestedAttributesMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Car" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)carNestedAttributesMapping { + return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { // [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesDictionary:@{@"carID" : @"id", @"year" : @"information.year"}]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id", @"year" : @"information.year"}]; [mapping addAttributesFromArray:@[@"model"]]; }]; } -+ (FEMManagedObjectMapping *)carWithDateMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Car" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)carWithDateMapping { + return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { // [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesDictionary:@{@"carID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; [mapping addAttributesFromArray:@[@"model", @"year"]]; [mapping addAttribute:[FEMAttribute mappingOfProperty:@"createdAt" toKeyPath:@"created_at" @@ -54,18 +54,18 @@ + (FEMManagedObjectMapping *)carWithDateMapping { }]; } -+ (FEMManagedObjectMapping *)phoneMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Phone" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)phoneMapping { + return [FEMMapping mappingForEntityName:@"Phone" configuration:^(FEMMapping *mapping) { // [mapping setPrimaryKey:@"phoneID"]; - [mapping addAttributesDictionary:@{@"phoneID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"phoneID" : @"id"}]; [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; }]; } -+ (FEMManagedObjectMapping *)personMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Person" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)personMapping { + return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { // [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesDictionary:@{@"personID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; [mapping addRelationship:[FEMRelationship mappingOfProperty:@"car" configuration:^(FEMRelationship *relationshipMapping) { @@ -81,15 +81,15 @@ + (FEMManagedObjectMapping *)personMapping { }]; } -+ (FEMManagedObjectMapping *)personWithPhoneMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Person" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)personWithPhoneMapping { + return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesDictionary:@{@"personID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; [mapping addRelationship:[FEMRelationship mappingOfProperty:@"phones" configuration:^(FEMRelationship *relationshipMapping) { - FEMManagedObjectMapping *phoneMapping = [self phoneMapping]; + FEMMapping *phoneMapping = [self phoneMapping]; [phoneMapping setPrimaryKey:@"phoneID"]; [relationshipMapping setToMany:YES]; @@ -98,10 +98,10 @@ + (FEMManagedObjectMapping *)personWithPhoneMapping { }]; } -+ (FEMManagedObjectMapping *)personWithCarMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Person" configuration:^(FEMManagedObjectMapping *mapping) { ++ (FEMMapping *)personWithCarMapping { + return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesDictionary:@{@"personID" : @"id"}]; + [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email"]]; [mapping addRelationship:[FEMRelationship mappingOfProperty:@"car" configuration:^(FEMRelationship *relationshipMapping) { diff --git a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m index a5821d7..c62b1e9 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m @@ -35,7 +35,7 @@ + (FEMMapping *)carWithRootKeyMapping { + (FEMMapping *)carNestedAttributesMapping { return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"model"]]; - [mapping addAttributesDictionary:@{ + [mapping addAttributesFromDictionary:@{ @"year" : @"information.year" }]; }]; @@ -53,7 +53,7 @@ + (FEMMapping *)carWithDateMapping { + (FEMMapping *)phoneMapping { return [FEMMapping mappingForClass:[PhoneNative class] configuration:^(FEMMapping *mapping) { [mapping addAttributesFromArray:@[@"number"]]; - [mapping addAttributesDictionary:@{ + [mapping addAttributesFromDictionary:@{ @"DDI" : @"ddi", @"DDD" : @"ddd", }]; @@ -158,7 +158,7 @@ + (FEMMapping *)nativeMappingWithNullPropertie { + (FEMMapping *)planeMapping { return [FEMMapping mappingForClass:[PlaneNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesDictionary:@{@"flightNumber" : @"flight_number"}]; + [mapping addAttributesFromDictionary:@{@"flightNumber" : @"flight_number"}]; [mapping addToManyRelationshipMapping:[self personMapping] forProperty:@"persons" keyPath:@"persons"]; }]; } diff --git a/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m index 02eb3ef..f842a44 100644 --- a/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m @@ -172,7 +172,7 @@ beforeEach(^{ mapping = [[FEMObjectMapping alloc] initWithObjectClass:[CarNative class]]; - [mapping addAttributesDictionary:@{ + [mapping addAttributesFromDictionary:@{ @"identifier" : @"id", @"email" : @"contact.email" }]; From 7654f01b562be72f9ae02ac6abda6a79519bf49f Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 16:19:15 +0300 Subject: [PATCH 38/95] Fix managed object store cache --- FastEasyMapping.xcodeproj/project.pbxproj | 2 ++ .../Source/Core/Store/FEMManagedObjectStore.m | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 6b9bfaf..8ca25f5 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD52DF811B037B1400E46915 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; + AD52DF821B03865000E46915 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -731,6 +732,7 @@ AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, + AD52DF821B03865000E46915 /* FEMManagedObjectStore.m in Sources */, 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index c3c2d5a..9be8cd2 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -16,14 +16,8 @@ @implementation FEMManagedObjectStore { FEMManagedObjectCache *_cache; - - NSManagedObjectContext *_managedObjectContext; - FEMManagedObjectMapping *_mapping; } -@synthesize mapping = _mapping; -@synthesize externalRepresentation = _externalRepresentation; - #pragma mark - Init - (instancetype)initWithContext:(NSManagedObjectContext *)context { @@ -36,13 +30,21 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { return self; } -#pragma mark - FEMDeserializerSource +#pragma mark - + +- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { + return [super performMappingTransaction:representation mapping:mapping transaction:^{ + _cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:self.context]; + transaction(); + _cache = nil; + }]; +} - (id)newObjectForMapping:(FEMMapping *)mapping { validateMapping(mapping); NSString *entityName = [mapping entityName]; - return [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:_managedObjectContext]; + return [NSEntityDescription insertNewObjectForEntityForName:entityName inManagedObjectContext:self.context]; } - (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { From 4144c2b359ac4f21329b5cb633ff02b3fcc3b9f7 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 17:45:25 +0300 Subject: [PATCH 39/95] Fix minor bugs --- FastEasyMapping.xcodeproj/project.pbxproj | 34 ++++++++++--------- .../Core/Deserializer/FEMDeserializer.m | 2 +- .../Source/Core/Mapping/FEMMapping.m | 7 ++-- .../Specs/FEMManagedObjectDeserializerSpec.m | 2 +- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 8ca25f5..8bd0090 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -16,10 +16,8 @@ 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; @@ -53,11 +51,6 @@ 2C375F3B18CCD40200FCB8EA /* Person.json in Resources */ = {isa = PBXBuildFile; fileRef = 69ED79AD80703DC44EFCC7EE /* Person.json */; }; 2C375F3C18CCD40200FCB8EA /* Car.json in Resources */ = {isa = PBXBuildFile; fileRef = 69ED74F0986B6C6DD2614CB7 /* Car.json */; }; 2C375F3D18CCD40200FCB8EA /* NativeChild.json in Resources */ = {isa = PBXBuildFile; fileRef = 69ED7CF6DFFBDF7A0BF32AFC /* NativeChild.json */; }; - 2C375F3E18CCD40A00FCB8EA /* FEMObjectMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7EC086EF5CE3263C6D8D /* FEMObjectMappingSpec.m */; }; - 2C375F3F18CCD40A00FCB8EA /* FEMObjectDeserializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7A9AEF651DACBF9BBC8F /* FEMObjectDeserializerSpec.m */; }; - 2C375F4018CCD40A00FCB8EA /* FEMSerializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED75B675560A0A804494CB /* FEMSerializerSpec.m */; }; - 2C375F4118CCD49B00FCB8EA /* FEMManagedObjectMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7C04E2BE02B24CFA1D7C /* FEMManagedObjectMappingSpec.m */; }; - 2C375F4218CCD49B00FCB8EA /* FEMManagedObjectDeserializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7C1B06B95B6C90EBB53A /* FEMManagedObjectDeserializerSpec.m */; }; 2C375F4318CCD49B00FCB8EA /* MappingProviderNative.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED799D533AED10DCFB4106 /* MappingProviderNative.m */; }; 2C375F4418CCD49B00FCB8EA /* MappingProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7532E1E5E3196BC27932 /* MappingProvider.m */; }; 2CF8097C18C3AD5700C07899 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CF8097B18C3AD5700C07899 /* Foundation.framework */; }; @@ -87,13 +80,21 @@ 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; + AD11B5EC1B038E8700B53F5A /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; + AD11B5ED1B038E8900B53F5A /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; - AD52DF811B037B1400E46915 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; AD52DF821B03865000E46915 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; + AD52DF831B0387C000E46915 /* FEMManagedObjectMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7C04E2BE02B24CFA1D7C /* FEMManagedObjectMappingSpec.m */; }; + AD52DF841B0387C000E46915 /* FEMManagedObjectDeserializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7C1B06B95B6C90EBB53A /* FEMManagedObjectDeserializerSpec.m */; }; + AD52DF851B0387C000E46915 /* FEMObjectMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7EC086EF5CE3263C6D8D /* FEMObjectMappingSpec.m */; }; + AD52DF861B0387C000E46915 /* FEMObjectDeserializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7A9AEF651DACBF9BBC8F /* FEMObjectDeserializerSpec.m */; }; + AD52DF871B0387C000E46915 /* FEMSerializerSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED75B675560A0A804494CB /* FEMSerializerSpec.m */; }; + AD52DF881B0387C000E46915 /* FEMCacheSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */; }; + AD52DF891B0387C000E46915 /* FEMAttributeMappingSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */; }; ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */; }; ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -736,8 +737,10 @@ 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */, 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */, 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, + AD11B5ED1B038E8900B53F5A /* FEMExcludableCollection.m in Sources */, 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, + AD11B5EC1B038E8700B53F5A /* FEMMergeableCollection.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, @@ -749,31 +752,30 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2C375F4118CCD49B00FCB8EA /* FEMManagedObjectMappingSpec.m in Sources */, - 2C375F4218CCD49B00FCB8EA /* FEMManagedObjectDeserializerSpec.m in Sources */, 2C375F4318CCD49B00FCB8EA /* MappingProviderNative.m in Sources */, 2C375F4418CCD49B00FCB8EA /* MappingProvider.m in Sources */, 2C375F1318CCD3FB00FCB8EA /* EasyMappingCoreDataExample.xcdatamodel in Sources */, - 2C375F3F18CCD40A00FCB8EA /* FEMObjectDeserializerSpec.m in Sources */, 2C375F1418CCD3FB00FCB8EA /* Car.m in Sources */, - AD52DF811B037B1400E46915 /* FEMMapping.m in Sources */, 2C375F1518CCD3FB00FCB8EA /* Phone.m in Sources */, 2C375F1618CCD3FB00FCB8EA /* Person.m in Sources */, 2C375F1718CCD3FB00FCB8EA /* NativeChild.m in Sources */, 2C375F1818CCD3FB00FCB8EA /* AddressNative.m in Sources */, 2C375F1918CCD3FB00FCB8EA /* CatNative.m in Sources */, + AD52DF831B0387C000E46915 /* FEMManagedObjectMappingSpec.m in Sources */, + AD52DF861B0387C000E46915 /* FEMObjectDeserializerSpec.m in Sources */, 2C375F1A18CCD3FB00FCB8EA /* PhoneNative.m in Sources */, + AD52DF851B0387C000E46915 /* FEMObjectMappingSpec.m in Sources */, + AD52DF841B0387C000E46915 /* FEMManagedObjectDeserializerSpec.m in Sources */, 2C375F1B18CCD3FB00FCB8EA /* PlaneNative.m in Sources */, 2C375F1C18CCD3FB00FCB8EA /* Native.m in Sources */, 2C375F1D18CCD3FB00FCB8EA /* FingerNative.m in Sources */, + AD52DF871B0387C000E46915 /* FEMSerializerSpec.m in Sources */, 2C375F1E18CCD3FB00FCB8EA /* SeaplaneNative.m in Sources */, 2C375F1F18CCD3FB00FCB8EA /* AlienNative.m in Sources */, + AD52DF881B0387C000E46915 /* FEMCacheSpec.m in Sources */, 2C375F2018CCD3FB00FCB8EA /* PersonNative.m in Sources */, - 2C375F3E18CCD40A00FCB8EA /* FEMObjectMappingSpec.m in Sources */, - 2C375F4018CCD40A00FCB8EA /* FEMSerializerSpec.m in Sources */, 2C375F2118CCD3FB00FCB8EA /* CarNative.m in Sources */, - 1D6A39844172720B32A975F4 /* FEMCacheSpec.m in Sources */, - 1D6A3C550D3AE60BEF5051D7 /* FEMAttributeMappingSpec.m in Sources */, + AD52DF891B0387C000E46915 /* FEMAttributeMappingSpec.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 1867ef7..e721691 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -151,7 +151,7 @@ + (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation ma } FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithStore:store]; - return [deserializer _fillObject:object fromRepresentation:representation mapping:mapping]; + return [deserializer fillObject:object fromRepresentation:representation mapping:mapping]; }; + (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m index 5a186e4..f0228a0 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m @@ -26,7 +26,7 @@ - (instancetype)initWithObjectClass:(Class)objectClass rootPath:(NSString *)root self.rootPath = rootPath; } - return nil; + return self; } - (instancetype)initWithEntityName:(NSString *)entityName { @@ -47,7 +47,7 @@ - (instancetype)initWithEntityName:(NSString *)entityName rootPath:(NSString *)r self.rootPath = rootPath; } - return nil; + return self; } #pragma mark - Attribute Mapping @@ -71,9 +71,6 @@ - (void)addPropertyMapping:(id)propertyMapping toMap:(NSMutableDict } - (void)addAttribute:(FEMAttribute *)attribute { - - - [self addPropertyMapping:attribute toMap:_attributeMap]; } diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index e06a443..8780170 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -15,7 +15,7 @@ #import "Phone.h" #import "FEMManagedObjectDeserializer.h" -SPEC_BEGIN(FEMDeserializerSpec) +SPEC_BEGIN(FEMManagedObjectDeserializerSpec) describe(@"FEMDeserializer", ^{ __block NSManagedObjectContext *moc; From 71c34bd9adc443a3f140506f5d71fbbaa491cb50 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 17:57:26 +0300 Subject: [PATCH 40/95] Add deserialiser delegate --- .../Core/Deserializer/FEMDeserializer.h | 14 ++++++++++++ .../Core/Deserializer/FEMDeserializer.m | 22 ++++++++++++++++++- .../Source/Core/Mapping/FEMMapping.h | 1 - 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 52fbe56..3d741ad 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -4,12 +4,26 @@ #import "FEMManagedObjectMapping.h" @class FEMObjectStore, FEMMapping, NSManagedObject, NSFetchRequest, NSManagedObjectContext; +@class FEMDeserializer; + +@protocol FEMDeserializerDelegate + +@optional +- (void)deserializer:(FEMDeserializer *)deserializer willMapObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(FEMDeserializer *)deserializer didMapObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; + +- (void)deserializer:(FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(FEMDeserializer *)deserializer didMapCollection:(NSArray *)collection fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; + +@end @interface FEMDeserializer : NSObject @property (nonatomic, strong, readonly) FEMObjectStore *store; - (id)initWithStore:(FEMObjectStore *)store; +@property (nonatomic, unsafe_unretained) id delegate; + - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index e721691..60c3db3 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -14,7 +14,16 @@ #import "FEMManagedObjectStore.h" #import "FEMObjectMapping.h" -@implementation FEMDeserializer +@implementation FEMDeserializer { + struct { + BOOL willMapObject: 1; + BOOL didMapObject: 1; + BOOL willMapCollection: 1; + BOOL didMapCollection: 1; + } _delegateFlags; +} + +#pragma mark - Init - (id)initWithStore:(FEMObjectStore *)store { NSParameterAssert(store != nil); @@ -26,6 +35,17 @@ - (id)initWithStore:(FEMObjectStore *)store { return self; } +#pragma mark - Delegate + +- (void)setDelegate:(id )delegate { + _delegate = delegate; + + _delegateFlags.willMapObject = [_delegate respondsToSelector:@selector(deserializer:willMapObjectFromRepresentation:mapping:)]; + _delegateFlags.didMapObject = [_delegate respondsToSelector:@selector(deserializer:didMapObject:fromRepresentation:mapping:)]; + _delegateFlags.willMapCollection = [_delegate respondsToSelector:@selector(deserializer:willMapCollectionFromRepresentation:mapping:)]; + _delegateFlags.didMapCollection = [_delegate respondsToSelector:@selector(deserializer:didMapCollection:fromRepresentation:mapping:)]; +} + #pragma mark - Deserialization - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary *)representation usingMapping:(FEMMapping *)mapping { diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h index dd2a200..d439bd5 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h @@ -22,7 +22,6 @@ - (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER; - (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath; - @property (nonatomic, readonly) Class objectClass; @property (nonatomic, copy, readonly) NSString *entityName; From 02847862a896222782ed939c86dcf1e3b333e428 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 18:00:12 +0300 Subject: [PATCH 41/95] Headers fix --- FastEasyMapping.xcodeproj/project.pbxproj | 16 ++++++++-------- .../Core/Assignment Policy/FEMAssignmentPolicy.h | 5 +---- .../Core/Assignment Policy/FEMAssignmentPolicy.m | 5 +---- .../Source/Core/Deserializer/FEMDeserializer.m | 2 -- .../Source/Core/Mapping/FEMProperty.h | 5 +---- .../Mapping/Object/FEMManagedObjectMapping.h | 8 +------- .../Core/Mapping/{ => Object}/FEMMapping.h | 0 .../Core/Mapping/{ => Object}/FEMMapping.m | 0 .../Source/Core/Store/FEMManagedObjectStore.h | 5 +---- .../Source/Core/Store/FEMManagedObjectStore.m | 5 +---- .../Source/Core/Store/FEMObjectStore.h | 5 +---- .../Source/Core/Store/FEMObjectStore.m | 5 +---- 12 files changed, 16 insertions(+), 45 deletions(-) rename FastEasyMapping/Source/Core/Mapping/{ => Object}/FEMMapping.h (100%) rename FastEasyMapping/Source/Core/Mapping/{ => Object}/FEMMapping.m (100%) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 8bd0090..532b1e7 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; + 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A348952AF3C9B329FC208 /* FEMMapping.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; @@ -15,6 +16,7 @@ 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; + 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3500E1995CD83C02D364 /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -69,12 +71,10 @@ 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7645386941DA79C1E53A /* NSArray+FEMPropertyRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */; settings = {ATTRIBUTES = (Private, ); }; }; 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757059F6C7A26468D880 /* NSArray+FEMPropertyRepresentation.m */; }; - 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED779509541DFE7A36679D /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED769040647781DD8B196D /* NSObject+FEMKVCExtension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED770C14BAB15CA7926116 /* NSObject+FEMKVCExtension.m */; }; 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7D24C1EE78C03CAB9C9B /* FEMManagedObjectCache.m */; }; 69ED7687C035FA51A536AB56 /* FEMTypeIntrospection.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */; }; - 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */; }; 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; @@ -133,6 +133,8 @@ 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; + 1D6A348952AF3C9B329FC208 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; + 1D6A3500E1995CD83C02D364 /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipAssignmentContext.h; sourceTree = ""; }; @@ -194,12 +196,10 @@ 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMDeserializer.m; sourceTree = ""; }; 69ED7745B6C0CD6C179EE0A8 /* CarNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CarNative.h; sourceTree = ""; }; 69ED775F5613FEA881051644 /* PhoneNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PhoneNative.h; sourceTree = ""; }; - 69ED779509541DFE7A36679D /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; 69ED77A829DD1436A5A2CA1B /* FastEasyMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastEasyMapping.h; sourceTree = ""; }; 69ED7810DD72B240882E07DF /* Address.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Address.json; sourceTree = ""; }; 69ED782333EB910A1F420719 /* SeaplaneNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SeaplaneNative.m; sourceTree = ""; }; 69ED78A3F1B154B04AA09ABB /* Male.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Male.json; sourceTree = ""; }; - 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; 69ED78FBF03886650959C5AE /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = ""; }; 69ED793ABFE3F8A13E1E3D30 /* PersonWithDifferentNaming.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithDifferentNaming.json; sourceTree = ""; }; 69ED794EEC7B9F51E50AC8FA /* AddressNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddressNative.h; sourceTree = ""; }; @@ -486,8 +486,6 @@ 69ED7C716C176C89DA2C9636 /* Object */, 69ED7C6CCD04878CED1E5BAE /* Attribute */, 69ED74A3F93755AF6DBD3662 /* Relationship */, - 69ED78C2DFBB1D8408F0D515 /* FEMMapping.m */, - 69ED779509541DFE7A36679D /* FEMMapping.h */, 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */, ); path = Mapping; @@ -556,6 +554,8 @@ children = ( 69ED70753A27735A60785078 /* FEMObjectMapping.h */, 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */, + 1D6A348952AF3C9B329FC208 /* FEMMapping.m */, + 1D6A3500E1995CD83C02D364 /* FEMMapping.h */, ); path = Object; sourceTree = ""; @@ -617,7 +617,7 @@ 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, - 69ED7191763B8C717620B63E /* FEMMapping.h in Headers */, + 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -739,12 +739,12 @@ 69ED756EBF9D955A7B6A580A /* FEMManagedObjectCache.m in Sources */, AD11B5ED1B038E8900B53F5A /* FEMExcludableCollection.m in Sources */, 69ED74D218BD6B3888549434 /* NSObject+FEMKVCExtension.m in Sources */, - 69ED775D5D598E6ECAA40BA2 /* FEMMapping.m in Sources */, AD11B5EC1B038E8700B53F5A /* FEMMergeableCollection.m in Sources */, ADC5B81D194E0F8600F07712 /* FEMAssignmentPolicy.m in Sources */, 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */, + 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index 3747d6a..a632f6e 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -1,7 +1,4 @@ -// -// 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 diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index c8a7444..dccba69 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -1,7 +1,4 @@ -// -// 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" diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 60c3db3..24392b1 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -4,7 +4,6 @@ #import -#import "FEMManagedObjectMapping.h" #import "FEMTypeIntrospection.h" #import "NSArray+FEMPropertyRepresentation.h" #import "FEMAttribute+Extension.h" @@ -12,7 +11,6 @@ #import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" #import "FEMManagedObjectStore.h" -#import "FEMObjectMapping.h" @implementation FEMDeserializer { struct { diff --git a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h index cbb6fa0..ea1b96d 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h @@ -1,7 +1,4 @@ -// -// Created by zen on 12/05/15. -// Copyright (c) 2015 Yalantis. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h index 3bb97ec..45393dd 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h @@ -1,10 +1,4 @@ -// -// FEMManagedObjectMapping.h -// EasyMappingExample -// -// Created by Alejandro Isaza on 2013-03-13. -// Copyright (c) 2013 Alejandro Isaza. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/FEMMapping.h rename to FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h diff --git a/FastEasyMapping/Source/Core/Mapping/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/FEMMapping.m rename to FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h index 7b77948..df6a463 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h @@ -1,7 +1,4 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMObjectStore.h" diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 9be8cd2..665df0f 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -1,7 +1,4 @@ -// -// Created by zen on 19/10/14. -// Copyright (c) 2014 Yalantis. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMManagedObjectStore.h" diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 93ed00f..aab6a63 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -1,7 +1,4 @@ -// -// Created by zen on 12/05/15. -// Copyright (c) 2015 Yalantis. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m index 41b3036..0c80084 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -1,7 +1,4 @@ -// -// Created by zen on 12/05/15. -// Copyright (c) 2015 Yalantis. All rights reserved. -// +// For License please refer to LICENSE file in the root of FastEasyMapping project #import "FEMObjectStore.h" #import "FEMMapping.h" From 45c0e5a7d53d75f549a597335be0555dc73f357c Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 18:18:25 +0300 Subject: [PATCH 42/95] Add delegate callbacks --- .../Core/Deserializer/FEMDeserializer.h | 2 +- .../Core/Deserializer/FEMDeserializer.m | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 3d741ad..a70a02f 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -13,7 +13,7 @@ - (void)deserializer:(FEMDeserializer *)deserializer didMapObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; - (void)deserializer:(FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; -- (void)deserializer:(FEMDeserializer *)deserializer didMapCollection:(NSArray *)collection fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(FEMDeserializer *)deserializer didMapCollection:(NSArray *)collection fromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; @end diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 24392b1..d608a65 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -87,6 +87,10 @@ - (id)_fillObject:(id)object fromRepresentation:(NSDictionary *)representation m } - (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + if (_delegateFlags.willMapObject) { + [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; + } + id object = [self.store registeredObjectForRepresentation:representation mapping:mapping]; if (!object) { object = [self.store newObjectForMapping:mapping]; @@ -98,10 +102,18 @@ - (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMappi [self.store registerObject:object forMapping:mapping]; } + if (_delegateFlags.didMapObject) { + [self.delegate deserializer:self didMapObject:object fromRepresentation:representation mapping:mapping]; + } + return object; } - (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { + if (_delegateFlags.willMapCollection) { + [self.delegate deserializer:self willMapCollectionFromRepresentation:representation mapping:mapping]; + } + NSMutableArray *output = [[NSMutableArray alloc] initWithCapacity:representation.count]; for (id objectRepresentation in representation) { @autoreleasepool { @@ -109,7 +121,12 @@ - (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FE [output addObject:object]; } } - return [output copy]; + + if (_delegateFlags.didMapCollection) { + [self.delegate deserializer:self didMapCollection:output fromRepresentation:representation mapping:mapping]; + } + + return output; } #pragma mark - Public @@ -126,11 +143,19 @@ - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMappin } - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { + if (_delegateFlags.willMapObject) { + [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; + } + [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); [self _fillObject:object fromRepresentation:root mapping:mapping]; }]; + if (_delegateFlags.didMapObject) { + [self.delegate deserializer:self didMapObject:object fromRepresentation:representation mapping:mapping]; + } + return object; } From c655404f5153cc3e9ec1e0a7aba3449b0e19abfd Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 18:32:42 +0300 Subject: [PATCH 43/95] Minor headers rearrangement --- FastEasyMapping.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 532b1e7..0daf221 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -78,7 +78,7 @@ 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */; }; 69ED7D115200A0D4F52DBBCA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69ED730BF972DF74DC2BA5B3 /* InfoPlist.strings */; }; 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED772E50A1A831B78D48B3 /* FEMDeserializer.m */; }; - 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7DE30D50997F9408F36E /* FEMManagedObjectCache.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; AD11B5EC1B038E8700B53F5A /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; AD11B5ED1B038E8900B53F5A /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; @@ -608,12 +608,12 @@ 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */, AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, + 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, - 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, From face55756a3ce36a528185aeef0a3ad268b6437a Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 13 May 2015 19:07:46 +0300 Subject: [PATCH 44/95] Temporary remove "deprecated" attribute --- .../Source/Core/Deserializer/FEMDeserializer.h | 12 ++++++------ .../Source/Core/Mapping/Object/FEMMapping.h | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index a70a02f..17c7101 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -45,17 +45,17 @@ @interface FEMDeserializer (FEMObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); ++ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); @end @interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); ++ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); + (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h index d439bd5..2d977f5 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h @@ -53,16 +53,16 @@ @interface FEMMapping (FEMObjectMapping_Deprecated) -+ (FEMMapping *)mappingForClass:(Class)objectClass configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); -+ (FEMMapping *)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); ++ (FEMMapping *)mappingForClass:(Class)objectClass configuration:(void (^)(FEMMapping *mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); ++ (FEMMapping *)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end @interface FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName;// __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMMapping *sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (FEMMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end From f4c168343838f60b6f990b2e3dee28514f954aa7 Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 13:25:19 +0300 Subject: [PATCH 45/95] Add stores to header --- FastEasyMapping/Source/FastEasyMapping.h | 3 +++ Podfile.lock | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index 4842f8b..cd5ba8d 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -7,6 +7,9 @@ #import "FEMAttribute.h" #import "FEMRelationship.h" +#import "FEMObjectStore.h" +#import "FEMManagedObjectStore.h" + #import "FEMMapping.h" #import "FEMObjectMapping.h" #import "FEMManagedObjectMapping.h" diff --git a/Podfile.lock b/Podfile.lock index 03754de..3a34fa4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -26,4 +26,4 @@ SPEC CHECKSUMS: MagicalRecord: f8a56bb87ab6552f20c4bb8681a1958a197ea3cd Mantle: 3fbcca07bdfe76c54a08c241689a60d34d08e783 -COCOAPODS: 0.36.4 +COCOAPODS: 0.37.1 From 4f48e0f2021d74aeaa433e1acac2a4ebdd9aac59 Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 16:02:43 +0300 Subject: [PATCH 46/95] Add inspection of mapping --- FastEasyMapping.xcodeproj/project.pbxproj | 8 ++ .../Source/Core/Cache/FEMManagedObjectCache.m | 17 ++-- .../Source/Utility/FEMMappingUtility.h | 11 +++ .../Source/Utility/FEMMappingUtility.m | 82 +++++++++++++++++++ 4 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 FastEasyMapping/Source/Utility/FEMMappingUtility.h create mode 100644 FastEasyMapping/Source/Utility/FEMMappingUtility.m diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 0daf221..92e29d6 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A348952AF3C9B329FC208 /* FEMMapping.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -23,6 +24,7 @@ 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; + 1D6A3FFE3771AC234D28EA4D /* FEMMappingUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3A4F887B37995524457E /* FEMMappingUtility.m */; }; 2C11898E18D07356005D8D91 /* FEMManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2C375F1318CCD3FB00FCB8EA /* EasyMappingCoreDataExample.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */; }; 2C375F1418CCD3FB00FCB8EA /* Car.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED767EE6E89A487714CDF8 /* Car.m */; }; @@ -134,12 +136,14 @@ 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; 1D6A348952AF3C9B329FC208 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; + 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMappingUtility.h; sourceTree = ""; }; 1D6A3500E1995CD83C02D364 /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipAssignmentContext.h; sourceTree = ""; }; 1D6A3936AEC2DF329B7D5C0C /* FEMCacheSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMCacheSpec.m; sourceTree = ""; }; 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithNullRelationships.json; sourceTree = ""; }; + 1D6A3A4F887B37995524457E /* FEMMappingUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMappingUtility.m; sourceTree = ""; }; 1D6A3ACBBC8E66609F169E94 /* Person_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_2.json; sourceTree = ""; }; 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMExcludableCollection.h; sourceTree = ""; }; 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; @@ -351,6 +355,8 @@ 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */, 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */, 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */, + 1D6A3A4F887B37995524457E /* FEMMappingUtility.m */, + 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */, ); path = Utility; sourceTree = ""; @@ -618,6 +624,7 @@ 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */, + 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -745,6 +752,7 @@ 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */, 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */, + 1D6A3FFE3771AC234D28EA4D /* FEMMappingUtility.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index b7ed650..7d5ae60 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -7,6 +7,9 @@ #import "FEMMapping.h" #import "FEMAttribute+Extension.h" #import "FEMRepresentationUtility.h" +#import "FEMRelationship.h" +#import "FEMMappingUtility.h" +#import "KWExample.h" @implementation FEMManagedObjectCache { NSManagedObjectContext *_context; @@ -30,7 +33,10 @@ - (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)represe _lookupKeysMap = [NSMutableDictionary new]; _lookupObjectsMap = [NSMutableDictionary new]; - [self prepareMappingLookupStructure:mapping]; + for (NSString *name in FEMMappingCollectUsedEntityNames(mapping)) { + _lookupKeysMap[name] = [[NSMutableSet alloc] init]; + } + [self inspectExternalRepresentation:representation mapping:mapping]; } @@ -87,15 +93,6 @@ - (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMMapping * } } -- (void)prepareMappingLookupStructure:(FEMMapping *)mapping { - NSMutableSet *entityNames = [NSMutableSet new]; - [self collectEntityNames:entityNames mapping:mapping]; - - for (NSString *entityName in entityNames) { - _lookupKeysMap[entityName] = [NSMutableSet new]; - } -} - - (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMMapping *)mapping { NSSet *lookupValues = _lookupKeysMap[mapping.entityName]; if (lookupValues.count == 0) return [NSMutableDictionary dictionary]; diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.h b/FastEasyMapping/Source/Utility/FEMMappingUtility.h new file mode 100644 index 0000000..5bdf76c --- /dev/null +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.h @@ -0,0 +1,11 @@ +// +// Created by zen on 14/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +@import Foundation; + +@class FEMMapping; + +FOUNDATION_EXTERN void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)); +FOUNDATION_EXTERN NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m new file mode 100644 index 0000000..7eb8f4d --- /dev/null +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -0,0 +1,82 @@ +// +// Created by zen on 14/05/15. +// Copyright (c) 2015 Yalantis. All rights reserved. +// + +#import "FEMMappingUtility.h" +#import "FEMMapping.h" +#import "FEMRepresentationUtility.h" + +void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { + apply(mapping); + + for (FEMRelationship *relationship in mapping.relationships) { + FEMMappingApply(relationship.objectMapping, apply); + } +} + +NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping) { + NSMutableSet *output = [[NSMutableSet alloc] init]; + FEMMappingApply(mapping, ^(FEMMapping *object) { + NSCParameterAssert(mapping.entityName != nil); + + [output addObject:mapping.entityName]; + }); + + return output; +} + +@implementation FEMMappingUtility + +#pragma mark - Primary Keys + +- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMMapping *)mapping { + if (mapping.primaryKey) { + FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; + NSParameterAssert(primaryKeyMapping); + + id primaryKeyValue = [primaryKeyMapping mappedValueFromRepresentation:objectRepresentation]; + if (primaryKeyValue && primaryKeyValue != NSNull.null) { + [_lookupKeysMap[mapping.entityName] addObject:primaryKeyValue]; + } + } + + for (FEMRelationship *relationshipMapping in mapping.relationships) { + id relationshipRepresentation = FEMRepresentationRootForKeyPath(objectRepresentation, relationshipMapping.keyPath); + if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { + [self inspectRepresentation:relationshipRepresentation mapping:relationshipMapping.objectMapping]; + } + } +} + +- (void)inspectRepresentation:(id)representation mapping:(FEMMapping *)mapping { + if ([representation isKindOfClass:NSArray.class]) { + for (id objectRepresentation in representation) { + [self inspectObjectRepresentation:objectRepresentation mapping:mapping]; + } + } else if ([representation isKindOfClass:NSDictionary.class]) { + [self inspectObjectRepresentation:representation mapping:mapping]; + } else { + NSAssert( + NO, + @"Expected container classes: NSArray, NSDictionary. Got:%@", + NSStringFromClass([representation class]) + ); + } +} + ++ (NSDictionary *)inspectPrimaryKeysFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { + NSSet *entityNames = FEMMappingCollectUsedEntityNames(mapping); + NSMutableDictionary *output = [[NSMutableDictionary alloc] initWithCapacity:entityNames.count]; + + for (NSString *name in entityNames) { + output[name] = [[NSMutableSet alloc] init]; + } + + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + [self inspectRepresentation:representation mapping:mapping]; + + return output; +} + +@end \ No newline at end of file From 083f5bb98dca203e03f1c883fc441aa1434ba65e Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 17:44:36 +0300 Subject: [PATCH 47/95] Move PK inspection to a separate file --- .../Source/Core/Cache/FEMManagedObjectCache.m | 58 +------------------ .../Source/Utility/FEMMappingUtility.m | 58 +------------------ .../Source/Utility/FEMRepresentationUtility.h | 6 +- .../Source/Utility/FEMRepresentationUtility.m | 55 ++++++++++++++++++ 4 files changed, 63 insertions(+), 114 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index 7d5ae60..427fef8 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -14,7 +14,7 @@ @implementation FEMManagedObjectCache { NSManagedObjectContext *_context; - NSMutableDictionary *_lookupKeysMap; + NSDictionary *_lookupKeysMap; NSMutableDictionary *_lookupObjectsMap; } @@ -30,14 +30,8 @@ - (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)represe if (self) { _context = context; - _lookupKeysMap = [NSMutableDictionary new]; + _lookupKeysMap = FEMRepresentationCollectPresentedPrimaryKeys(representation, mapping); _lookupObjectsMap = [NSMutableDictionary new]; - - for (NSString *name in FEMMappingCollectUsedEntityNames(mapping)) { - _lookupKeysMap[name] = [[NSMutableSet alloc] init]; - } - - [self inspectExternalRepresentation:representation mapping:mapping]; } return self; @@ -45,54 +39,6 @@ - (instancetype)initWithMapping:(FEMMapping *)mapping representation:(id)represe #pragma mark - Inspection -- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMMapping *)mapping { - if (mapping.primaryKey) { - FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; - NSParameterAssert(primaryKeyMapping); - - id primaryKeyValue = [primaryKeyMapping mappedValueFromRepresentation:objectRepresentation]; - if (primaryKeyValue && primaryKeyValue != NSNull.null) { - [_lookupKeysMap[mapping.entityName] addObject:primaryKeyValue]; - } - } - - for (FEMRelationship *relationshipMapping in mapping.relationships) { - id relationshipRepresentation = FEMRepresentationRootForKeyPath(objectRepresentation, relationshipMapping.keyPath); - if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { - [self inspectRepresentation:relationshipRepresentation mapping:relationshipMapping.objectMapping]; - } - } -} - -- (void)inspectRepresentation:(id)representation mapping:(FEMMapping *)mapping { - if ([representation isKindOfClass:NSArray.class]) { - for (id objectRepresentation in representation) { - [self inspectObjectRepresentation:objectRepresentation mapping:mapping]; - } - } else if ([representation isKindOfClass:NSDictionary.class]) { - [self inspectObjectRepresentation:representation mapping:mapping]; - } else { - NSAssert( - NO, - @"Expected container classes: NSArray, NSDictionary. Got:%@", - NSStringFromClass([representation class]) - ); - } -} - -- (void)inspectExternalRepresentation:(id)externalRepresentation mapping:(FEMMapping *)mapping { - id representation = FEMRepresentationRootForKeyPath(externalRepresentation, mapping.rootPath); - [self inspectRepresentation:representation mapping:mapping]; -} - -- (void)collectEntityNames:(NSMutableSet *)namesCollection mapping:(FEMMapping *)mapping { - [namesCollection addObject:mapping.entityName]; - - for (FEMRelationship *relationshipMapping in mapping.relationships) { - [self collectEntityNames:namesCollection mapping:relationshipMapping.objectMapping]; - } -} - - (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMMapping *)mapping { NSSet *lookupValues = _lookupKeysMap[mapping.entityName]; if (lookupValues.count == 0) return [NSMutableDictionary dictionary]; diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m index 7eb8f4d..c4ee991 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.m +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -5,7 +5,6 @@ #import "FEMMappingUtility.h" #import "FEMMapping.h" -#import "FEMRepresentationUtility.h" void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { apply(mapping); @@ -24,59 +23,4 @@ void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { }); return output; -} - -@implementation FEMMappingUtility - -#pragma mark - Primary Keys - -- (void)inspectObjectRepresentation:(id)objectRepresentation mapping:(FEMMapping *)mapping { - if (mapping.primaryKey) { - FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; - NSParameterAssert(primaryKeyMapping); - - id primaryKeyValue = [primaryKeyMapping mappedValueFromRepresentation:objectRepresentation]; - if (primaryKeyValue && primaryKeyValue != NSNull.null) { - [_lookupKeysMap[mapping.entityName] addObject:primaryKeyValue]; - } - } - - for (FEMRelationship *relationshipMapping in mapping.relationships) { - id relationshipRepresentation = FEMRepresentationRootForKeyPath(objectRepresentation, relationshipMapping.keyPath); - if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { - [self inspectRepresentation:relationshipRepresentation mapping:relationshipMapping.objectMapping]; - } - } -} - -- (void)inspectRepresentation:(id)representation mapping:(FEMMapping *)mapping { - if ([representation isKindOfClass:NSArray.class]) { - for (id objectRepresentation in representation) { - [self inspectObjectRepresentation:objectRepresentation mapping:mapping]; - } - } else if ([representation isKindOfClass:NSDictionary.class]) { - [self inspectObjectRepresentation:representation mapping:mapping]; - } else { - NSAssert( - NO, - @"Expected container classes: NSArray, NSDictionary. Got:%@", - NSStringFromClass([representation class]) - ); - } -} - -+ (NSDictionary *)inspectPrimaryKeysFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { - NSSet *entityNames = FEMMappingCollectUsedEntityNames(mapping); - NSMutableDictionary *output = [[NSMutableDictionary alloc] initWithCapacity:entityNames.count]; - - for (NSString *name in entityNames) { - output[name] = [[NSMutableSet alloc] init]; - } - - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - [self inspectRepresentation:representation mapping:mapping]; - - return output; -} - -@end \ No newline at end of file +} \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h index d8942fb..7586143 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h @@ -5,4 +5,8 @@ #import -FOUNDATION_EXTERN id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath); \ No newline at end of file +FOUNDATION_EXTERN id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath); + +@class FEMMapping; + +FOUNDATION_EXTERN NSDictionary *FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index f53e22c..c659f2d 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -4,6 +4,9 @@ // #import "FEMRepresentationUtility.h" +#import "FEMMapping.h" +#import "FEMMappingUtility.h" +#import "FEMAttribute+Extension.h" id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { if (keyPath.length > 0) { @@ -11,4 +14,56 @@ id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { } return representation; +} + +void _FEMRepresentationCollectPresentedPrimaryKeys(id, FEMMapping *, NSDictionary *); + +void _FEMRepresentationCollectObjectPrimaryKeys(NSDictionary *object, FEMMapping *mapping, NSDictionary *container) { + if (mapping.primaryKey) { + FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; + id primaryKeyValue = [primaryKeyMapping mappedValueFromRepresentation:object]; + if (primaryKeyValue && primaryKeyValue != NSNull.null) { + NSMutableSet *set = container[mapping.entityName]; + [set addObject:primaryKeyValue]; + } + } + + for (FEMRelationship *relationship in mapping.relationships) { + id relationshipRepresentation = FEMRepresentationRootForKeyPath(object, relationship.keyPath); + if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { + _FEMRepresentationCollectPresentedPrimaryKeys(relationshipRepresentation, relationship.objectMapping, container); + } + } +} + +void _FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping, NSDictionary *container) { + if ([representation isKindOfClass:NSArray.class]) { + for (id object in (id)representation) { + _FEMRepresentationCollectObjectPrimaryKeys(object, mapping, container); + } + } else if ([representation isKindOfClass:NSDictionary.class]) { + _FEMRepresentationCollectObjectPrimaryKeys(representation, mapping, container); + } else { + NSCAssert( + NO, + @"Expected container classes: NSArray, NSDictionary. Got:%@", + NSStringFromClass([representation class]) + ); + } +}; + +NSDictionary *FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping) { + FEMMappingApply(mapping, ^(FEMMapping *object) { + NSCParameterAssert(object.entityName != nil); + }); + + NSMutableDictionary *output = [[NSMutableDictionary alloc] init]; + for (NSString *name in FEMMappingCollectUsedEntityNames(mapping)) { + output[name] = [[NSMutableSet alloc] init]; + } + + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + _FEMRepresentationCollectPresentedPrimaryKeys(root, mapping, output); + + return output; } \ No newline at end of file From 45ce343d0612d5fd912725c1bf345942f070de32 Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 17:53:42 +0300 Subject: [PATCH 48/95] Fixed typo --- FastEasyMapping/Source/Utility/FEMMappingUtility.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m index c4ee991..4a2a803 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.m +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -17,9 +17,9 @@ void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping) { NSMutableSet *output = [[NSMutableSet alloc] init]; FEMMappingApply(mapping, ^(FEMMapping *object) { - NSCParameterAssert(mapping.entityName != nil); + NSCParameterAssert(object.entityName != nil); - [output addObject:mapping.entityName]; + [output addObject:object.entityName]; }); return output; From 1d7881dba72440bcdedd6c00594bde1eaa276d99 Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 20:14:29 +0300 Subject: [PATCH 49/95] Fix public headers --- FastEasyMapping.xcodeproj/project.pbxproj | 8 ++++---- FastEasyMapping/Source/FastEasyMapping.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 92e29d6..d4afdf7 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -11,9 +11,9 @@ 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A348952AF3C9B329FC208 /* FEMMapping.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; settings = {ATTRIBUTES = (Private, ); }; }; - 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */; }; + 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; - 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; @@ -618,13 +618,13 @@ 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, ADC5B81F194E0FB700F07712 /* FEMAssignmentPolicy.h in Headers */, + 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, + 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */, 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, - 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */, 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */, - 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/FastEasyMapping.h b/FastEasyMapping/Source/FastEasyMapping.h index cd5ba8d..2d78c25 100644 --- a/FastEasyMapping/Source/FastEasyMapping.h +++ b/FastEasyMapping/Source/FastEasyMapping.h @@ -23,5 +23,7 @@ #import "FEMAssignmentPolicy.h" #import "FEMTypes.h" +#import "FEMRepresentationUtility.h" +#import "FEMMappingUtility.h" #endif /* _FASTEASYMAPPING_ */ \ No newline at end of file From a13ee24e19773163a27edaa247cca633708fe005 Mon Sep 17 00:00:00 2001 From: zen Date: Thu, 14 May 2015 20:25:48 +0300 Subject: [PATCH 50/95] Remove Kiwi header from lib --- FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m | 1 - 1 file changed, 1 deletion(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index 427fef8..90982a0 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -9,7 +9,6 @@ #import "FEMRepresentationUtility.h" #import "FEMRelationship.h" #import "FEMMappingUtility.h" -#import "KWExample.h" @implementation FEMManagedObjectCache { NSManagedObjectContext *_context; From 0d0bd2699605e25a8509e432e564abde3dbdb01a Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 22 Jun 2015 18:06:52 +0300 Subject: [PATCH 51/95] Add ability to treat NSNumber & NSString as a valid object container --- FastEasyMapping/Source/Utility/FEMRepresentationUtility.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index c659f2d..a8446ce 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -41,17 +41,16 @@ void _FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping for (id object in (id)representation) { _FEMRepresentationCollectObjectPrimaryKeys(object, mapping, container); } - } else if ([representation isKindOfClass:NSDictionary.class]) { + } else if ([representation isKindOfClass:NSDictionary.class] || [representation isKindOfClass:[NSNumber class]] || [representation isKindOfClass:[NSString class]]) { _FEMRepresentationCollectObjectPrimaryKeys(representation, mapping, container); } else { NSCAssert( NO, - @"Expected container classes: NSArray, NSDictionary. Got:%@", + @"Expected container classes: NSArray, NSDictionary, NSNumber or NSString. Got:%@", NSStringFromClass([representation class]) ); } }; - NSDictionary *FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping) { FEMMappingApply(mapping, ^(FEMMapping *object) { NSCParameterAssert(object.entityName != nil); From 8240fbe195a94b9566dcfbd99f8d15571398324f Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 22 Jun 2015 18:07:44 +0300 Subject: [PATCH 52/95] Fix delegate methods to reflects NSNumber, NSString & NSDictionary as a valid containers --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 17c7101..0154f4c 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -9,8 +9,8 @@ @protocol FEMDeserializerDelegate @optional -- (void)deserializer:(FEMDeserializer *)deserializer willMapObjectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; -- (void)deserializer:(FEMDeserializer *)deserializer didMapObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(FEMDeserializer *)deserializer willMapObjectFromRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(FEMDeserializer *)deserializer didMapObject:(id)object fromRepresentation:(id)representation mapping:(FEMMapping *)mapping; - (void)deserializer:(FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; - (void)deserializer:(FEMDeserializer *)deserializer didMapCollection:(NSArray *)collection fromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; From 978ff542e1dd8f437a121c65d4afedd7a3110681 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 22 Jun 2015 18:08:12 +0300 Subject: [PATCH 53/95] Fix linker warning --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 0154f4c..c807949 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -54,7 +54,7 @@ @interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); + + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); + (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation From 1d6d79cd600706bca9d4ec6bd3bc0ad4d2ae3f39 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 1 Jul 2015 18:14:56 +0300 Subject: [PATCH 54/95] Add nullability attributes --- .../Assignment Policy/FEMAssignmentPolicy.h | 12 ++-- .../Assignment Policy/FEMAssignmentPolicy.m | 2 +- .../FEMRelationshipAssignmentContext.h | 16 +++--- .../Core/Deserializer/FEMDeserializer.h | 45 +++++++-------- .../Core/Mapping/Attribute/FEMAttribute.h | 22 ++++---- .../Core/Mapping/Attribute/FEMAttribute.m | 4 ++ .../Source/Core/Mapping/FEMProperty.h | 4 +- .../Source/Core/Mapping/Object/FEMMapping.h | 56 +++++++++---------- .../Mapping/Relationship/FEMRelationship.h | 34 +++++------ .../Source/Core/Serializer/FEMSerializer.h | 4 +- .../Source/Core/Store/FEMManagedObjectStore.h | 4 +- .../Source/Core/Store/FEMObjectStore.h | 14 ++--- 12 files changed, 110 insertions(+), 107 deletions(-) diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h index a632f6e..d1a573b 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.h @@ -4,12 +4,12 @@ @class FEMRelationshipAssignmentContext; -typedef id (^FEMAssignmentPolicy)(FEMRelationshipAssignmentContext *context); +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; \ No newline at end of file +OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyObjectReplace; +OBJC_EXTERN __nonnull FEMAssignmentPolicy FEMAssignmentPolicyCollectionReplace; \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m index dccba69..48ba891 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMAssignmentPolicy.m @@ -6,7 +6,7 @@ #import "FEMExcludableCollection.h" #import "FEMMergeableCollection.h" -FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id(FEMRelationshipAssignmentContext *context) { +FEMAssignmentPolicy FEMAssignmentPolicyAssign = ^id(FEMRelationshipAssignmentContext * context) { return context.targetRelationshipValue; }; diff --git a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h index b82914b..e0d1afc 100644 --- a/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h +++ b/FastEasyMapping/Source/Core/Assignment Policy/FEMRelationshipAssignmentContext.h @@ -10,22 +10,22 @@ @protocol FEMRelationshipAssignmentContextDelegate @required -- (void)assignmentContext:(FEMRelationshipAssignmentContext *)context deletedObject:(id)object; +- (void)assignmentContext:(nonnull FEMRelationshipAssignmentContext *)context deletedObject:(nonnull id)object; @end @interface FEMRelationshipAssignmentContext: NSObject -@property (nonatomic, unsafe_unretained, readonly) FEMObjectStore *store; -- (instancetype)initWithStore:(FEMObjectStore *)store; +@property (nonatomic, unsafe_unretained, readonly, nonnull) FEMObjectStore *store; +- (nonnull instancetype)initWithStore:(nonnull FEMObjectStore *)store; -@property (nonatomic, strong, readonly) id destinationObject; -@property (nonatomic, strong, readonly) FEMRelationship *relationship; +@property (nonatomic, strong, readonly, nonnull) id destinationObject; +@property (nonatomic, strong, readonly, nonnull) FEMRelationship *relationship; -@property (nonatomic, strong, readonly) id sourceRelationshipValue; -@property (nonatomic, strong, readonly) id targetRelationshipValue; +@property (nonatomic, strong, readonly, nullable) id sourceRelationshipValue; +@property (nonatomic, strong, readonly, nullable) id targetRelationshipValue; -- (void)deleteRelationshipObject:(id)object; +- (void)deleteRelationshipObject:(nonnull id)object; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index c807949..b7111e6 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -9,57 +9,52 @@ @protocol FEMDeserializerDelegate @optional -- (void)deserializer:(FEMDeserializer *)deserializer willMapObjectFromRepresentation:(id)representation mapping:(FEMMapping *)mapping; -- (void)deserializer:(FEMDeserializer *)deserializer didMapObject:(id)object fromRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer willMapObjectFromRepresentation:(nonnull id)representation mapping:(nonnull FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer didMapObject:(nonnull id)object fromRepresentation:(nonnull id)representation mapping:(nonnull FEMMapping *)mapping; -- (void)deserializer:(FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; -- (void)deserializer:(FEMDeserializer *)deserializer didMapCollection:(NSArray *)collection fromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer didMapCollection:(nonnull NSArray *)collection fromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; @end @interface FEMDeserializer : NSObject -@property (nonatomic, strong, readonly) FEMObjectStore *store; -- (id)initWithStore:(FEMObjectStore *)store; +@property (nonatomic, strong, readonly, nonnull) FEMObjectStore *store; +- (nonnull instancetype)initWithStore:(nonnull FEMObjectStore *)store; -@property (nonatomic, unsafe_unretained) id delegate; +@property (nonatomic, unsafe_unretained, nullable) id delegate; -- (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; -- (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; -- (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; +- (nonnull id)objectFromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping; +- (nonnull id)fillObject:(nonnull id)object fromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping; +- (nonnull NSArray *)collectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; @end @interface FEMDeserializer (Extension) -+ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; -+ (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; ++ (nonnull id)objectFromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; ++ (nonnull id)objectFromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping; -+ (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping; - -+ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; -+ (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping; ++ (nonnull NSArray *)collectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; ++ (nonnull NSArray *)collectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; @end @interface FEMDeserializer (FEMObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); ++ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); ++ (nonnull id)fillObject:(nonnull id)object fromExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); @end @interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) -+ (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); ++ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); -+ (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); ++ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); -+ (NSArray *)synchronizeCollectionExternalRepresentation:(NSArray *)externalRepresentation - usingMapping:(FEMMapping *)mapping - predicate:(NSPredicate *)predicate - context:(NSManagedObjectContext *)context __attribute__((unavailable)); ++ (nonnull NSArray *)synchronizeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping predicate:(nonnull NSPredicate *)predicate context:(nonnull NSManagedObjectContext *)context __attribute__((unavailable)); @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h index 1185879..b1a3bd7 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h @@ -7,11 +7,11 @@ @interface FEMAttribute : NSObject -- (id)mapValue:(id)value; -- (id)reverseMapValue:(id)value; +- (nullable id)mapValue:(nullable id)value; +- (nullable id)reverseMapValue:(nullable id)value; -- (id)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath map:(FEMMapBlock)map reverseMap:(FEMMapBlock)reverseMap; +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath map:(nullable FEMMapBlock)map reverseMap:(nullable FEMMapBlock)reverseMap; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property toKeyPath:(nullable NSString *)keyPath map:(nullable FEMMapBlock)map reverseMap:(nullable FEMMapBlock)reverseMap; @end @@ -20,32 +20,34 @@ /** * same as +[FEMAttribute mappingOfProperty:property toKeyPath:property]; */ -+ (instancetype)mappingOfProperty:(NSString *)property; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property; /** * same as +[FEMAttribute mappingOfProperty:property toKeyPath:nil map:NULL]; */ -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property toKeyPath:(nonnull NSString *)keyPath; /** * same as +[FEMAttribute mappingOfProperty:property toKeyPath:nil map:map]; */ -+ (instancetype)mappingOfProperty:(NSString *)property map:(FEMMapBlock)map; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property map:(nonnull FEMMapBlock)map; + ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property reverseMap:(nonnull FEMMapBlock)reverseMap; /** * same as +[FEMAttribute mappingOfProperty:property toKeyPath:nil map:NULL reverseMap:NULL]; */ -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath map:(FEMMapBlock)map; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property toKeyPath:(nonnull NSString *)keyPath map:(nonnull FEMMapBlock)map; /** * create mapping object, based on NSDateFormatter. * NSDateFormatter instance uses en_US_POSIX locale and UTC Timezone */ -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath dateFormat:(NSString *)dateFormat; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property toKeyPath:(nullable NSString *)keyPath dateFormat:(nonnull NSString *)dateFormat; /** * property represented by NSURL, value at keyPath - NSString */ -+ (instancetype)mappingOfURLProperty:(NSString *)property toKeyPath:(NSString *)keyPath; ++ (nonnull instancetype)mappingOfURLProperty:(nonnull NSString *)property toKeyPath:(nullable NSString *)keyPath; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m index 689a593..c6f8c22 100644 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m +++ b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m @@ -77,6 +77,10 @@ + (instancetype)mappingOfProperty:(NSString *)property map:(FEMMapBlock)map { return [self mappingOfProperty:property toKeyPath:nil map:map reverseMap:NULL]; } ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property reverseMap:(nonnull FEMMapBlock)reverseMap { + return [self mappingOfProperty:property toKeyPath:nil map:NULL reverseMap:reverseMap]; +} + + (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath dateFormat:(NSString *)dateFormat { NSDateFormatter *formatter = [NSDateFormatter new]; [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; diff --git a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h index ea1b96d..5d76f9e 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMProperty.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMProperty.h @@ -4,7 +4,7 @@ @protocol FEMProperty -@property (nonatomic, copy) NSString *property; -@property (nonatomic, copy) NSString *keyPath; +@property (nonatomic, copy, nonnull) NSString *property; +@property (nonatomic, copy, nullable) NSString *keyPath; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h index 2d977f5..ecf0a20 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h @@ -11,58 +11,58 @@ NSMutableDictionary *_relationshipMap; } -- (instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); -+ (instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); -- (id)initWithRootPath:(NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); +- (nonnull instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); ++ (nonnull instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); +- (nonnull instancetype)initWithRootPath:(nullable NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); -- (instancetype)initWithObjectClass:(Class)objectClass NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithObjectClass:(Class)objectClass rootPath:(NSString *)rootPath; +- (nonnull instancetype)initWithObjectClass:(nonnull Class)objectClass NS_DESIGNATED_INITIALIZER; +- (nonnull instancetype)initWithObjectClass:(nonnull Class)objectClass rootPath:(nullable NSString *)rootPath; -- (instancetype)initWithEntityName:(NSString *)entityName NS_DESIGNATED_INITIALIZER; -- (id)initWithEntityName:(NSString *)entityName rootPath:(NSString *)rootPath; +- (nonnull instancetype)initWithEntityName:(nonnull NSString *)entityName NS_DESIGNATED_INITIALIZER; +- (nonnull instancetype)initWithEntityName:(nonnull NSString *)entityName rootPath:(nullable NSString *)rootPath; -@property (nonatomic, readonly) Class objectClass; -@property (nonatomic, copy, readonly) NSString *entityName; +@property (nonatomic, readonly, nullable) Class objectClass; +@property (nonatomic, copy, readonly, nullable) NSString *entityName; -@property (nonatomic, copy) NSString *rootPath; +@property (nonatomic, copy, nullable) NSString *rootPath; -@property (nonatomic, copy) NSString *primaryKey; -@property (nonatomic, strong, readonly) FEMAttribute *primaryKeyAttribute; +@property (nonatomic, copy, nullable) NSString *primaryKey; +@property (nonatomic, strong, readonly, nullable) FEMAttribute *primaryKeyAttribute; -@property (nonatomic, strong, readonly) NSArray *attributes; -- (void)addAttribute:(FEMAttribute *)attribute; -- (FEMAttribute *)attributeForProperty:(NSString *)property; +@property (nonatomic, strong, readonly, nonnull) NSArray *attributes; +- (void)addAttribute:(nonnull FEMAttribute *)attribute; +- (nullable FEMAttribute *)attributeForProperty:(nonnull NSString *)property; -@property (nonatomic, strong, readonly) NSArray *relationships; -- (void)addRelationship:(FEMRelationship *)relationship; -- (FEMRelationship *)relationshipForProperty:(NSString *)property; +@property (nonatomic, strong, readonly, nonnull) NSArray *relationships; +- (void)addRelationship:(nonnull FEMRelationship *)relationship; +- (nullable FEMRelationship *)relationshipForProperty:(nonnull NSString *)property; @end @interface FEMMapping (Shortcut) -- (void)addAttributesFromArray:(NSArray *)attributes; -- (void)addAttributesFromDictionary:(NSDictionary *)attributesToKeyPath; -- (void)addAttributeWithProperty:(NSString *)property keyPath:(NSString *)keyPath; +- (void)addAttributesFromArray:(nonnull NSArray *)attributes; +- (void)addAttributesFromDictionary:(nonnull NSDictionary *)attributesToKeyPath; +- (void)addAttributeWithProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath; -- (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; -- (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath; +- (void)addRelationshipMapping:(nonnull FEMMapping *)mapping forProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath; +- (void)addToManyRelationshipMapping:(nonnull FEMMapping *)mapping forProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath; @end @interface FEMMapping (FEMObjectMapping_Deprecated) -+ (FEMMapping *)mappingForClass:(Class)objectClass configuration:(void (^)(FEMMapping *mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); -+ (FEMMapping *)mappingForClass:(Class)objectClass rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); ++ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); ++ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass rootPath:(nullable NSString *)rootPath configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end @interface FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName;// __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName configuration:(void (^)(FEMMapping *sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (FEMMapping *)mappingForEntityName:(NSString *)entityName rootPath:(NSString *)rootPath configuration:(void (^)(FEMMapping *sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName;// __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName rootPath:(nullable NSString *)rootPath configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h index 90db382..da3697d 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h @@ -9,30 +9,32 @@ @interface FEMRelationship : NSObject -@property (nonatomic, copy) FEMAssignmentPolicy assignmentPolicy; +@property (nonatomic, copy, nonnull) FEMAssignmentPolicy assignmentPolicy; -@property (nonatomic, strong) FEMMapping *objectMapping; +@property (nonatomic) BOOL weak; +@property (nonatomic, strong, nonnull) FEMMapping *objectMapping; @property (nonatomic, getter=isToMany) BOOL toMany; -- (void)setObjectMapping:(FEMMapping *)objectMapping forKeyPath:(NSString *)keyPath; +- (void)setObjectMapping:(nonnull FEMMapping *)objectMapping forKeyPath:(nullable NSString *)keyPath; -- (instancetype)initWithProperty:(NSString *)property - keyPath:(NSString *)keyPath - assignmentPolicy:(FEMAssignmentPolicy)policy - objectMapping:(FEMMapping *)objectMapping; +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property + keyPath:(nullable NSString *)keyPath + assignmentPolicy:(nullable FEMAssignmentPolicy)policy + objectMapping:(nullable FEMMapping *)objectMapping NS_DESIGNATED_INITIALIZER; -+ (instancetype)mappingOfProperty:(NSString *)property - configuration:(void (^)(FEMRelationship *mapping))configuration; -+ (instancetype)mappingOfProperty:(NSString *)property - toKeyPath:(NSString *)keyPath - configuration:(void (^)(FEMRelationship *mapping))configuration; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property + configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration; + ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property + toKeyPath:(nullable NSString *)keyPath + configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration; /** * same as + [FEMRelationship mappingOfProperty:property toKeyPath:nil objectMapping:objectMapping]; */ -+ (instancetype)mappingOfProperty:(NSString *)property objectMapping:(FEMMapping *)objectMapping; -+ (instancetype)mappingOfProperty:(NSString *)property - toKeyPath:(NSString *)keyPath - objectMapping:(FEMMapping *)objectMapping; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property objectMapping:(nonnull FEMMapping *)objectMapping; ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property + toKeyPath:(nullable NSString *)keyPath + objectMapping:(nonnull FEMMapping *)objectMapping; @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.h b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.h index abff8b7..d28648e 100644 --- a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.h +++ b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.h @@ -6,7 +6,7 @@ @interface FEMSerializer : NSObject -+ (NSDictionary *)serializeObject:(id)object usingMapping:(FEMMapping *)mapping; -+ (id)serializeCollection:(NSArray *)collection usingMapping:(FEMMapping *)mapping; ++ (nonnull NSDictionary *)serializeObject:(nonnull id)object usingMapping:(nonnull FEMMapping *)mapping; ++ (nonnull id)serializeCollection:(nonnull NSArray *)collection usingMapping:(nonnull FEMMapping *)mapping; @end diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h index df6a463..dbaf021 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.h @@ -6,8 +6,8 @@ @interface FEMManagedObjectStore : FEMObjectStore -- (instancetype)initWithContext:(NSManagedObjectContext *)context; -@property (nonatomic, strong, readonly) NSManagedObjectContext *context; +- (nonnull instancetype)initWithContext:(nonnull NSManagedObjectContext *)context NS_DESIGNATED_INITIALIZER; +@property (nonatomic, strong, readonly, nonnull) NSManagedObjectContext *context; @property (nonatomic) BOOL saveContextOnCommit; diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index aab6a63..7df9aec 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -8,15 +8,15 @@ @interface FEMObjectStore : NSObject -- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction; +- (nullable NSError *)performMappingTransaction:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping transaction:(nonnull void (^)(void))transaction; -- (id)newObjectForMapping:(FEMMapping *)mapping; -- (FEMRelationshipAssignmentContext *)newAssignmentContext; +- (nonnull id)newObjectForMapping:(nonnull FEMMapping *)mapping; +- (nonnull FEMRelationshipAssignmentContext *)newAssignmentContext; -- (void)registerObject:(id)object forMapping:(FEMMapping *)mapping; -- (BOOL)canRegisterObject:(id)object forMapping:(FEMMapping *)mapping; +- (void)registerObject:(nonnull id)object forMapping:(nonnull FEMMapping *)mapping; +- (BOOL)canRegisterObject:(nonnull id)object forMapping:(nonnull FEMMapping *)mapping; -- (NSDictionary *)registeredObjectsForMapping:(FEMMapping *)mapping; -- (id)registeredObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping; +- (nonnull NSDictionary *)registeredObjectsForMapping:(nonnull FEMMapping *)mapping; +- (nullable id)registeredObjectForRepresentation:(nonnull id)representation mapping:(nonnull FEMMapping *)mapping; @end \ No newline at end of file From e61bca1e5b178f4b5d7d74818cf5bd258d97cdf5 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 1 Jul 2015 18:47:44 +0300 Subject: [PATCH 55/95] Add weak relationship handling in deserailizer --- .../Core/Deserializer/FEMDeserializer.m | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index d608a65..7e2ed78 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -55,12 +55,16 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * id targetValue = nil; if (relationshipRepresentation != NSNull.null) { if (relationship.isToMany) { - targetValue = [self _collectionFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; + targetValue = [self _collectionFromRepresentation:relationshipRepresentation + mapping:relationship.objectMapping + allocateIfNeeded:!relationship.weak]; objc_property_t property = class_getProperty([object class], [relationship.property UTF8String]); targetValue = [targetValue fem_propertyRepresentation:property]; } else { - targetValue = [self _objectFromRepresentation:relationshipRepresentation mapping:relationship.objectMapping]; + targetValue = [self _objectFromRepresentation:relationshipRepresentation + mapping:relationship.objectMapping + allocateIfNeeded:!relationship.weak]; } } @@ -86,15 +90,19 @@ - (id)_fillObject:(id)object fromRepresentation:(NSDictionary *)representation m return object; } -- (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - if (_delegateFlags.willMapObject) { - [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; - } - +- (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping allocateIfNeeded:(BOOL)allocate { id object = [self.store registeredObjectForRepresentation:representation mapping:mapping]; - if (!object) { + if (!object && allocate) { object = [self.store newObjectForMapping:mapping]; } + + if (!object) { + return nil; + } + + if (_delegateFlags.willMapObject) { + [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; + } [self _fillObject:object fromRepresentation:representation mapping:mapping]; @@ -109,7 +117,7 @@ - (id)_objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMappi return object; } -- (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { +- (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping allocateIfNeeded:(BOOL)allocate { if (_delegateFlags.willMapCollection) { [self.delegate deserializer:self willMapCollectionFromRepresentation:representation mapping:mapping]; } @@ -117,7 +125,7 @@ - (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FE NSMutableArray *output = [[NSMutableArray alloc] initWithCapacity:representation.count]; for (id objectRepresentation in representation) { @autoreleasepool { - id object = [self _objectFromRepresentation:objectRepresentation mapping:mapping]; + id object = [self _objectFromRepresentation:objectRepresentation mapping:mapping allocateIfNeeded:allocate]; [output addObject:object]; } } @@ -136,7 +144,7 @@ - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMappin __block id object = nil; [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - object = [self _objectFromRepresentation:root mapping:mapping]; + object = [self _objectFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; }]; return object; @@ -163,7 +171,7 @@ - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEM __block NSArray *objects = nil; [self.store performMappingTransaction:representation mapping:mapping transaction:^{ id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - objects = [self _collectionFromRepresentation:root mapping:mapping]; + objects = [self _collectionFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; }]; return objects; From 47ad7aadf23d1f5814694e57d73cfc706f1fb6c6 Mon Sep 17 00:00:00 2001 From: zen Date: Wed, 1 Jul 2015 18:52:23 +0300 Subject: [PATCH 56/95] Linker warning issue --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h | 2 ++ FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m | 6 +----- FastEasyMappingTests/Specs/FEMAttributeMappingSpec.m | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index b7111e6..d28b1e6 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -35,6 +35,8 @@ + (nonnull id)objectFromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; + (nonnull id)objectFromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping; ++ (nonnull id)fillObject:(nonnull id)object fromRepresentation:(nonnull NSDictionary *)representation mapping:(nonnull FEMMapping *)mapping; + + (nonnull NSArray *)collectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; + (nonnull NSArray *)collectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 7e2ed78..a622fbc 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -225,10 +225,6 @@ + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresenta return [self objectFromRepresentation:externalRepresentation mapping:mapping context:context]; } -+ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { - return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; -} - + (NSArray *)deserializeCollectionExternalRepresentation:(NSArray *)externalRepresentation usingMapping:(FEMMapping *)mapping context:(NSManagedObjectContext *)context { return [self collectionFromRepresentation:externalRepresentation mapping:mapping context:context]; } @@ -241,7 +237,7 @@ + (id)deserializeObjectExternalRepresentation:(NSDictionary *)externalRepresenta return [self objectFromRepresentation:externalRepresentation mapping:mapping]; } -+ (id)fillObject:(id)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { ++ (id)fillObject:(NSManagedObject *)object fromExternalRepresentation:(NSDictionary *)externalRepresentation usingMapping:(FEMMapping *)mapping { return [self fillObject:object fromRepresentation:externalRepresentation mapping:mapping]; } diff --git a/FastEasyMappingTests/Specs/FEMAttributeMappingSpec.m b/FastEasyMappingTests/Specs/FEMAttributeMappingSpec.m index 0369f33..7544fac 100644 --- a/FastEasyMappingTests/Specs/FEMAttributeMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMAttributeMappingSpec.m @@ -26,7 +26,7 @@ describe(@"property can't be nil", ^{ [[theBlock(^{ - mapping = [[FEMAttribute alloc] initWithProperty:nil keyPath:nil map:NULL reverseMap:NULL]; + mapping = [[FEMAttribute alloc] initWithProperty:@"" keyPath:nil map:NULL reverseMap:NULL]; }) should] raise]; }); From e58a55fe3816588d2978a92f2141194f8b2e30f4 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 12:11:37 +0300 Subject: [PATCH 57/95] Restore deprecation attributes --- .../Source/Core/Deserializer/FEMDeserializer.h | 12 +++++------- .../Source/Core/Mapping/Object/FEMMapping.h | 11 +++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index d28b1e6..09213d5 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -45,18 +45,16 @@ @interface FEMDeserializer (FEMObjectDeserializer_Deprecated) -+ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); -+ (nonnull id)fillObject:(nonnull id)object fromExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); -+ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); ++ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:] instead"))); ++ (nonnull id)fillObject:(nonnull id)object fromExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer fillObject:fromRepresentation:mapping:] instead"))); ++ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:] instead"))); @end @interface FEMDeserializer (FEMManagedObjectDeserializer_Deprecated) -+ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); - -+ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context; // __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); - ++ (nonnull id)deserializeObjectExternalRepresentation:(nonnull NSDictionary *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer objectFromRepresentation:mapping:context:] instead"))); ++ (nonnull NSArray *)deserializeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping context:(nonnull NSManagedObjectContext *)context __attribute__((deprecated("Use +[FEMDeserializer collectionFromRepresentation:mapping:context:] instead"))); + (nonnull NSArray *)synchronizeCollectionExternalRepresentation:(nonnull NSArray *)externalRepresentation usingMapping:(nonnull FEMMapping *)mapping predicate:(nonnull NSPredicate *)predicate context:(nonnull NSManagedObjectContext *)context __attribute__((unavailable)); @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h index ecf0a20..b40a34f 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h @@ -11,10 +11,9 @@ NSMutableDictionary *_relationshipMap; } -- (nonnull instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); -+ (nonnull instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); -- (nonnull instancetype)initWithRootPath:(nullable NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass] or -[FEMMapping initWithEntityName:] insted"))); - +- (nonnull instancetype)init __attribute__((unavailable("use -[FEMMapping initWithObjectClass:] or -[FEMMapping initWithEntityName:] insted"))); ++ (nonnull instancetype)new __attribute__((unavailable("use -[FEMMapping initWithObjectClass:] or -[FEMMapping initWithEntityName:] insted"))); +- (nonnull instancetype)initWithRootPath:(nullable NSString *)rootPath __attribute__((unavailable("use -[FEMMapping initWithObjectClass:] or -[FEMMapping initWithEntityName:] insted"))); - (nonnull instancetype)initWithObjectClass:(nonnull Class)objectClass NS_DESIGNATED_INITIALIZER; - (nonnull instancetype)initWithObjectClass:(nonnull Class)objectClass rootPath:(nullable NSString *)rootPath; @@ -53,8 +52,8 @@ @interface FEMMapping (FEMObjectMapping_Deprecated) -+ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); -+ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass rootPath:(nullable NSString *)rootPath configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); ++ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:] instead"))); ++ (nonnull FEMMapping *)mappingForClass:(nonnull Class)objectClass rootPath:(nullable NSString *)rootPath configuration:(nonnull void (^)(FEMMapping * __nonnull mapping))configuration __attribute__((deprecated("Use -[FEMMapping initWithObjectClass:rootPath:] instead"))); @end From fe7e903319c1d55f20a40b1128a26c3b03effb77 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:07:25 +0300 Subject: [PATCH 58/95] Renaming in FEMRelationship --- .../Core/Deserializer/FEMDeserializer.m | 4 +- .../Source/Core/Mapping/Object/FEMMapping.h | 6 +- .../Source/Core/Mapping/Object/FEMMapping.m | 2 +- .../Mapping/Relationship/FEMRelationship.h | 45 ++++++-- .../Mapping/Relationship/FEMRelationship.m | 102 ++++++++++-------- .../Source/Core/Serializer/FEMSerializer.m | 4 +- .../Source/Utility/FEMMappingUtility.m | 2 +- .../Source/Utility/FEMRepresentationUtility.m | 2 +- FastEasyMappingTests/Specs/FEMCacheSpec.m | 2 +- .../Specs/FEMManagedObjectDeserializerSpec.m | 4 +- 10 files changed, 102 insertions(+), 71 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index a622fbc..6caae93 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -56,14 +56,14 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * if (relationshipRepresentation != NSNull.null) { if (relationship.isToMany) { targetValue = [self _collectionFromRepresentation:relationshipRepresentation - mapping:relationship.objectMapping + mapping:relationship.mapping allocateIfNeeded:!relationship.weak]; objc_property_t property = class_getProperty([object class], [relationship.property UTF8String]); targetValue = [targetValue fem_propertyRepresentation:property]; } else { targetValue = [self _objectFromRepresentation:relationshipRepresentation - mapping:relationship.objectMapping + mapping:relationship.mapping allocateIfNeeded:!relationship.weak]; } } diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h index b40a34f..aed97ee 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h @@ -60,8 +60,8 @@ @interface FEMMapping (FEMManagedObjectMapping_Deprecated) -+ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName;// __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); -+ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName rootPath:(nullable NSString *)rootPath configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration; // __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:] instead"))); ++ (nonnull FEMMapping *)mappingForEntityName:(nonnull NSString *)entityName rootPath:(nullable NSString *)rootPath configuration:(nullable void (^)(FEMMapping * __nonnull sender))configuration __attribute__((deprecated("Use -[FEMMapping initWithEntityName:rootPath:] instead"))); @end diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m index f0228a0..1b8000d 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m @@ -56,7 +56,7 @@ - (void)addPropertyMapping:(id)propertyMapping toMap:(NSMutableDict NSParameterAssert(propertyMapping); NSAssert( propertyMapping.property.length > 0, - @"It's illegal to add objectMapping without specified property:%@", + @"It's illegal to add mapping without specified property:%@", propertyMapping ); diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h index da3697d..f2c64b9 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h @@ -12,29 +12,52 @@ @property (nonatomic, copy, nonnull) FEMAssignmentPolicy assignmentPolicy; @property (nonatomic) BOOL weak; -@property (nonatomic, strong, nonnull) FEMMapping *objectMapping; +@property (nonatomic, strong, nonnull) FEMMapping *mapping; @property (nonatomic, getter=isToMany) BOOL toMany; -- (void)setObjectMapping:(nonnull FEMMapping *)objectMapping forKeyPath:(nullable NSString *)keyPath; +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property mapping:(nonnull FEMMapping *)mapping; + +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property + keyPath:(nullable NSString *)keyPath + mapping:(nonnull FEMMapping *)mapping NS_DESIGNATED_INITIALIZER; + +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property + keyPath:(nonnull NSString *)keyPath + mapping:(nonnull FEMMapping *)mapping + assignmentPolicy:(nonnull FEMAssignmentPolicy)assignmentPolicy; + +- (void)setMapping:(nonnull FEMMapping *)mapping forKeyPath:(nullable NSString *)keyPath; + +@end + +@interface FEMRelationship (Deprecated) + +- (void)setObjectMapping:(nonnull FEMMapping *)objectMapping forKeyPath:(nullable NSString *)keyPath __attribute__((deprecated("Use -[FEMRelationship setMappaing:forKeyPath:] instead"))); - (nonnull instancetype)initWithProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath assignmentPolicy:(nullable FEMAssignmentPolicy)policy - objectMapping:(nullable FEMMapping *)objectMapping NS_DESIGNATED_INITIALIZER; + objectMapping:(nullable FEMMapping *)objectMapping __attribute__((deprecated("Use -[FEMRelationship initWithProperty:keyPath:mapping:assignmentPolicy:] instead"))); +/** +* same as + [FEMRelationship mappingOfProperty:property toKeyPath:nil mapping:mapping]; +*/ ++ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property objectMapping:(nonnull FEMMapping *)objectMapping __attribute__((deprecated("Use -[FEMRelationship initWithProperty:mapping:] instead"))); + (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property - configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration; + toKeyPath:(nullable NSString *)keyPath + objectMapping:(nonnull FEMMapping *)objectMapping __attribute__((deprecated("Use -[FEMRelationship initWithProperty:keyPath:mapping:] instead"))); + +@property (nonatomic, strong, nonnull) FEMMapping *objectMapping __attribute__((deprecated("Use FEMRelationship.mapping instead"))); + +@end + +@interface FEMRelationship (Unavailable) + (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property - toKeyPath:(nullable NSString *)keyPath - configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration; + configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration __attribute__((unavailable("Use -[FEMRelationship initWithProperty:keyPath:mapping:] instead"))); -/** -* same as + [FEMRelationship mappingOfProperty:property toKeyPath:nil objectMapping:objectMapping]; -*/ -+ (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property objectMapping:(nonnull FEMMapping *)objectMapping; + (nonnull instancetype)mappingOfProperty:(nonnull NSString *)property toKeyPath:(nullable NSString *)keyPath - objectMapping:(nonnull FEMMapping *)objectMapping; + configuration:(nonnull void (^)(FEMRelationship * __nonnull mapping))configuration __attribute__((unavailable("Use -[FEMRelationship initWithProperty:keyPath:mapping:] instead"))); @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m index f9618b8..a798f2b 100644 --- a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m +++ b/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m @@ -10,69 +10,48 @@ @implementation FEMRelationship #pragma mark - Init -- (instancetype)initWithProperty:(NSString *)property - keyPath:(NSString *)keyPath - assignmentPolicy:(FEMAssignmentPolicy)policy - objectMapping:(FEMMapping *)objectMapping { - NSParameterAssert(property.length > 0); - - self = [super init]; - if (self) { - _property = [property copy]; - _keyPath = [keyPath copy]; - _assignmentPolicy = (FEMAssignmentPolicy)[policy copy] ?: FEMAssignmentPolicyAssign; - _objectMapping = objectMapping; - } - - return self; +- (instancetype)initWithProperty:(NSString *)property mapping:(FEMMapping *)mapping { + return [self initWithProperty:property keyPath:nil mapping:mapping]; } -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath configuration:(void (^)(FEMRelationship *mapping))configuration { - NSParameterAssert(configuration); +- (instancetype)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath mapping:(FEMMapping *)mapping { + self = [super init]; + if (self) { + self.property = property; + self.keyPath = keyPath; + self.mapping = mapping; + self.assignmentPolicy = FEMAssignmentPolicyAssign; + } - FEMRelationship *mapping = [[self alloc] initWithProperty:property - keyPath:keyPath - assignmentPolicy:NULL - objectMapping:nil]; - configuration(mapping); - return mapping; + return self; } -+ (instancetype)mappingOfProperty:(NSString *)property configuration:(void (^)(FEMRelationship *mapping))configuration { - return [self mappingOfProperty:property toKeyPath:nil configuration:configuration]; +- (instancetype)initWithProperty:(NSString *)property keyPath:(NSString *)keyPath mapping:(FEMMapping *)mapping assignmentPolicy:(FEMAssignmentPolicy)assignmentPolicy { + self = [self initWithProperty:property keyPath:keyPath mapping:mapping]; + if (self) { + self.assignmentPolicy = assignmentPolicy; + } + return self; } -+ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath objectMapping:(FEMMapping *)objectMapping { - return [[self alloc] initWithProperty:property keyPath:keyPath assignmentPolicy:NULL objectMapping:objectMapping]; -} +#pragma mark - Shortcut -+ (instancetype)mappingOfProperty:(NSString *)property objectMapping:(FEMMapping *)objectMapping { - return [self mappingOfProperty:property toKeyPath:nil objectMapping:objectMapping]; -} - -#pragma mark - Property objectMapping - -- (void)setObjectMapping:(FEMMapping *)objectMapping forKeyPath:(NSString *)keyPath { - _objectMapping = objectMapping; - - [self setKeyPath:keyPath]; -} - -- (void)setObjectMapping:(FEMMapping *)objectMapping { - [self setObjectMapping:objectMapping forKeyPath:nil]; +- (void)setMapping:(nonnull FEMMapping *)mapping forKeyPath:(nullable NSString *)keyPath { + self.mapping = mapping; + self.keyPath = keyPath; } #pragma mark - Description - (NSString *)description { return [NSString stringWithFormat: - @"<%@ %p>\n {\nproperty:%@ keyPath:%@ toMany:%@\nobjectMapping:(%@)}\n", + @"<%@ %p>\n {\nproperty:%@ keyPath:%@ toMany:%@\nmapping:(%@)}\n", NSStringFromClass(self.class), (__bridge void *) self, self.property, self.keyPath, @(self.toMany), - [self.objectMapping description] + [self.mapping description] ]; } @@ -80,12 +59,41 @@ - (NSString *)description { @implementation FEMRelationship (Deprecated) -+ (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPath configuration:(void (^)(FEMRelationship *mapping))configuration { - return [self mappingOfProperty:property toKeyPath:keyPath configuration:configuration]; +@dynamic objectMapping; + +- (FEMMapping *)objectMapping { + return self.mapping; +} + +- (void)setObjectMapping:(FEMMapping *)objectMapping { + self.mapping = objectMapping; } + (instancetype)mappingOfProperty:(NSString *)property keyPath:(NSString *)keyPath objectMapping:(FEMMapping *)objectMapping { - return [self mappingOfProperty:property toKeyPath:keyPath objectMapping:objectMapping]; + return [[self alloc] initWithProperty:property keyPath:keyPath mapping:objectMapping]; +} + +#pragma mark - Init + +- (instancetype)initWithProperty:(NSString *)property + keyPath:(NSString *)keyPath + assignmentPolicy:(FEMAssignmentPolicy)policy + objectMapping:(FEMMapping *)objectMapping { + return [self initWithProperty:property keyPath:keyPath mapping:objectMapping assignmentPolicy:policy]; +} + ++ (instancetype)mappingOfProperty:(NSString *)property toKeyPath:(NSString *)keyPath objectMapping:(FEMMapping *)objectMapping { + return [[self alloc] initWithProperty:property keyPath:keyPath mapping:objectMapping]; +} + ++ (instancetype)mappingOfProperty:(NSString *)property objectMapping:(FEMMapping *)objectMapping { + return [[self alloc] initWithProperty:property mapping:objectMapping]; +} + +#pragma mark - Property objectMapping + +- (void)setObjectMapping:(FEMMapping *)objectMapping forKeyPath:(NSString *)keyPath { + [self setMapping:objectMapping forKeyPath:keyPath]; } @end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m index 6ed79ba..383789a 100644 --- a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m +++ b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m @@ -82,9 +82,9 @@ + (void)setRelationshipObjectOn:(NSMutableDictionary *)representation if (value) { id relationshipRepresentation = nil; if (relationshipMapping.isToMany) { - relationshipRepresentation = [self _serializeCollection:value usingMapping:relationshipMapping.objectMapping]; + relationshipRepresentation = [self _serializeCollection:value usingMapping:relationshipMapping.mapping]; } else { - relationshipRepresentation = [self _serializeObject:value usingMapping:relationshipMapping.objectMapping]; + relationshipRepresentation = [self _serializeObject:value usingMapping:relationshipMapping.mapping]; } if (relationshipMapping.keyPath.length > 0) { diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m index 4a2a803..9889f37 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.m +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -10,7 +10,7 @@ void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { apply(mapping); for (FEMRelationship *relationship in mapping.relationships) { - FEMMappingApply(relationship.objectMapping, apply); + FEMMappingApply(relationship.mapping, apply); } } diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index a8446ce..72282db 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -31,7 +31,7 @@ void _FEMRepresentationCollectObjectPrimaryKeys(NSDictionary *object, FEMMapping for (FEMRelationship *relationship in mapping.relationships) { id relationshipRepresentation = FEMRepresentationRootForKeyPath(object, relationship.keyPath); if (relationshipRepresentation && relationshipRepresentation != NSNull.null) { - _FEMRepresentationCollectPresentedPrimaryKeys(relationshipRepresentation, relationship.objectMapping, container); + _FEMRepresentationCollectPresentedPrimaryKeys(relationshipRepresentation, relationship.mapping, container); } } } diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 65de1fd..3fce26f 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -135,7 +135,7 @@ mapping = [MappingProvider personWithCarMapping]; cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:context]; - carMapping = (id) [mapping relationshipForProperty:@"car"].objectMapping; + carMapping = (id) [mapping relationshipForProperty:@"car"].mapping; }); afterEach(^{ diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index 8780170..6ed2af9 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -232,7 +232,7 @@ }); - context(@"with hasOne objectMapping", ^{ + context(@"with hasOne mapping", ^{ __block Person *person; __block Car *expectedCar; @@ -261,7 +261,7 @@ }); - context(@"with hasMany objectMapping", ^{ + context(@"with hasMany mapping", ^{ __block Person *person; beforeEach(^{ From 7ad4f16089000eb7ef32482330f354a736e9bc2b Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:07:34 +0300 Subject: [PATCH 59/95] Fix mapping provider --- .../Mapping Provider/MappingProvider.m | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/FastEasyMappingTests/Mapping Provider/MappingProvider.m b/FastEasyMappingTests/Mapping Provider/MappingProvider.m index 5553c4e..7d270dd 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProvider.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProvider.m @@ -67,17 +67,9 @@ + (FEMMapping *)personMapping { // [mapping setPrimaryKey:@"personID"]; [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; - [mapping addRelationship:[FEMRelationship mappingOfProperty:@"car" - configuration:^(FEMRelationship *relationshipMapping) { - [relationshipMapping setObjectMapping:[self carMapping] - forKeyPath:@"car"]; - }]]; - - [mapping addRelationship:[FEMRelationship mappingOfProperty:@"phones" - configuration:^(FEMRelationship *relationshipMapping) { - [relationshipMapping setToMany:YES]; - [relationshipMapping setObjectMapping:[self phoneMapping] forKeyPath:@"phones"]; - }]]; + + [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; + [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; }]; } @@ -87,14 +79,9 @@ + (FEMMapping *)personWithPhoneMapping { [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; - [mapping addRelationship:[FEMRelationship mappingOfProperty:@"phones" - configuration:^(FEMRelationship *relationshipMapping) { - FEMMapping *phoneMapping = [self phoneMapping]; - [phoneMapping setPrimaryKey:@"phoneID"]; - - [relationshipMapping setToMany:YES]; - [relationshipMapping setObjectMapping:phoneMapping forKeyPath:@"phones"]; - }]]; + FEMMapping *phoneMapping = [self phoneMapping]; + phoneMapping.primaryKey = @"phoneID"; + [mapping addToManyRelationshipMapping:phoneMapping forProperty:@"phones" keyPath:@"phones"]; }]; } @@ -103,10 +90,8 @@ + (FEMMapping *)personWithCarMapping { [mapping setPrimaryKey:@"personID"]; [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; [mapping addAttributesFromArray:@[@"name", @"email"]]; - [mapping addRelationship:[FEMRelationship mappingOfProperty:@"car" - configuration:^(FEMRelationship *relationshipMapping) { - [relationshipMapping setObjectMapping:[self carMappingWithPrimaryKey] forKeyPath:@"car"]; - }]]; + + [mapping addRelationshipMapping:[self carMappingWithPrimaryKey] forProperty:@"car" keyPath:@"car"]; }]; } From ab0573c56a6280af6a8b4eb4f1af7d28bb0b57c2 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:14:37 +0300 Subject: [PATCH 60/95] Update mapping provider syntax to latest --- .../Mapping Provider/MappingProvider.m | 107 +++++++++--------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/FastEasyMappingTests/Mapping Provider/MappingProvider.m b/FastEasyMappingTests/Mapping Provider/MappingProvider.m index 7d270dd..683a9d9 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProvider.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProvider.m @@ -13,86 +13,87 @@ @implementation MappingProvider + (FEMMapping *)carMappingWithPrimaryKey { FEMMapping *mapping = [self carMapping]; - [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; + mapping.primaryKey = @"carID"; + [mapping addAttributesFromDictionary:@{@"carID": @"id"}]; return mapping; } + (FEMMapping *)carMapping { - return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"model", @"year"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + + return mapping; } + (FEMMapping *)carWithRootKeyMapping { - return [FEMMapping mappingForEntityName:@"Car" - rootPath:@"car" - configuration:^(FEMMapping *mapping) { -// [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; - [mapping addAttributesFromArray:@[@"model", @"year"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Car" rootPath:@"car"]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + + return mapping; } + (FEMMapping *)carNestedAttributesMapping { - return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { -// [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesFromDictionary:@{@"carID" : @"id", @"year" : @"information.year"}]; - [mapping addAttributesFromArray:@[@"model"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id", @"year" : @"information.year"}]; + [mapping addAttributesFromArray:@[@"model"]]; + + return mapping; } + (FEMMapping *)carWithDateMapping { - return [FEMMapping mappingForEntityName:@"Car" configuration:^(FEMMapping *mapping) { -// [mapping setPrimaryKey:@"carID"]; - [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; - [mapping addAttributesFromArray:@[@"model", @"year"]]; - [mapping addAttribute:[FEMAttribute mappingOfProperty:@"createdAt" - toKeyPath:@"created_at" - dateFormat:@"yyyy-MM-dd"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; + [mapping addAttributesFromDictionary:@{@"carID" : @"id"}]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + FEMAttribute *createdAtAttribute = [FEMAttribute mappingOfProperty:@"createdAt" toKeyPath:@"created_at" dateFormat:@"yyyy-MM-dd"]; + [mapping addAttribute:createdAtAttribute]; + + return mapping; } + (FEMMapping *)phoneMapping { - return [FEMMapping mappingForEntityName:@"Phone" configuration:^(FEMMapping *mapping) { -// [mapping setPrimaryKey:@"phoneID"]; - [mapping addAttributesFromDictionary:@{@"phoneID" : @"id"}]; - [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Phone"]; + mapping.primaryKey = @"phoneID"; + [mapping addAttributesFromDictionary:@{@"phoneID" : @"id"}]; + [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; + + return mapping; } + (FEMMapping *)personMapping { - return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { -// [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; - [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; - - [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; - [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + mapping.primaryKey = @"personID"; + [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; + [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; + + [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; + [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; + + return mapping; } + (FEMMapping *)personWithPhoneMapping { - return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { - [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; - [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; - - FEMMapping *phoneMapping = [self phoneMapping]; - phoneMapping.primaryKey = @"phoneID"; - [mapping addToManyRelationshipMapping:phoneMapping forProperty:@"phones" keyPath:@"phones"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + mapping.primaryKey = @"personID"; + [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; + [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; + + FEMMapping *phoneMapping = [self phoneMapping]; + phoneMapping.primaryKey = @"phoneID"; + [mapping addToManyRelationshipMapping:phoneMapping forProperty:@"phones" keyPath:@"phones"]; + + return mapping; } + (FEMMapping *)personWithCarMapping { - return [FEMMapping mappingForEntityName:@"Person" configuration:^(FEMMapping *mapping) { - [mapping setPrimaryKey:@"personID"]; - [mapping addAttributesFromDictionary:@{@"personID" : @"id"}]; - [mapping addAttributesFromArray:@[@"name", @"email"]]; + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + mapping.primaryKey = @"personID"; + [mapping addAttributesFromDictionary:@{@"personID": @"id"}]; + [mapping addAttributesFromArray:@[@"name", @"email"]]; + [mapping addRelationshipMapping:[self carMappingWithPrimaryKey] forProperty:@"car" keyPath:@"car"]; - [mapping addRelationshipMapping:[self carMappingWithPrimaryKey] forProperty:@"car" keyPath:@"car"]; - }]; + return mapping; } @end From 26ab9ee5161c4439621766ed5b0f4c671c8ba7f3 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:16:00 +0300 Subject: [PATCH 61/95] Update FEMMapping syntax to latest --- .../Source/Core/Mapping/Object/FEMMapping.m | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m index 1b8000d..84a2cf2 100644 --- a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m +++ b/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m @@ -150,18 +150,14 @@ - (void)addAttributeWithProperty:(NSString *)property keyPath:(NSString *)keyPat } - (void)addRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath { - FEMRelationship *relationshipMapping = [FEMRelationship mappingOfProperty:property - toKeyPath:keyPath - objectMapping:mapping]; - [self addRelationship:relationshipMapping]; + FEMRelationship *relationship = [[FEMRelationship alloc] initWithProperty:property keyPath:keyPath mapping:mapping]; + [self addRelationship:relationship]; } - (void)addToManyRelationshipMapping:(FEMMapping *)mapping forProperty:(NSString *)property keyPath:(NSString *)keyPath { - FEMRelationship *relationshipMapping = [FEMRelationship mappingOfProperty:property - toKeyPath:keyPath - objectMapping:mapping]; - [relationshipMapping setToMany:YES]; - [self addRelationship:relationshipMapping]; + FEMRelationship *relationship = [[FEMRelationship alloc] initWithProperty:property keyPath:keyPath mapping:mapping]; + relationship.toMany = YES; + [self addRelationship:relationship]; } @end From 9f1a4bf211b58915c0482eb3aeb1818b761ddfa5 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:28:21 +0300 Subject: [PATCH 62/95] Update native mapping provider to latest syntax --- .../Mapping Provider/MappingProviderNative.m | 233 +++++++++--------- 1 file changed, 117 insertions(+), 116 deletions(-) diff --git a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m index c62b1e9..63ed8c8 100644 --- a/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m +++ b/FastEasyMappingTests/Mapping Provider/MappingProviderNative.m @@ -19,167 +19,168 @@ @implementation MappingProviderNative + (FEMMapping *)carMapping { - return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"model", @"year"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class]]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + + return mapping; } + (FEMMapping *)carWithRootKeyMapping { - return [FEMMapping mappingForClass:[CarNative class] - rootPath:@"car" - configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"model", @"year"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class] rootPath:@"car"]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + + return mapping; } + (FEMMapping *)carNestedAttributesMapping { - return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"model"]]; - [mapping addAttributesFromDictionary:@{ - @"year" : @"information.year" - }]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class]]; + [mapping addAttributesFromArray:@[@"model"]]; + [mapping addAttributesFromDictionary:@{@"year" : @"information.year"}]; + + return mapping; } + (FEMMapping *)carWithDateMapping { - return [FEMMapping mappingForClass:[CarNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"model", @"year"]]; - [mapping addAttribute:[FEMAttribute mappingOfProperty:@"createdAt" - toKeyPath:@"created_at" - dateFormat:@"yyyy-MM-dd"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class]]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + FEMAttribute *createdAtAttribute = [FEMAttribute mappingOfProperty:@"createdAt" toKeyPath:@"created_at" dateFormat:@"yyyy-MM-dd"]; + [mapping addAttribute:createdAtAttribute]; + + return mapping; } + (FEMMapping *)phoneMapping { - return [FEMMapping mappingForClass:[PhoneNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"number"]]; - [mapping addAttributesFromDictionary:@{ - @"DDI" : @"ddi", - @"DDD" : @"ddd", - }]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PhoneNative class]]; + [mapping addAttributesFromArray:@[@"number"]]; + [mapping addAttributesFromDictionary:@{@"DDI" : @"ddi", @"DDD" : @"ddd"}]; + + return mapping; } + (FEMMapping *)personMapping { - return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { - NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; - [mapping addAttributesFromArray:@[@"name", @"email"]]; - [mapping addAttribute:[FEMAttribute mappingOfProperty:@"gender" - toKeyPath:@"gender" - map:^id(id value) { - return genders[value]; - } - reverseMap:^id(id value) { - return [genders allKeysForObject:value].lastObject; - }]]; - - [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; - [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PersonNative class]]; + [mapping addAttributesFromArray:@[@"name", @"email"]]; + + NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; + FEMAttribute *genderAttribute = [[FEMAttribute alloc] initWithProperty:@"gender" keyPath:@"gender" map:^id(id value) { + return genders[value]; + } reverseMap:^id(id value) { + return [genders allKeysForObject:value].lastObject; + }]; + [mapping addAttribute:genderAttribute]; + + [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; + [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; + + return mapping; } + (FEMMapping *)personWithCarMapping { - return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"name", @"email"]]; - [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PersonNative class]]; + [mapping addAttributesFromArray:@[@"name", @"email"]]; + [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; + + return mapping; } + (FEMMapping *)personWithPhonesMapping { - return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"name", @"email"]]; - [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PersonNative class]]; + [mapping addAttributesFromArray:@[@"name", @"email"]]; + [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; + + return mapping; } + (FEMMapping *)personWithOnlyValueBlockMapping { - return [FEMMapping mappingForClass:[PersonNative class] configuration:^(FEMMapping *mapping) { - NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; - [mapping addAttributesFromArray:@[@"name", @"email"]]; - [mapping addAttribute:[FEMAttribute mappingOfProperty:@"gender" - toKeyPath:@"gender" - map:^id(id value) { - return genders[value]; - } - reverseMap:^id(id value) { - return [genders allKeysForObject:value].lastObject; - }]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PersonNative class]]; + [mapping addAttributesFromArray:@[@"name", @"email"]]; + + NSDictionary *genders = @{@"male" : @(GenderMale), @"female" : @(GenderFemale)}; + FEMAttribute *genderAttribute = [[FEMAttribute alloc] initWithProperty:@"gender" keyPath:@"gender" map:^id(id value) { + return genders[value]; + } reverseMap:^id(id value) { + return [genders allKeysForObject:value].lastObject; + }]; + [mapping addAttribute:genderAttribute]; + + return mapping; } + (FEMMapping *)addressMapping { - return [FEMMapping mappingForClass:[AddressNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"street"]]; - [mapping addAttribute:[FEMAttribute mappingOfProperty:@"location" - toKeyPath:@"location" - map:^id(id value) { - CLLocationDegrees latitudeValue = [[value objectAtIndex:0] doubleValue]; - CLLocationDegrees longitudeValue = [[value objectAtIndex:1] doubleValue]; - return [[CLLocation alloc] initWithLatitude:latitudeValue - longitude:longitudeValue]; - } - reverseMap:^id(CLLocation *value) { - return @[ - @(value.coordinate.latitude), - @(value.coordinate.longitude) - ]; - }]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[AddressNative class]]; + [mapping addAttributesFromArray:@[@"street"]]; + + FEMAttribute *locationAttribute = [[FEMAttribute alloc] initWithProperty:@"location" keyPath:@"location" map:^id(id value) { + CLLocationDegrees latitudeValue = [[value objectAtIndex:0] doubleValue]; + CLLocationDegrees longitudeValue = [[value objectAtIndex:1] doubleValue]; + return [[CLLocation alloc] initWithLatitude:latitudeValue longitude:longitudeValue]; + } reverseMap:^id(CLLocation *value) { + return @[@(value.coordinate.latitude), @(value.coordinate.longitude)]; + }]; + [mapping addAttribute:locationAttribute]; + + return mapping; } + (FEMMapping *)nativeMapping { - return [FEMMapping mappingForClass:[Native class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[ - @"charProperty", - @"unsignedCharProperty", - @"shortProperty", - @"unsignedShortProperty", - @"intProperty", - @"unsignedIntProperty", - @"integerProperty", - @"unsignedIntegerProperty", - @"longProperty", - @"unsignedLongProperty", - @"longLongProperty", - @"unsignedLongLongProperty", - @"floatProperty", - @"cgFloatProperty", - @"doubleProperty", - @"boolProperty" - ]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Native class]]; + [mapping addAttributesFromArray:@[ + @"charProperty", + @"unsignedCharProperty", + @"shortProperty", + @"unsignedShortProperty", + @"intProperty", + @"unsignedIntProperty", + @"integerProperty", + @"unsignedIntegerProperty", + @"longProperty", + @"unsignedLongProperty", + @"longLongProperty", + @"unsignedLongLongProperty", + @"floatProperty", + @"cgFloatProperty", + @"doubleProperty", + @"boolProperty" + ]]; + + return mapping; } + (FEMMapping *)nativeMappingWithNullPropertie { - return [FEMMapping mappingForClass:[CatNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"age"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[CatNative class]]; + [mapping addAttributesFromArray:@[@"age"]]; + + return mapping; } + (FEMMapping *)planeMapping { - return [FEMMapping mappingForClass:[PlaneNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromDictionary:@{@"flightNumber" : @"flight_number"}]; - [mapping addToManyRelationshipMapping:[self personMapping] forProperty:@"persons" keyPath:@"persons"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[PlaneNative class]]; + [mapping addAttributesFromDictionary:@{@"flightNumber" : @"flight_number"}]; + [mapping addToManyRelationshipMapping:[self personMapping] forProperty:@"persons" keyPath:@"persons"]; + + return mapping; } + (FEMMapping *)alienMapping { - return [FEMMapping mappingForClass:[AlienNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"name"]]; - [mapping addToManyRelationshipMapping:[self fingerMapping] forProperty:@"fingers" keyPath:@"fingers"]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[AlienNative class]]; + [mapping addAttributesFromArray:@[@"name"]]; + [mapping addToManyRelationshipMapping:[self fingerMapping] forProperty:@"fingers" keyPath:@"fingers"]; + + return mapping; } + (FEMMapping *)fingerMapping { - return [FEMMapping mappingForClass:[FingerNative class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"name"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[FingerNative class]]; + [mapping addAttributesFromArray:@[@"name"]]; + + return mapping; } + (FEMMapping *)nativeChildMapping { - return [FEMMapping mappingForClass:[NativeChild class] configuration:^(FEMMapping *mapping) { - [mapping addAttributesFromArray:@[@"intProperty", @"boolProperty", @"childProperty"]]; - }]; + FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[NativeChild class]]; + [mapping addAttributesFromArray:@[@"intProperty", @"boolProperty", @"childProperty"]]; + + return mapping; } @end From f773a8558435bcc954950b1eb136d453278b8013 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:31:04 +0300 Subject: [PATCH 63/95] Update cache specs to latest syntax --- FastEasyMappingTests/Specs/FEMCacheSpec.m | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMCacheSpec.m b/FastEasyMappingTests/Specs/FEMCacheSpec.m index 3fce26f..9585477 100644 --- a/FastEasyMappingTests/Specs/FEMCacheSpec.m +++ b/FastEasyMappingTests/Specs/FEMCacheSpec.m @@ -83,10 +83,8 @@ it(@"should add objects", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] beNil]; - - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + + Car *car = [FEMDeserializer objectFromRepresentation:representation mapping:mapping context:context]; [cache addExistingObject:car mapping:mapping]; [[[cache existingObjectForRepresentation:representation mapping:mapping] should] equal:car]; @@ -95,9 +93,7 @@ it(@"should return registered object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer objectFromRepresentation:representation mapping:mapping context:context]; [[@(car.objectID.isTemporaryID) should] beTrue]; [[[context objectRegisteredForID:car.objectID] should] equal:car]; @@ -108,9 +104,8 @@ it(@"should return saved object", ^{ [[@([Car MR_countOfEntitiesWithContext:context]) should] beZero]; - Car *car = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Car *car = [FEMDeserializer objectFromRepresentation:representation mapping:mapping context:context]; + [[@(car.objectID.isTemporaryID) should] beTrue]; [context MR_saveToPersistentStoreAndWait]; [[@([Car MR_countOfEntitiesWithContext:context]) should] equal:@1]; @@ -146,18 +141,14 @@ }); it(@"should return nil for missing nested object", ^{ - [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + [FEMDeserializer objectFromRepresentation:representation mapping:mapping context:context]; id missingObjectRepresentation = @{@"id": @2}; [[[cache existingObjectForRepresentation:missingObjectRepresentation mapping:carMapping] should] beNil]; }); it(@"should return existing nested object", ^{ - Person *person = [FEMDeserializer deserializeObjectExternalRepresentation:representation - usingMapping:mapping - context:context]; + Person *person = [FEMDeserializer objectFromRepresentation:representation mapping:mapping context:context]; [[[cache existingObjectForRepresentation:representation[@"car"] mapping:carMapping] should] equal:person.car]; }); }); From 1930c2ff02ae68eae69f4238045b3c442bfe437e Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:47:11 +0300 Subject: [PATCH 64/95] Update deserialized spec to latest syntax --- .../Specs/FEMObjectDeserializerSpec.m | 57 ++++++++----------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m index 2421009..e74eb0a 100644 --- a/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMObjectDeserializerSpec.m @@ -31,8 +31,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative carMapping]]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:[MappingProviderNative carMapping]]; }); specify(^{ @@ -56,8 +55,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative carWithRootKeyMapping]]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:[MappingProviderNative carWithRootKeyMapping]]; externalRepresentation = [externalRepresentation objectForKey:@"car"]; }); @@ -82,8 +80,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative carNestedAttributesMapping]]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:[MappingProviderNative carNestedAttributesMapping]]; }); specify(^{ @@ -107,8 +104,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative carWithDateMapping]]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:[MappingProviderNative carWithDateMapping]]; }); specify(^{ @@ -145,8 +141,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Male"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; }); specify(^{ @@ -162,8 +158,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Female"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative personWithOnlyValueBlockMapping]]; }); specify(^{ @@ -179,8 +175,8 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Address"]; - address = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative addressMapping]]; + address = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative addressMapping]]; }); specify(^{ @@ -212,8 +208,8 @@ expectedCar = [carFactory build]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative personMapping]]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative personMapping]]; }); specify(^{ @@ -241,8 +237,8 @@ [mapping addRelationshipMapping:[MappingProviderNative carMapping] forProperty:@"car" keyPath:@"vehicle"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:mapping]; }); specify(^{ @@ -269,8 +265,8 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative personMapping]]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative personMapping]]; }); specify(^{ @@ -293,8 +289,7 @@ forProperty:@"phones" keyPath:@"cellphones"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:mapping]; }); specify(^{ @@ -323,8 +318,7 @@ beforeEach(^{ FEMObjectMapping * mapping = [MappingProviderNative nativeMapping]; NSDictionary * externalRepresentation = [CMFixture buildUsingFixture:@"Native"]; - native = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + native = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:mapping]; }); specify(^{ @@ -413,8 +407,7 @@ beforeEach(^{ FEMObjectMapping *catMapping = [MappingProviderNative nativeMappingWithNullPropertie]; NSDictionary *values = @{ @"age": [NSNull null] }; - cat = [FEMDeserializer deserializeObjectExternalRepresentation:values - usingMapping:catMapping]; + cat = [FEMDeserializer objectFromRepresentation:values mapping:catMapping]; }); specify(^{ @@ -438,8 +431,7 @@ beforeEach(^{ externalRepresentation = [CMFixture buildUsingFixture:@"Cars"]; - carsArray = [FEMDeserializer deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative carMapping]]; + carsArray = [FEMDeserializer collectionFromRepresentation:externalRepresentation mapping:[MappingProviderNative carMapping]]; }); specify(^{ @@ -464,8 +456,7 @@ [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"stewardess" keyPath:@"stewardess"]; [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"stars" keyPath:@"stars"]; - plane = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + plane = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:mapping]; }); specify(^{ @@ -499,8 +490,7 @@ FEMObjectMapping * mapping = [[FEMObjectMapping alloc] initWithObjectClass:[SeaplaneNative class]]; [mapping addToManyRelationshipMapping:[MappingProviderNative personMapping] forProperty:@"passengers" keyPath:@"persons"]; - seaplane = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + seaplane = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:mapping]; }); specify(^{ @@ -519,8 +509,7 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Alien"]; - alien = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative alienMapping]]; + alien = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:[MappingProviderNative alienMapping]]; }); specify(^{ From 02c06b4389887e711226ae603f69ce101e9ef4a5 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:49:29 +0300 Subject: [PATCH 65/95] Update managed object deserializer spec to latest syntax --- .../Specs/FEMManagedObjectDeserializerSpec.m | 748 +++++++++--------- 1 file changed, 374 insertions(+), 374 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m index 6ed2af9..f774c4c 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectDeserializerSpec.m @@ -17,482 +17,482 @@ SPEC_BEGIN(FEMManagedObjectDeserializerSpec) -describe(@"FEMDeserializer", ^{ - __block NSManagedObjectContext *moc; + describe(@"FEMDeserializer", ^{ + __block NSManagedObjectContext *moc; - beforeEach(^{ - [MagicalRecord setDefaultModelFromClass:[self class]]; - [MagicalRecord setupCoreDataStackWithInMemoryStore]; + beforeEach(^{ + [MagicalRecord setDefaultModelFromClass:[self class]]; + [MagicalRecord setupCoreDataStackWithInMemoryStore]; - moc = [NSManagedObjectContext MR_defaultContext]; - }); + moc = [NSManagedObjectContext MR_defaultContext]; + }); - afterEach(^{ - moc = nil; + afterEach(^{ + moc = nil; - [MagicalRecord cleanUp]; - }); + [MagicalRecord cleanUp]; + }); - describe(@".objectFromExternalRepresentation:usingMapping:", ^{ + describe(@".objectFromExternalRepresentation:mapping:", ^{ - context(@"a simple object", ^{ + context(@"a simple object", ^{ - __block Car *car; - __block NSDictionary *externalRepresentation; + __block Car *car; + __block NSDictionary *externalRepresentation; - beforeEach(^{ - externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; - }); + beforeEach(^{ + externalRepresentation = [CMFixture buildUsingFixture:@"Car"]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMapping] + context:moc]; + }); - specify(^{ - [car shouldNotBeNil]; - }); + specify(^{ + [car shouldNotBeNil]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); - specify(^{ - [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; - }); + specify(^{ + [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; + }); - }); + }); - context(@"with existing object", ^{ - __block Car *oldCar; - __block Car *car; - __block NSDictionary *externalRepresentation; + context(@"with existing object", ^{ + __block Car *oldCar; + __block Car *car; + __block NSDictionary *externalRepresentation; - beforeEach(^{ - oldCar = [NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:moc]; - oldCar.carID = @(1); - oldCar.year = @"1980"; - oldCar.model = @""; - [moc MR_saveToPersistentStoreAndWait]; + beforeEach(^{ + oldCar = [NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:moc]; + oldCar.carID = @(1); + oldCar.year = @"1980"; + oldCar.model = @""; + [moc MR_saveToPersistentStoreAndWait]; - externalRepresentation = @{ + externalRepresentation = @{ @"id" : @(1), @"model" : @"i30", @"year" : @"2013" - }; + }; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; - }); + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; + }); - specify(^{ - [car shouldNotBeNil]; - }); + specify(^{ + [car shouldNotBeNil]; + }); - specify(^{ - [[car should] equal:oldCar]; - }); + specify(^{ + [[car should] equal:oldCar]; + }); - specify(^{ - [[car.carID should] equal:oldCar.carID]; - }); + specify(^{ + [[car.carID should] equal:oldCar.carID]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); - specify(^{ - [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; - }); + specify(^{ + [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; + }); - specify(^{ - [[[Car MR_findAll] should] haveCountOf:1]; + specify(^{ + [[[Car MR_findAll] should] haveCountOf:1]; + }); }); - }); - context(@"don't clear missing values", ^{ - __block Car *oldCar; - __block Car *car; - __block NSDictionary *externalRepresentation; + context(@"don't clear missing values", ^{ + __block Car *oldCar; + __block Car *car; + __block NSDictionary *externalRepresentation; - beforeEach(^{ - oldCar = [NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:moc]; - oldCar.carID = @(1); - oldCar.year = @"1980"; - oldCar.model = @""; - - externalRepresentation = @{@"id" : @(1), @"model" : @"i30",}; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMappingWithPrimaryKey] - context:moc]; - }); + beforeEach(^{ + oldCar = [NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:moc]; + oldCar.carID = @(1); + oldCar.year = @"1980"; + oldCar.model = @""; - specify(^{ - [[car.carID should] equal:oldCar.carID]; - }); + externalRepresentation = @{@"id" : @(1), @"model" : @"i30",}; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carMappingWithPrimaryKey] + context:moc]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.carID should] equal:oldCar.carID]; + }); - specify(^{ - [[car.year should] equal:oldCar.year]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); + + specify(^{ + [[car.year should] equal:oldCar.year]; + }); + + specify(^{ + [[[Car MR_findAll] should] haveCountOf:1]; + }); - specify(^{ - [[[Car MR_findAll] should] haveCountOf:1]; }); - }); + context(@"with root key", ^{ + __block Car *car; + __block NSDictionary *externalRepresentation; - context(@"with root key", ^{ - __block Car *car; - __block NSDictionary *externalRepresentation; + beforeEach(^{ + externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carWithRootKeyMapping] + context:moc]; + externalRepresentation = [externalRepresentation objectForKey:@"car"]; + }); - beforeEach(^{ - externalRepresentation = [CMFixture buildUsingFixture:@"CarWithRoot"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithRootKeyMapping] - context:moc]; - externalRepresentation = [externalRepresentation objectForKey:@"car"]; - }); + specify(^{ + [car shouldNotBeNil]; + }); - specify(^{ - [car shouldNotBeNil]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; + }); - specify(^{ - [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; }); - }); + context(@"with nested information", ^{ + __block Car *car; + __block NSDictionary *externalRepresentation; - context(@"with nested information", ^{ - __block Car *car; - __block NSDictionary *externalRepresentation; + beforeEach(^{ + externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carNestedAttributesMapping] + context:moc]; + }); - beforeEach(^{ - externalRepresentation = [CMFixture buildUsingFixture:@"CarWithNestedAttributes"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carNestedAttributesMapping] - context:moc]; - }); + specify(^{ + [car shouldNotBeNil]; + }); - specify(^{ - [car shouldNotBeNil]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.year should] equal:[[externalRepresentation objectForKey:@"information"] objectForKey:@"year"]]; + }); - specify(^{ - [[car.year should] equal:[[externalRepresentation objectForKey:@"information"] objectForKey:@"year"]]; }); - }); + context(@"with dateformat", ^{ + __block Car *car; + __block NSDictionary *externalRepresentation; - context(@"with dateformat", ^{ - __block Car *car; - __block NSDictionary *externalRepresentation; + beforeEach(^{ + moc = [NSManagedObjectContext MR_defaultContext]; + externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; + car = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider carWithDateMapping] + context:moc]; + }); - beforeEach(^{ - moc = [NSManagedObjectContext MR_defaultContext]; - externalRepresentation = [CMFixture buildUsingFixture:@"CarWithDate"]; - car = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carWithDateMapping] - context:moc]; - }); + specify(^{ + [car shouldNotBeNil]; + }); - specify(^{ - [car shouldNotBeNil]; - }); + specify(^{ + [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; + }); - specify(^{ - [[car.model should] equal:[externalRepresentation objectForKey:@"model"]]; - }); + specify(^{ + [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; + }); - specify(^{ - [[car.year should] equal:[externalRepresentation objectForKey:@"year"]]; - }); + it(@"should populate createdAt property with a NSDate", ^{ - it(@"should populate createdAt property with a NSDate", ^{ + NSDateFormatter *format = [[NSDateFormatter alloc] init]; + format.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; + format.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; + format.dateFormat = @"yyyy-MM-dd"; + NSDate *expectedDate = [format dateFromString:[externalRepresentation objectForKey:@"created_at"]]; + [[car.createdAt should] equal:expectedDate]; - NSDateFormatter *format = [[NSDateFormatter alloc] init]; - format.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; - format.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; - format.dateFormat = @"yyyy-MM-dd"; - NSDate *expectedDate = [format dateFromString:[externalRepresentation objectForKey:@"created_at"]]; - [[car.createdAt should] equal:expectedDate]; + }); }); - }); + context(@"with hasOne mapping", ^{ + __block Person *person; + __block Car *expectedCar; - context(@"with hasOne mapping", ^{ - __block Person *person; - __block Car *expectedCar; + beforeEach(^{ + expectedCar = [Car MR_createEntity]; + expectedCar.model = @"i30"; + expectedCar.year = @"2013"; - beforeEach(^{ - expectedCar = [Car MR_createEntity]; - expectedCar.model = @"i30"; - expectedCar.year = @"2013"; - - NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; - }); + NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider personMapping] + context:moc]; + }); - specify(^{ - [person.car shouldNotBeNil]; - }); + specify(^{ + [person.car shouldNotBeNil]; + }); + + specify(^{ + [[person.car.model should] equal:expectedCar.model]; + }); + + specify(^{ + [[person.car.year should] equal:expectedCar.year]; + }); - specify(^{ - [[person.car.model should] equal:expectedCar.model]; }); - specify(^{ - [[person.car.year should] equal:expectedCar.year]; + context(@"with hasMany mapping", ^{ + __block Person *person; + + beforeEach(^{ + moc = [NSManagedObjectContext MR_defaultContext]; + NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProvider personMapping] + context:moc]; + }); + + specify(^{ + [person.phones shouldNotBeNil]; + }); + + specify(^{ + [[person.phones should] haveCountOf:2]; + }); + }); }); - context(@"with hasMany mapping", ^{ - __block Person *person; + describe(@".deserializeCollectionExternalRepresentation:usingmapping:", ^{ + __block NSArray *carsArray; + __block NSArray *externalRepresentation; beforeEach(^{ - moc = [NSManagedObjectContext MR_defaultContext]; - NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Person"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:moc]; + externalRepresentation = [CMFixture buildUsingFixture:@"Cars"]; + carsArray = [FEMDeserializer collectionFromRepresentation:externalRepresentation + mapping:[MappingProvider carMapping] + context:moc]; }); specify(^{ - [person.phones shouldNotBeNil]; + [carsArray shouldNotBeNil]; }); specify(^{ - [[person.phones should] haveCountOf:2]; + [[carsArray should] haveCountOf:[externalRepresentation count]]; }); }); - }); + describe(@"null relationship", ^{ + __block Person *person = nil; - describe(@".deserializeCollectionExternalRepresentation:usingusingMapping:", ^{ - __block NSArray *carsArray; - __block NSArray *externalRepresentation; + beforeAll(^{ + NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; + FEMMapping *mapping = [MappingProvider personMapping]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation mapping:mapping context:moc]; + }); - beforeEach(^{ - externalRepresentation = [CMFixture buildUsingFixture:@"Cars"]; - carsArray = [FEMDeserializer deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; - }); + context(@"to-one", ^{ + it(@"it should be nil", ^{ + [[person.car should] beNil]; + }); + }); - specify(^{ - [carsArray shouldNotBeNil]; + context(@"to-many", ^{ + it(@"it should be empty", ^{ + [[person.phones should] beNil]; + }); + }); }); - specify(^{ - [[carsArray should] haveCountOf:[externalRepresentation count]]; - }); + describe(@"relationship assignment policy", ^{ + __block NSDictionary *externalRepresentation_v1 = nil; + __block NSDictionary *externalRepresentation_v2 = nil; + __block FEMMapping *mapping = nil; + __block FEMRelationship *relationshipMapping = nil; + + context(@"to-one", ^{ + beforeEach(^{ + externalRepresentation_v1 = [CMFixture buildUsingFixture:@"PersonWithCar_1"]; + externalRepresentation_v2 = [CMFixture buildUsingFixture:@"PersonWithCar_2"]; + mapping = [MappingProvider personWithCarMapping]; + relationshipMapping = [mapping relationshipForProperty:@"car"]; + }); - }); + afterEach(^{ + externalRepresentation_v1 = nil; + externalRepresentation_v2 = nil; + mapping = nil; + relationshipMapping = nil; + }); - describe(@"null relationship", ^{ - __block Person *person = nil; + context(@"assign", ^{ + it(@"should assign new value", ^{ + relationshipMapping.assignmentPolicy = FEMAssignmentPolicyAssign; - beforeAll(^{ - NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithMissingRelationships"]; - FEMMapping *mapping = [MappingProvider personMapping]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation usingMapping:mapping context:moc]; - }); - - context(@"to-one", ^{ - it(@"it should be nil", ^{ - [[person.car should] beNil]; - }); - }); + [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; + Person *person_v1 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; + [moc MR_saveToPersistentStoreAndWait]; - context(@"to-many", ^{ - it(@"it should be empty", ^{ - [[person.phones should] beNil]; - }); - }); - }); + [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - describe(@"relationship assignment policy", ^{ - __block NSDictionary *externalRepresentation_v1 = nil; - __block NSDictionary *externalRepresentation_v2 = nil; - __block FEMMapping *mapping = nil; - __block FEMRelationship *relationshipMapping = nil; - - context(@"to-one", ^{ - beforeEach(^{ - externalRepresentation_v1 = [CMFixture buildUsingFixture:@"PersonWithCar_1"]; - externalRepresentation_v2 = [CMFixture buildUsingFixture:@"PersonWithCar_2"]; - mapping = [MappingProvider personWithCarMapping]; - relationshipMapping = [mapping relationshipForProperty:@"car"]; - }); - - afterEach(^{ - externalRepresentation_v1 = nil; - externalRepresentation_v2 = nil; - mapping = nil; - relationshipMapping = nil; - }); - - context(@"assign", ^{ - it(@"should assign new value", ^{ - relationshipMapping.assignmentPolicy = FEMAssignmentPolicyAssign; - - [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; - [moc MR_saveToPersistentStoreAndWait]; - - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - - Car *car_v1 = person_v1.car; - [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - - Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; - - [[person_v1 should] equal:person_v2]; - Car *car_v2 = person_v1.car; - - [[car_v1 shouldNot] equal:car_v2]; - [[car_v1.person should] beNil]; + Car *car_v1 = person_v1.car; + [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; + + Person *person_v2 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v2 + mapping:mapping + context:moc]; + + [[person_v1 should] equal:person_v2]; + Car *car_v2 = person_v1.car; + + [[car_v1 shouldNot] equal:car_v2]; + [[car_v1.person should] beNil]; + }); }); - }); - - context(@"merge", ^{ - it(@"should act as assign", ^{ - relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectMerge; - - [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; - [moc MR_saveToPersistentStoreAndWait]; - - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - - Car *car_v1 = person_v1.car; - [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; - - Person *person_v2 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v2 - usingMapping:mapping - context:moc]; - [moc MR_saveToPersistentStoreAndWait]; - - [[person_v1 should] equal:person_v2]; - Car *car_v2 = person_v1.car; - - [[car_v1 shouldNot] equal:car_v2]; - [[car_v1.person should] beNil]; + + context(@"merge", ^{ + it(@"should act as assign", ^{ + relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectMerge; + + [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; + Person *person_v1 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; + [moc MR_saveToPersistentStoreAndWait]; + + [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; + + Car *car_v1 = person_v1.car; + [[car_v1 should] equal:[Car MR_findFirstInContext:moc]]; + + Person *person_v2 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v2 + mapping:mapping + context:moc]; + [moc MR_saveToPersistentStoreAndWait]; + + [[person_v1 should] equal:person_v2]; + Car *car_v2 = person_v1.car; + + [[car_v1 shouldNot] equal:car_v2]; + [[car_v1.person should] beNil]; + }); }); - }); - context(@"replace", ^{ - it(@"should not replace equal object", ^{ - relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectReplace; + context(@"replace", ^{ + it(@"should not replace equal object", ^{ + relationshipMapping.assignmentPolicy = FEMAssignmentPolicyObjectReplace; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; - Car *car_v1 = person_v1.car; + [[@([Car MR_countOfEntitiesWithContext:moc]) should] beZero]; + Person *person_v1 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; + Car *car_v1 = person_v1.car; - [moc MR_saveToPersistentStoreAndWait]; + [moc MR_saveToPersistentStoreAndWait]; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; + [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - [FEMDeserializer fillObject:person_v1 - fromRepresentation:externalRepresentation_v1 - mapping:mapping]; - [moc MR_saveToPersistentStoreAndWait]; - [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; + [FEMDeserializer fillObject:person_v1 + fromRepresentation:externalRepresentation_v1 + mapping:mapping]; + [moc MR_saveToPersistentStoreAndWait]; + [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; - [[person_v1.car should] equal:car_v1]; + [[person_v1.car should] equal:car_v1]; + }); }); }); - }); - context(@"to-many", ^{ - beforeEach(^{ - externalRepresentation_v1 = [CMFixture buildUsingFixture:@"Person_1"]; - externalRepresentation_v2 = [CMFixture buildUsingFixture:@"Person_2"]; - mapping = [MappingProvider personWithPhoneMapping]; - relationshipMapping = [mapping relationshipForProperty:@"phones"]; - }); - - afterEach(^{ - externalRepresentation_v1 = nil; - externalRepresentation_v2 = nil; - mapping = nil; - relationshipMapping = nil; - }); - - context(@"merge", ^{ - it(@"should merge existing and new objects", ^{ - relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionMerge; - - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; - [moc MR_saveToPersistentStoreAndWait]; - - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; - - NSSet *phones_1 = person_v1.phones; - [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - - [FEMDeserializer fillObject:person_v1 - fromRepresentation:externalRepresentation_v2 - mapping:mapping]; - [moc MR_saveToPersistentStoreAndWait]; - - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@3]; + context(@"to-many", ^{ + beforeEach(^{ + externalRepresentation_v1 = [CMFixture buildUsingFixture:@"Person_1"]; + externalRepresentation_v2 = [CMFixture buildUsingFixture:@"Person_2"]; + mapping = [MappingProvider personWithPhoneMapping]; + relationshipMapping = [mapping relationshipForProperty:@"phones"]; + }); - [[@([phones_1 isSubsetOfSet:person_v1.phones]) should] beTrue]; + afterEach(^{ + externalRepresentation_v1 = nil; + externalRepresentation_v2 = nil; + mapping = nil; + relationshipMapping = nil; }); - }); - - context(@"replace", ^{ - it(@"should delete existing and assign new objects", ^{ - relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionReplace; - - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; - Person *person_v1 = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation_v1 - usingMapping:mapping - context:moc]; - [moc MR_saveToPersistentStoreAndWait]; - - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; - - NSSet *phones_1 = person_v1.phones; - [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; - - [FEMDeserializer fillObject:person_v1 - fromRepresentation:externalRepresentation_v2 - mapping:mapping]; - [moc MR_saveToPersistentStoreAndWait]; - [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; + context(@"merge", ^{ + it(@"should merge existing and new objects", ^{ + relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionMerge; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; + Person *person_v1 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; + [moc MR_saveToPersistentStoreAndWait]; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; + + NSSet *phones_1 = person_v1.phones; + [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; + + [FEMDeserializer fillObject:person_v1 + fromRepresentation:externalRepresentation_v2 + mapping:mapping]; + [moc MR_saveToPersistentStoreAndWait]; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@3]; + + [[@([phones_1 isSubsetOfSet:person_v1.phones]) should] beTrue]; + }); + }); + + context(@"replace", ^{ + it(@"should delete existing and assign new objects", ^{ + relationshipMapping.assignmentPolicy = FEMAssignmentPolicyCollectionReplace; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] beZero]; + Person *person_v1 = [FEMDeserializer objectFromRepresentation:externalRepresentation_v1 + mapping:mapping + context:moc]; + [moc MR_saveToPersistentStoreAndWait]; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; + + NSSet *phones_1 = person_v1.phones; + [[@([phones_1 isEqualToSet:[NSSet setWithArray:[Phone MR_findAllInContext:moc]]]) should] beTrue]; + + [FEMDeserializer fillObject:person_v1 + fromRepresentation:externalRepresentation_v2 + mapping:mapping]; + [moc MR_saveToPersistentStoreAndWait]; + + [[@([Phone MR_countOfEntitiesWithContext:moc]) should] equal:@2]; + }); }); }); }); - }); // describe(@"synchronization", ^{ // __block Car *car; @@ -517,7 +517,7 @@ // [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; // // [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] -// usingMapping:mapping +// mapping:mapping // predicate:nil // context:moc]; // [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -532,7 +532,7 @@ // // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID == 1"]; // [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] -// usingMapping:mapping +// mapping:mapping // predicate:predicate // context:moc]; // [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@1]; @@ -545,13 +545,13 @@ // // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"carID != 1"]; // [FEMDeserializer synchronizeCollectionExternalRepresentation:@[externalRepresentation] -// usingMapping:mapping +// mapping:mapping // predicate:predicate // context:moc]; // [[@([Car MR_countOfEntitiesWithContext:moc]) should] equal:@2]; // }); // }); // }); -}); + }); SPEC_END From 68034042dc6f961f9fe4db2b163ce9130f1569aa Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 13:54:26 +0300 Subject: [PATCH 66/95] Update all tests to latest syntax --- .../Specs/FEMManagedObjectMappingSpec.m | 11 ++-------- .../Specs/FEMObjectMappingSpec.m | 10 ++------- .../Specs/FEMSerializerSpec.m | 21 +++++++++---------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m index 876a010..4e9e7a0 100644 --- a/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMManagedObjectMappingSpec.m @@ -70,10 +70,7 @@ __block FEMMapping *mapping; beforeEach(^{ - mapping = [FEMMapping mappingForEntityName:@"Car" - configuration:^(FEMMapping *mapping) { - - }]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; }); specify(^{ @@ -91,11 +88,7 @@ __block FEMMapping *mapping; beforeEach(^{ - mapping = [FEMMapping mappingForEntityName:@"Car" - rootPath:@"car" - configuration:^(FEMMapping *mapping) { - - }]; + mapping = [[FEMMapping alloc] initWithEntityName:@"Car" rootPath:@"car"]; }); specify(^{ diff --git a/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m b/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m index f842a44..cc75501 100644 --- a/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m +++ b/FastEasyMappingTests/Specs/FEMObjectMappingSpec.m @@ -18,9 +18,7 @@ __block FEMObjectMapping *mapping; beforeEach(^{ - mapping = [FEMObjectMapping mappingForClass:[CarNative class] configuration:^(FEMObjectMapping *mapping) { - - }]; + mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class]]; }); specify(^{ @@ -38,11 +36,7 @@ __block FEMObjectMapping *mapping; beforeEach(^{ - mapping = [FEMObjectMapping mappingForClass:[CarNative class] - rootPath:@"car" - configuration:^(FEMObjectMapping *mapping) { - - }]; + mapping = [[FEMMapping alloc] initWithObjectClass:[CarNative class] rootPath:@"car"]; }); specify(^{ diff --git a/FastEasyMappingTests/Specs/FEMSerializerSpec.m b/FastEasyMappingTests/Specs/FEMSerializerSpec.m index 23e8913..eb2129c 100644 --- a/FastEasyMappingTests/Specs/FEMSerializerSpec.m +++ b/FastEasyMappingTests/Specs/FEMSerializerSpec.m @@ -308,8 +308,8 @@ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:mapping]; representation = [FEMSerializer serializeObject:person usingMapping:mapping]; }); @@ -354,7 +354,7 @@ }]; person = [factory build]; representation = [FEMSerializer serializeObject:person - usingMapping:[MappingProviderNative personWithPhonesMapping]]; + usingMapping:[MappingProviderNative personWithPhonesMapping]]; }); @@ -380,8 +380,8 @@ keyPath:@"cellphones"]; NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"PersonWithDifferentNaming"]; - person = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:mapping]; + person = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:mapping]; representation = [FEMSerializer serializeObject:person usingMapping:mapping]; }); @@ -414,10 +414,9 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"Native"]; - native = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative nativeMapping]]; - representation = [FEMSerializer serializeObject:native - usingMapping:[MappingProviderNative nativeMapping]]; + native = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative nativeMapping]]; + representation = [FEMSerializer serializeObject:native usingMapping:[MappingProviderNative nativeMapping]]; }); specify(^{ @@ -508,8 +507,8 @@ beforeEach(^{ NSDictionary *externalRepresentation = [CMFixture buildUsingFixture:@"NativeChild"]; - nativeChild = [FEMDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProviderNative nativeChildMapping]]; + nativeChild = [FEMDeserializer objectFromRepresentation:externalRepresentation + mapping:[MappingProviderNative nativeChildMapping]]; representation = [FEMSerializer serializeObject:nativeChild usingMapping:[MappingProviderNative nativeChildMapping]]; }); From 0327197fa987648107f18108ae1c9d16c8b544be Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 16:18:32 +0300 Subject: [PATCH 67/95] Add missing headers --- FastEasyMapping.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index d4afdf7..1a85a54 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -87,6 +87,9 @@ AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; + AD4E3A5F1B909710007D5511 /* FEMManagedObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; + AD4E3A601B909710007D5511 /* FEMExcludableCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */; settings = {ATTRIBUTES = (Private, ); }; }; + AD4E3A611B909710007D5511 /* FEMMergeableCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */; settings = {ATTRIBUTES = (Private, ); }; }; AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF791B03657900E46915 /* FEMManagedObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = AD52DF7B1B03657900E46915 /* FEMObjectDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD52DF821B03865000E46915 /* FEMManagedObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */; }; @@ -614,6 +617,7 @@ 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */, AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, + AD4E3A5F1B909710007D5511 /* FEMManagedObjectStore.h in Headers */, 69ED7E8934131F087C5492A3 /* FEMManagedObjectCache.h in Headers */, 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */, 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */, @@ -623,6 +627,8 @@ 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */, 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */, 69ED72338B6419101B1C8CDB /* NSObject+FEMKVCExtension.h in Headers */, + AD4E3A601B909710007D5511 /* FEMExcludableCollection.h in Headers */, + AD4E3A611B909710007D5511 /* FEMMergeableCollection.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */, ); From 4318a7980477fb49393dff40339b2fc7fc01997f Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 16:33:24 +0300 Subject: [PATCH 68/95] Remove FEMAttribute extension --- FastEasyMapping.xcodeproj/project.pbxproj | 96 +++++++------------ .../Source/Core/Cache/FEMManagedObjectCache.m | 2 +- .../Core/Deserializer/FEMDeserializer.m | 16 +++- .../Attribute/FEMAttribute+Extension.h | 11 --- .../Attribute/FEMAttribute+Extension.m | 26 ----- .../Mapping/{Attribute => }/FEMAttribute.h | 0 .../Mapping/{Attribute => }/FEMAttribute.m | 0 .../{Object => }/FEMManagedObjectMapping.h | 0 .../Core/Mapping/{Object => }/FEMMapping.h | 0 .../Core/Mapping/{Object => }/FEMMapping.m | 0 .../Mapping/{Object => }/FEMObjectMapping.h | 0 .../{Relationship => }/FEMRelationship.h | 0 .../{Relationship => }/FEMRelationship.m | 0 .../Source/Utility/FEMMappingUtility.h | 5 +- .../Source/Utility/FEMMappingUtility.m | 6 ++ .../Source/Utility/FEMRepresentationUtility.m | 3 +- 16 files changed, 58 insertions(+), 107 deletions(-) delete mode 100644 FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.h delete mode 100644 FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.m rename FastEasyMapping/Source/Core/Mapping/{Attribute => }/FEMAttribute.h (100%) rename FastEasyMapping/Source/Core/Mapping/{Attribute => }/FEMAttribute.m (100%) rename FastEasyMapping/Source/Core/Mapping/{Object => }/FEMManagedObjectMapping.h (100%) rename FastEasyMapping/Source/Core/Mapping/{Object => }/FEMMapping.h (100%) rename FastEasyMapping/Source/Core/Mapping/{Object => }/FEMMapping.m (100%) rename FastEasyMapping/Source/Core/Mapping/{Object => }/FEMObjectMapping.h (100%) rename FastEasyMapping/Source/Core/Mapping/{Relationship => }/FEMRelationship.h (100%) rename FastEasyMapping/Source/Core/Mapping/{Relationship => }/FEMRelationship.m (100%) diff --git a/FastEasyMapping.xcodeproj/project.pbxproj b/FastEasyMapping.xcodeproj/project.pbxproj index 1a85a54..5de9b4c 100644 --- a/FastEasyMapping.xcodeproj/project.pbxproj +++ b/FastEasyMapping.xcodeproj/project.pbxproj @@ -7,25 +7,30 @@ objects = { /* Begin PBXBuildFile section */ + 1D6A302A3D95B8A0913B335C /* FEMObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3F8FD0F112B4BA9380FE /* FEMObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A30748FCFC86CFA72493D /* FEMObjectStore.m */; }; - 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A348952AF3C9B329FC208 /* FEMMapping.m */; }; 1D6A324055B27F52CF7B8719 /* Person_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A31C3D577329518B3E664 /* Person_1.json */; }; 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1D6A348584F61C3260854CE2 /* FEMMappingUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A34C84E523B5F58F87C5E /* PersonWithMissingRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */; }; + 1D6A364F0E2FE974D31C49B9 /* FEMRelationship.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3F0C9AE4FD7FC200D09F /* FEMRelationship.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A368456D992002FA3C6A9 /* FEMRepresentationUtility.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 1D6A369BDB69900A3774C427 /* FEMAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32731DF0CE9F69F54AE4 /* FEMAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A370F588D1C2F011CAAD0 /* PersonWithCar_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */; }; + 1D6A37A1CE12DEB217C99911 /* FEMManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3E335535878DA801854C /* FEMManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 1D6A3814C824D2128E3A043A /* FEMMapping.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3B87ABEBEDD845682F62 /* FEMMapping.m */; }; 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */; }; - 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3500E1995CD83C02D364 /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A38BAA53A46E856AF5CC4 /* FEMRelationshipAssignmentContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A3B04DDB373C1542E785F /* PersonWithNullRelationships.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3A47A8DEF276ECDCDF46 /* PersonWithNullRelationships.json */; }; 1D6A3BB7C54CCCC7720A793A /* FEMObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 1D6A3BC1A08D550FFFF3E9A5 /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3C63218EDC50D1C848E3 /* FEMAttribute.m */; }; + 1D6A3D2F519049D3E97895A9 /* FEMMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3DB6E70D06B240357965 /* FEMMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1D6A3D32342A71CC6BCA3855 /* Person_2.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3ACBBC8E66609F169E94 /* Person_2.json */; }; + 1D6A3E950CAD3D0A01F2C1B3 /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3EDB0333D6F8C6AF1C22 /* FEMRelationship.m */; }; 1D6A3EB013A2AC7B8B7B69CE /* PersonWithCar_1.json in Resources */ = {isa = PBXBuildFile; fileRef = 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */; }; 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */; }; 1D6A3FFE3771AC234D28EA4D /* FEMMappingUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3A4F887B37995524457E /* FEMMappingUtility.m */; }; - 2C11898E18D07356005D8D91 /* FEMManagedObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2C375F1318CCD3FB00FCB8EA /* EasyMappingCoreDataExample.xcdatamodel in Sources */ = {isa = PBXBuildFile; fileRef = 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */; }; 2C375F1418CCD3FB00FCB8EA /* Car.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED767EE6E89A487714CDF8 /* Car.m */; }; 2C375F1518CCD3FB00FCB8EA /* Phone.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED75A1803E4FA721E79895 /* Phone.m */; }; @@ -62,14 +67,10 @@ 2CF8098B18C3AD5700C07899 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CF8097B18C3AD5700C07899 /* Foundation.framework */; }; 2CF8098D18C3AD5700C07899 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CF8098C18C3AD5700C07899 /* UIKit.framework */; }; 2CF8099018C3AD5700C07899 /* libFastEasyMapping.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2CF8097818C3AD5700C07899 /* libFastEasyMapping.a */; }; - 2CF809A318C3AE9A00C07899 /* FEMObjectMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED70753A27735A60785078 /* FEMObjectMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 2CF809A418C3AE9A00C07899 /* FEMAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED724125F45703B27BFC0C /* FEMAttribute.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 2CF809A518C3AE9A00C07899 /* FEMRelationship.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1A1592194E312212F9 /* FEMRelationship.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7C1B2AB96554F9FDF10B /* FEMSerializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED771F4A0CC2BB6D9583BC /* FEMDeserializer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AA18C3AE9A00C07899 /* FastEasyMapping.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED77A829DD1436A5A2CA1B /* FastEasyMapping.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7A8B2E60F728B99A0CB9 /* FEMTypes.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AD18C3AEC800C07899 /* NSArray+FEMPropertyRepresentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7645386941DA79C1E53A /* NSArray+FEMPropertyRepresentation.h */; settings = {ATTRIBUTES = (Private, ); }; }; 2CF809AF18C3AEC800C07899 /* FEMTypeIntrospection.h in Headers */ = {isa = PBXBuildFile; fileRef = 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */; settings = {ATTRIBUTES = (Private, ); }; }; 69ED7144E37E067666813AF9 /* NSArray+FEMPropertyRepresentation.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757059F6C7A26468D880 /* NSArray+FEMPropertyRepresentation.m */; }; @@ -84,9 +85,6 @@ 9983A129111A4AB8A30520BE /* libPods-FastEasyMappingTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */; }; AD11B5EC1B038E8700B53F5A /* FEMMergeableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */; }; AD11B5ED1B038E8900B53F5A /* FEMExcludableCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */; }; - AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED7141C706CAC006EADE5A /* FEMAttribute.m */; }; - AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED757758DA67B4E8247495 /* FEMRelationship.m */; }; - AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */; }; AD4E3A5F1B909710007D5511 /* FEMManagedObjectStore.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A311D0B99D619E11B0641 /* FEMManagedObjectStore.h */; settings = {ATTRIBUTES = (Public, ); }; }; AD4E3A601B909710007D5511 /* FEMExcludableCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */; settings = {ATTRIBUTES = (Private, ); }; }; AD4E3A611B909710007D5511 /* FEMMergeableCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */; settings = {ATTRIBUTES = (Private, ); }; }; @@ -132,15 +130,14 @@ 1D6A31C3D577329518B3E664 /* Person_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_1.json; sourceTree = ""; }; 1D6A31CC30FC2DC11994EBA8 /* FEMRelationshipAssignmentContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRelationshipAssignmentContext.m; sourceTree = ""; }; 1D6A32164D7EFFBC35F34F17 /* FEMManagedObjectStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectStore.m; sourceTree = ""; }; + 1D6A32731DF0CE9F69F54AE4 /* FEMAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttribute.h; sourceTree = ""; }; 1D6A328FCE22411C60FBC7C4 /* FEMRepresentationUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRepresentationUtility.m; sourceTree = ""; }; 1D6A32B1909842797CD2E0D3 /* FEMObjectStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectStore.h; sourceTree = ""; }; 1D6A334CB9A14401554BDA18 /* FEMAttributeMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttributeMappingSpec.m; sourceTree = ""; }; 1D6A33C793CC8D51633186DC /* FEMMergeableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMergeableCollection.m; sourceTree = ""; }; 1D6A3466BDE4D4241DCB93D3 /* PersonWithCar_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_2.json; sourceTree = ""; }; 1D6A34832F9D9655B8006CA7 /* PersonWithMissingRelationships.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithMissingRelationships.json; sourceTree = ""; }; - 1D6A348952AF3C9B329FC208 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; 1D6A34B621512A2FE61ECE26 /* FEMMappingUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMappingUtility.h; sourceTree = ""; }; - 1D6A3500E1995CD83C02D364 /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; 1D6A368ADA05F6A09F22A3AC /* FEMMergeableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMergeableCollection.h; sourceTree = ""; }; 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMProperty.h; sourceTree = ""; }; 1D6A37E108D6B12FA8587FA6 /* FEMRelationshipAssignmentContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationshipAssignmentContext.h; sourceTree = ""; }; @@ -149,12 +146,19 @@ 1D6A3A4F887B37995524457E /* FEMMappingUtility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMappingUtility.m; sourceTree = ""; }; 1D6A3ACBBC8E66609F169E94 /* Person_2.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Person_2.json; sourceTree = ""; }; 1D6A3AF6BD6EABAAACD8D4B8 /* FEMExcludableCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMExcludableCollection.h; sourceTree = ""; }; + 1D6A3B87ABEBEDD845682F62 /* FEMMapping.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMMapping.m; sourceTree = ""; }; 1D6A3BDA3CA0DDFF256CDB49 /* FEMExcludableCollection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMExcludableCollection.m; sourceTree = ""; }; 1D6A3C137E92421E8D0A5E41 /* FEMAssignmentPolicy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAssignmentPolicy.m; sourceTree = ""; }; + 1D6A3C63218EDC50D1C848E3 /* FEMAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttribute.m; sourceTree = ""; }; + 1D6A3DB6E70D06B240357965 /* FEMMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMMapping.h; sourceTree = ""; }; 1D6A3E2CCF90DF3444D0707E /* PersonWithCar_1.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = PersonWithCar_1.json; sourceTree = ""; }; + 1D6A3E335535878DA801854C /* FEMManagedObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectMapping.h; sourceTree = ""; }; 1D6A3E68C0FB99F7A73DE0C5 /* FEMAssignmentPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAssignmentPolicy.h; sourceTree = ""; }; 1D6A3E939A8527DF07B8E6EB /* FEMRelationshipAssignmentContext+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FEMRelationshipAssignmentContext+Internal.h"; sourceTree = ""; }; 1D6A3E942488A7A8C0C01C0C /* FEMRepresentationUtility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRepresentationUtility.h; sourceTree = ""; }; + 1D6A3EDB0333D6F8C6AF1C22 /* FEMRelationship.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRelationship.m; sourceTree = ""; }; + 1D6A3F0C9AE4FD7FC200D09F /* FEMRelationship.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationship.h; sourceTree = ""; }; + 1D6A3F8FD0F112B4BA9380FE /* FEMObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectMapping.h; sourceTree = ""; }; 29060352558D8EB5B9B013A4 /* Pods-FastEasyMappingTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FastEasyMappingTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FastEasyMappingTests/Pods-FastEasyMappingTests.debug.xcconfig"; sourceTree = ""; }; 2C375F1018CCBC2900FCB8EA /* EasyMappingCoreDataExample.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = EasyMappingCoreDataExample.xcdatamodel; sourceTree = ""; }; 2C9A6B49F30D4D58A8309D61 /* libPods-FastEasyMappingTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FastEasyMappingTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -163,17 +167,13 @@ 2CF8098818C3AD5700C07899 /* FastEasyMappingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FastEasyMappingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 2CF8098918C3AD5700C07899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 2CF8098C18C3AD5700C07899 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; - 69ED70753A27735A60785078 /* FEMObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMObjectMapping.h; sourceTree = ""; }; 69ED70F7239A59402E626302 /* Cars.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Cars.json; sourceTree = ""; }; 69ED70FD89800BB41C8894FE /* MappingProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MappingProvider.h; sourceTree = ""; }; - 69ED7141C706CAC006EADE5A /* FEMAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMAttribute.m; sourceTree = ""; }; 69ED714FF0FE4A0F2A6F5928 /* AddressNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddressNative.m; sourceTree = ""; }; 69ED7153320369C3FEB8A8F4 /* FastEasyMapping-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FastEasyMapping-Prefix.pch"; sourceTree = ""; }; 69ED71666439C5B0BC0A6650 /* CatNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CatNative.h; sourceTree = ""; }; - 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FEMAttribute+Extension.m"; sourceTree = ""; }; 69ED71A71F750AEBC8BA6FF0 /* MappingProviderNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MappingProviderNative.h; sourceTree = ""; }; 69ED7209D50C3640D4456C8D /* Plane.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Plane.json; sourceTree = ""; }; - 69ED724125F45703B27BFC0C /* FEMAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMAttribute.h; sourceTree = ""; }; 69ED73028D190C49BF2E0F8D /* FEMSerializer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMSerializer.m; sourceTree = ""; }; 69ED734D9AF0D834B3D9D190 /* CarNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CarNative.m; sourceTree = ""; }; 69ED741033C38A5C3BAA7B08 /* FingerNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FingerNative.h; sourceTree = ""; }; @@ -182,10 +182,8 @@ 69ED74EA8FEC3EC66EF72AA7 /* PlaneNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PlaneNative.m; sourceTree = ""; }; 69ED74F0986B6C6DD2614CB7 /* Car.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Car.json; sourceTree = ""; }; 69ED7532E1E5E3196BC27932 /* MappingProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MappingProvider.m; sourceTree = ""; }; - 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FEMAttribute+Extension.h"; sourceTree = ""; }; 69ED75443C8F85492C4D3907 /* SeaplaneNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeaplaneNative.h; sourceTree = ""; }; 69ED757059F6C7A26468D880 /* NSArray+FEMPropertyRepresentation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+FEMPropertyRepresentation.m"; sourceTree = ""; }; - 69ED757758DA67B4E8247495 /* FEMRelationship.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMRelationship.m; sourceTree = ""; }; 69ED758473F42E39AE484636 /* CarWithDate.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = CarWithDate.json; sourceTree = ""; }; 69ED75A1803E4FA721E79895 /* Phone.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Phone.m; sourceTree = ""; }; 69ED75B675560A0A804494CB /* FEMSerializerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMSerializerSpec.m; sourceTree = ""; }; @@ -220,7 +218,6 @@ 69ED7BBE657BC5F333DD5560 /* CarWithNestedAttributes.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = CarWithNestedAttributes.json; sourceTree = ""; }; 69ED7C04E2BE02B24CFA1D7C /* FEMManagedObjectMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectMappingSpec.m; sourceTree = ""; }; 69ED7C0B46A2C9AC90B37710 /* PersonNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PersonNative.m; sourceTree = ""; }; - 69ED7C1A1592194E312212F9 /* FEMRelationship.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMRelationship.h; sourceTree = ""; }; 69ED7C1B06B95B6C90EBB53A /* FEMManagedObjectDeserializerSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMManagedObjectDeserializerSpec.m; sourceTree = ""; }; 69ED7C1B2AB96554F9FDF10B /* FEMSerializer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMSerializer.h; sourceTree = ""; }; 69ED7CB8A80C99BF8D7413F6 /* FastEasyMappingTests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.info; path = "FastEasyMappingTests-Info.plist"; sourceTree = ""; }; @@ -233,7 +230,6 @@ 69ED7E6CB1B484C7F335B55F /* FEMTypeIntrospection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMTypeIntrospection.h; sourceTree = ""; }; 69ED7E718033F733C45E7416 /* Phone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Phone.h; sourceTree = ""; }; 69ED7E9D5D47846FEFCA62F5 /* FingerNative.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FingerNative.m; sourceTree = ""; }; - 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FEMManagedObjectMapping.h; sourceTree = ""; }; 69ED7EC086EF5CE3263C6D8D /* FEMObjectMappingSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMObjectMappingSpec.m; sourceTree = ""; }; 69ED7EC1199D47734B9812E7 /* Alien.json */ = {isa = PBXFileReference; lastKnownFileType = file.json; path = Alien.json; sourceTree = ""; }; 69ED7F5DB5E0C3FF6672226E /* FEMTypeIntrospection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FEMTypeIntrospection.m; sourceTree = ""; }; @@ -469,15 +465,6 @@ path = Core; sourceTree = ""; }; - 69ED74A3F93755AF6DBD3662 /* Relationship */ = { - isa = PBXGroup; - children = ( - 69ED7C1A1592194E312212F9 /* FEMRelationship.h */, - 69ED757758DA67B4E8247495 /* FEMRelationship.m */, - ); - path = Relationship; - sourceTree = ""; - }; 69ED752D2981B7C6882366D2 /* Foundation */ = { isa = PBXGroup; children = ( @@ -492,10 +479,15 @@ 69ED7574EDCD21D0E501C8A1 /* Mapping */ = { isa = PBXGroup; children = ( - 69ED7C716C176C89DA2C9636 /* Object */, - 69ED7C6CCD04878CED1E5BAE /* Attribute */, - 69ED74A3F93755AF6DBD3662 /* Relationship */, 1D6A3781CA28E31A3CDCE626 /* FEMProperty.h */, + 1D6A3DB6E70D06B240357965 /* FEMMapping.h */, + 1D6A3E335535878DA801854C /* FEMManagedObjectMapping.h */, + 1D6A3F8FD0F112B4BA9380FE /* FEMObjectMapping.h */, + 1D6A3B87ABEBEDD845682F62 /* FEMMapping.m */, + 1D6A32731DF0CE9F69F54AE4 /* FEMAttribute.h */, + 1D6A3C63218EDC50D1C848E3 /* FEMAttribute.m */, + 1D6A3EDB0333D6F8C6AF1C22 /* FEMRelationship.m */, + 1D6A3F0C9AE4FD7FC200D09F /* FEMRelationship.h */, ); path = Mapping; sourceTree = ""; @@ -547,28 +539,6 @@ path = Source; sourceTree = ""; }; - 69ED7C6CCD04878CED1E5BAE /* Attribute */ = { - isa = PBXGroup; - children = ( - 69ED724125F45703B27BFC0C /* FEMAttribute.h */, - 69ED7141C706CAC006EADE5A /* FEMAttribute.m */, - 69ED7539B5509DF9599396EA /* FEMAttribute+Extension.h */, - 69ED718D4E6F950EE17E08C6 /* FEMAttribute+Extension.m */, - ); - path = Attribute; - sourceTree = ""; - }; - 69ED7C716C176C89DA2C9636 /* Object */ = { - isa = PBXGroup; - children = ( - 69ED70753A27735A60785078 /* FEMObjectMapping.h */, - 69ED7EA48925307F4DB06848 /* FEMManagedObjectMapping.h */, - 1D6A348952AF3C9B329FC208 /* FEMMapping.m */, - 1D6A3500E1995CD83C02D364 /* FEMMapping.h */, - ); - path = Object; - sourceTree = ""; - }; 69ED7C8732A1C26BF1CF78CD /* Deserializer */ = { isa = PBXGroup; children = ( @@ -605,16 +575,11 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 2C11898E18D07356005D8D91 /* FEMManagedObjectMapping.h in Headers */, 2CF809AA18C3AE9A00C07899 /* FastEasyMapping.h in Headers */, - 2CF809A318C3AE9A00C07899 /* FEMObjectMapping.h in Headers */, - 2CF809A418C3AE9A00C07899 /* FEMAttribute.h in Headers */, - 2CF809A518C3AE9A00C07899 /* FEMRelationship.h in Headers */, 2CF809A618C3AE9A00C07899 /* FEMSerializer.h in Headers */, 2CF809A918C3AE9A00C07899 /* FEMDeserializer.h in Headers */, AD52DF7D1B03657900E46915 /* FEMManagedObjectDeserializer.h in Headers */, 2CF809AB18C3AE9A00C07899 /* FEMTypes.h in Headers */, - 2CF809AC18C3AEC800C07899 /* FEMAttribute+Extension.h in Headers */, AD52DF7F1B03657900E46915 /* FEMObjectDeserializer.h in Headers */, 1D6A369BF512C6E71C26FBF0 /* FEMProperty.h in Headers */, AD4E3A5F1B909710007D5511 /* FEMManagedObjectStore.h in Headers */, @@ -630,7 +595,11 @@ AD4E3A601B909710007D5511 /* FEMExcludableCollection.h in Headers */, AD4E3A611B909710007D5511 /* FEMMergeableCollection.h in Headers */, 1D6A344F5FF5B8AD3E1FDC04 /* FEMRelationshipAssignmentContext+Internal.h in Headers */, - 1D6A38364CB754F0BEE49D24 /* FEMMapping.h in Headers */, + 1D6A3D2F519049D3E97895A9 /* FEMMapping.h in Headers */, + 1D6A37A1CE12DEB217C99911 /* FEMManagedObjectMapping.h in Headers */, + 1D6A302A3D95B8A0913B335C /* FEMObjectMapping.h in Headers */, + 1D6A369BDB69900A3774C427 /* FEMAttribute.h in Headers */, + 1D6A364F0E2FE974D31C49B9 /* FEMRelationship.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -741,9 +710,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - AD308A781B023E6C00B03F6A /* FEMAttribute.m in Sources */, - AD308A7A1B023E6C00B03F6A /* FEMAttribute+Extension.m in Sources */, - AD308A791B023E6C00B03F6A /* FEMRelationship.m in Sources */, 69ED797C93C27C8E3BBC1BDB /* FEMSerializer.m in Sources */, 69ED7DADB8044F2B42C1CD94 /* FEMDeserializer.m in Sources */, AD52DF821B03865000E46915 /* FEMManagedObjectStore.m in Sources */, @@ -757,8 +723,10 @@ 1D6A30D09CC7C04D4C0E8FAC /* FEMObjectStore.m in Sources */, 1D6A3FE5C05F54B80DCD6D93 /* FEMRepresentationUtility.m in Sources */, 1D6A3821F8D06660ABDEE560 /* FEMRelationshipAssignmentContext.m in Sources */, - 1D6A316DBA47161814A2E1D8 /* FEMMapping.m in Sources */, 1D6A3FFE3771AC234D28EA4D /* FEMMappingUtility.m in Sources */, + 1D6A3814C824D2128E3A043A /* FEMMapping.m in Sources */, + 1D6A3BC1A08D550FFFF3E9A5 /* FEMAttribute.m in Sources */, + 1D6A3E950CAD3D0A01F2C1B3 /* FEMRelationship.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index 90982a0..a0d9ca8 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -69,7 +69,7 @@ - (NSMutableDictionary *)cachedObjectsForMapping:(FEMMapping *)mapping { - (id)existingObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { NSDictionary *entityObjectsMap = [self cachedObjectsForMapping:mapping]; - id primaryKeyValue = [mapping.primaryKeyAttribute mappedValueFromRepresentation:representation]; + id primaryKeyValue = FEMAttributeMappedValueFromRepresentation(mapping.primaryKeyAttribute, representation); if (primaryKeyValue == nil || primaryKeyValue == NSNull.null) return nil; return entityObjectsMap[primaryKeyValue]; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 6caae93..1ab1ab8 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -6,11 +6,12 @@ #import "FEMTypeIntrospection.h" #import "NSArray+FEMPropertyRepresentation.h" -#import "FEMAttribute+Extension.h" #import "FEMObjectStore.h" #import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" #import "FEMManagedObjectStore.h" +#import "FEMMappingUtility.h" +#import "NSObject+FEMKVCExtension.h" @implementation FEMDeserializer { struct { @@ -80,9 +81,20 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } } +- (void)setAttributeValue:(FEMAttribute *)attribute onObject:(id)object fromRepresentation:(id)representation { + id value = FEMAttributeMappedValueFromRepresentation(attribute, representation); + if (value == NSNull.null) { + if (!FEMObjectPropertyTypeIsScalar(object, attribute.property)) { + [object setValue:nil forKey:attribute.property]; + } + } else if (value) { + [object fem_setValueIfDifferent:value forKey:attribute.property]; + } +} + - (id)_fillObject:(id)object fromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { for (FEMAttribute *attribute in mapping.attributes) { - [attribute setMappedValueToObject:object fromRepresentation:representation]; + [self setAttributeValue:attribute onObject:object fromRepresentation:representation]; } [self fulfillObjectRelationships:object fromRepresentation:representation usingMapping:mapping]; diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.h b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.h deleted file mode 100644 index 26317e7..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.h +++ /dev/null @@ -1,11 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import -#import "FEMAttribute.h" - -@interface FEMAttribute (Extension) - -- (id)mappedValueFromRepresentation:(id)representation; -- (void)setMappedValueToObject:(id)object fromRepresentation:(id)representation; - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.m b/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.m deleted file mode 100644 index 8c93c8c..0000000 --- a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute+Extension.m +++ /dev/null @@ -1,26 +0,0 @@ -// For License please refer to LICENSE file in the root of FastEasyMapping project - -#import "FEMAttribute+Extension.h" -#import "FEMTypeIntrospection.h" -#import "NSObject+FEMKVCExtension.h" - -@implementation FEMAttribute (Extension) - -- (id)mappedValueFromRepresentation:(id)representation { - id value = self.keyPath ? [representation valueForKeyPath:self.keyPath] : representation; - - return [self mapValue:value]; -} - -- (void)setMappedValueToObject:(id)object fromRepresentation:(id)representation { - id value = [self mappedValueFromRepresentation:representation]; - if (value == NSNull.null) { - if (!FEMObjectPropertyTypeIsScalar(object, self.property)) { - [object setValue:nil forKey:self.property]; - } - } else if (value) { - [object fem_setValueIfDifferent:value forKey:self.property]; - } -} - -@end \ No newline at end of file diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h b/FastEasyMapping/Source/Core/Mapping/FEMAttribute.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h rename to FastEasyMapping/Source/Core/Mapping/FEMAttribute.h diff --git a/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m b/FastEasyMapping/Source/Core/Mapping/FEMAttribute.m similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.m rename to FastEasyMapping/Source/Core/Mapping/FEMAttribute.m diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMManagedObjectMapping.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Object/FEMManagedObjectMapping.h rename to FastEasyMapping/Source/Core/Mapping/FEMManagedObjectMapping.h diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMMapping.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.h rename to FastEasyMapping/Source/Core/Mapping/FEMMapping.h diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m b/FastEasyMapping/Source/Core/Mapping/FEMMapping.m similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Object/FEMMapping.m rename to FastEasyMapping/Source/Core/Mapping/FEMMapping.m diff --git a/FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h b/FastEasyMapping/Source/Core/Mapping/FEMObjectMapping.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Object/FEMObjectMapping.h rename to FastEasyMapping/Source/Core/Mapping/FEMObjectMapping.h diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/FEMRelationship.h similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h rename to FastEasyMapping/Source/Core/Mapping/FEMRelationship.h diff --git a/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m b/FastEasyMapping/Source/Core/Mapping/FEMRelationship.m similarity index 100% rename from FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.m rename to FastEasyMapping/Source/Core/Mapping/FEMRelationship.m diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.h b/FastEasyMapping/Source/Utility/FEMMappingUtility.h index 5bdf76c..8b17295 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.h +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.h @@ -6,6 +6,9 @@ @import Foundation; @class FEMMapping; +@class FEMAttribute; FOUNDATION_EXTERN void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)); -FOUNDATION_EXTERN NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping); \ No newline at end of file +FOUNDATION_EXTERN NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping); + +FOUNDATION_EXTERN id FEMAttributeMappedValueFromRepresentation(FEMAttribute *attribute, id representation); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m index 9889f37..e69ee17 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.m +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -5,6 +5,7 @@ #import "FEMMappingUtility.h" #import "FEMMapping.h" +#import "FEMAttribute.h" void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { apply(mapping); @@ -23,4 +24,9 @@ void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { }); return output; +} + +id FEMAttributeMappedValueFromRepresentation(FEMAttribute *attribute, id representation) { + id value = attribute.keyPath ? [representation valueForKeyPath:attribute.keyPath] : representation; + return [attribute mapValue:value]; } \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index 72282db..df5aff9 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -6,7 +6,6 @@ #import "FEMRepresentationUtility.h" #import "FEMMapping.h" #import "FEMMappingUtility.h" -#import "FEMAttribute+Extension.h" id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { if (keyPath.length > 0) { @@ -21,7 +20,7 @@ id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { void _FEMRepresentationCollectObjectPrimaryKeys(NSDictionary *object, FEMMapping *mapping, NSDictionary *container) { if (mapping.primaryKey) { FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; - id primaryKeyValue = [primaryKeyMapping mappedValueFromRepresentation:object]; + id primaryKeyValue = FEMAttributeMappedValueFromRepresentation(primaryKeyMapping, object); if (primaryKeyValue && primaryKeyValue != NSNull.null) { NSMutableSet *set = container[mapping.entityName]; [set addObject:primaryKeyValue]; From dfd0ac5617a24253c5bcfe5f3c2a6b777cfe0bee Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 16:35:20 +0300 Subject: [PATCH 69/95] Renaming of attribute utility function --- FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m | 5 +---- .../Source/Core/Deserializer/FEMDeserializer.m | 2 +- FastEasyMapping/Source/Utility/FEMMappingUtility.h | 5 +---- FastEasyMapping/Source/Utility/FEMMappingUtility.m | 6 ------ FastEasyMapping/Source/Utility/FEMRepresentationUtility.h | 6 ++++-- FastEasyMapping/Source/Utility/FEMRepresentationUtility.m | 8 +++++++- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m index a0d9ca8..eaa44e5 100644 --- a/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m +++ b/FastEasyMapping/Source/Core/Cache/FEMManagedObjectCache.m @@ -5,10 +5,7 @@ #import #import "FEMMapping.h" -#import "FEMAttribute+Extension.h" #import "FEMRepresentationUtility.h" -#import "FEMRelationship.h" -#import "FEMMappingUtility.h" @implementation FEMManagedObjectCache { NSManagedObjectContext *_context; @@ -69,7 +66,7 @@ - (NSMutableDictionary *)cachedObjectsForMapping:(FEMMapping *)mapping { - (id)existingObjectForRepresentation:(id)representation mapping:(FEMMapping *)mapping { NSDictionary *entityObjectsMap = [self cachedObjectsForMapping:mapping]; - id primaryKeyValue = FEMAttributeMappedValueFromRepresentation(mapping.primaryKeyAttribute, representation); + id primaryKeyValue = FEMRepresentationValueForAttribute(representation, mapping.primaryKeyAttribute); if (primaryKeyValue == nil || primaryKeyValue == NSNull.null) return nil; return entityObjectsMap[primaryKeyValue]; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 1ab1ab8..b69c2c6 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -82,7 +82,7 @@ - (void)fulfillObjectRelationships:(id)object fromRepresentation:(NSDictionary * } - (void)setAttributeValue:(FEMAttribute *)attribute onObject:(id)object fromRepresentation:(id)representation { - id value = FEMAttributeMappedValueFromRepresentation(attribute, representation); + id value = FEMRepresentationValueForAttribute(representation, attribute); if (value == NSNull.null) { if (!FEMObjectPropertyTypeIsScalar(object, attribute.property)) { [object setValue:nil forKey:attribute.property]; diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.h b/FastEasyMapping/Source/Utility/FEMMappingUtility.h index 8b17295..5bdf76c 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.h +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.h @@ -6,9 +6,6 @@ @import Foundation; @class FEMMapping; -@class FEMAttribute; FOUNDATION_EXTERN void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)); -FOUNDATION_EXTERN NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping); - -FOUNDATION_EXTERN id FEMAttributeMappedValueFromRepresentation(FEMAttribute *attribute, id representation); \ No newline at end of file +FOUNDATION_EXTERN NSSet * FEMMappingCollectUsedEntityNames(FEMMapping *mapping); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMMappingUtility.m b/FastEasyMapping/Source/Utility/FEMMappingUtility.m index e69ee17..9889f37 100644 --- a/FastEasyMapping/Source/Utility/FEMMappingUtility.m +++ b/FastEasyMapping/Source/Utility/FEMMappingUtility.m @@ -5,7 +5,6 @@ #import "FEMMappingUtility.h" #import "FEMMapping.h" -#import "FEMAttribute.h" void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { apply(mapping); @@ -24,9 +23,4 @@ void FEMMappingApply(FEMMapping *mapping, void (^apply)(FEMMapping *object)) { }); return output; -} - -id FEMAttributeMappedValueFromRepresentation(FEMAttribute *attribute, id representation) { - id value = attribute.keyPath ? [representation valueForKeyPath:attribute.keyPath] : representation; - return [attribute mapValue:value]; } \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h index 7586143..8cd25f5 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.h @@ -5,8 +5,10 @@ #import +@class FEMMapping, FEMAttribute; + FOUNDATION_EXTERN id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath); -@class FEMMapping; +FOUNDATION_EXTERN NSDictionary *FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping); -FOUNDATION_EXTERN NSDictionary *FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping *mapping); \ No newline at end of file +FOUNDATION_EXTERN id FEMRepresentationValueForAttribute(id representation, FEMAttribute *attribute); \ No newline at end of file diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index df5aff9..8056679 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -6,6 +6,7 @@ #import "FEMRepresentationUtility.h" #import "FEMMapping.h" #import "FEMMappingUtility.h" +#import "FEMAttribute.h" id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { if (keyPath.length > 0) { @@ -20,7 +21,7 @@ id FEMRepresentationRootForKeyPath(id representation, NSString *keyPath) { void _FEMRepresentationCollectObjectPrimaryKeys(NSDictionary *object, FEMMapping *mapping, NSDictionary *container) { if (mapping.primaryKey) { FEMAttribute *primaryKeyMapping = mapping.primaryKeyAttribute; - id primaryKeyValue = FEMAttributeMappedValueFromRepresentation(primaryKeyMapping, object); + id primaryKeyValue = FEMRepresentationValueForAttribute(object, primaryKeyMapping); if (primaryKeyValue && primaryKeyValue != NSNull.null) { NSMutableSet *set = container[mapping.entityName]; [set addObject:primaryKeyValue]; @@ -64,4 +65,9 @@ void _FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping _FEMRepresentationCollectPresentedPrimaryKeys(root, mapping, output); return output; +} + +id FEMRepresentationValueForAttribute(id representation, FEMAttribute *attribute) { + id value = attribute.keyPath ? [representation valueForKeyPath:attribute.keyPath] : representation; + return [attribute mapValue:value]; } \ No newline at end of file From 0ce747666da7e40ed991215bc092337195812a03 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 16:38:50 +0300 Subject: [PATCH 70/95] Add private header files to podspec --- FastEasyMapping.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/FastEasyMapping.podspec b/FastEasyMapping.podspec index 75d46d4..8e528c0 100644 --- a/FastEasyMapping.podspec +++ b/FastEasyMapping.podspec @@ -13,4 +13,5 @@ Pod::Spec.new do |spec| spec.frameworks = 'CoreData' spec.source_files = 'FastEasyMapping/Source/**/*.{h,m}' + spec.private_header_files = 'FastEasyMapping/Source/Extensions/**/*.h' end From cee6fac9f37be32fafcbfa42c89d779da58c6d7f Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 16:39:58 +0300 Subject: [PATCH 71/95] Change on readme --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4840f10..43823a6 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,21 @@ It turns out, that almost all popular libraries for JSON mapping SLOW. The main FastEasyMapping

-# Setup +# Installation #### Cocoapods: ```ruby #Podfile -pod 'FastEasyMapping' +pod 'FastEasyMapping', ~> '1.0' ``` or add as a static library. +# Architecture + + + + # Usage ## Deserialization. NSManagedObject From ee74b3a19124c0204f7ac2f16f6fc967807b56e0 Mon Sep 17 00:00:00 2001 From: zen Date: Fri, 28 Aug 2015 17:45:31 +0300 Subject: [PATCH 72/95] Add intoduction to new FEM README. --- README.md | 152 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 118 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 43823a6..ee33f62 100644 --- a/README.md +++ b/README.md @@ -16,25 +16,64 @@ It turns out, that almost all popular libraries for JSON mapping SLOW. The main #### Cocoapods: ```ruby #Podfile - -pod 'FastEasyMapping', ~> '1.0' +platform :ios, '7.0' +pod 'FastEasyMapping', '~> 1.0' ``` or add as a static library. -# Architecture - - - - -# Usage -## Deserialization. NSManagedObject +## Architecture + +### Mapping + +* `FEMMapping` +* `` + - `FEMAttribute' + - `FEMRelationship` + +### Deserialization _(JSON to Object)_ +- `FEMDeserializer` + +### Serialization _(Object to JSON)_ +- `FEMSerializer` + +### Advanced Deserialization +- `FEMObjectStore` +- `FEMManagedObjectStore` +- `FEMManagedObjectCache` + +## Usage +### Deserialization + +Nowadays `NSObject` and `NSManagedObject` mapping supported out of the box. Lets take a look on how basic mapping looks like:. For example, we have JSON: + +```json +{ + "name": "Lucas", + "user_email": "lucastoc@gmail.com", + "car": { + "model": "i30", + "year": "2013" + }, + "phones": [ + { + "ddi": "55", + "ddd": "85", + "number": "1111-1111" + }, + { + "ddi": "55", + "ddd": "11", + "number": "2222-222" + } + ] +} +``` -Supose you have these classes: +and corresponding [CoreData](https://www.objc.io/issues/4-core-data/core-data-overview/)-generated classes: ```objective-c @interface Person : NSManagedObject -@property (nonatomic, retain) NSNumber *personID; @property (nonatomic, retain) NSString *name; @property (nonatomic, retain) NSString *email; @property (nonatomic, retain) Car *car; @@ -44,17 +83,14 @@ Supose you have these classes: @interface Car : NSManagedObject -@property (nonatomic, retain) NSNumber *carID; @property (nonatomic, retain) NSString *model; @property (nonatomic, retain) NSString *year; -@property (nonatomic, retain) NSDate *createdAt; @property (nonatomic, retain) Person *person; @end @interface Phone : NSManagedObject -@property (nonatomic, retain) NSNumber *phoneID; @property (nonatomic, retain) NSString *ddi; @property (nonatomic, retain) NSString *ddd; @property (nonatomic, retain) NSString *number; @@ -63,41 +99,89 @@ Supose you have these classes: @end ``` -Mapping can be described in next way: +In order to map _JSON to Object_ and vice versa we have to describe mapping rules: ```objective-c -@implementation MappingProvider +@implementation Person (Mapping) -+ (FEMManagedObjectMapping *)personMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Person" configuration:^(FEMManagedObjectMapping *mapping) { - [mapping setPrimaryKey:@"personID"]; // object uniquing ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + [mapping addAttributesFromArray:@[@"name"]]; + [mapping addAttributesFromDictionary:@{@"email": @"user_email"}]; - [mapping addAttributesFromDictionary:@{@"personID": @"id"}]; - [mapping addAttributesFromArray:@[@"name", @"email", @"gender"]]; + [mapping addRelationshipMapping:[Car defaultMapping] forProperty:@"car" keyPath:@"car"]; + [mapping addToManyRelationshipMapping:[Person defaultMapping] forProperty:@"phones" keyPath:@"phones"]; - [mapping addRelationshipMapping:[self carMapping] forProperty:@"car" keyPath:@"car"]; - [mapping addToManyRelationshipMapping:[self phoneMapping] forProperty:@"phones" keyPath:@"phones"]; - }]; + return mapping; } -+ (FEMManagedObjectMapping *)carMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Car" configuration:^(FEMManagedObjectMapping *mapping) { - [mapping setPrimaryKey:@"carID"]; +@end + +@implementation Car (Mapping) - [mapping addAttributesFromArray:@[@"model", @"year"]]; - }]; ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Car"]; + [mapping addAttributesFromArray:@[@"model", @"year"]]; + + return mapping; } -+ (FEMManagedObjectMapping *)phoneMapping { - return [FEMManagedObjectMapping mappingForEntityName:@"Phone" configuration:^(FEMManagedObjectMapping *mapping) { - [mapping addAttributesFromDictionary:@{@"phoneID" : @"id"}]; - [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; - }]; +@end + + +@implementation Phone (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Phone"]; + [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; + + return mapping; } @end ``` +Now we can deserialize Object from JSON easily: + +```objective-c +FEMMapping *mapping = [Person defaultMapping]; +Person *person = [FEMDeserializer objectFromRepresentation:json mapping:mapping context:managedObjectContext]; +``` + +Or collection of objects: + +```objective-c +NSArray *persons = [FEMDeserializer collectionFromRepresentation:json mapping:mapping context:managedObjectContext]; +``` + +Or update object: +```objective-c +[FEMDeserializer fillObject:person fromRepresentation:json mapping:mapping]; + +``` + +### Serialization + +Now we want to convert an _Object to JSON_ having mapping defined above: +```objective-c +FEMMapping *mapping = [Person defaultMapping]; +Person *person = ...; +NSDictionary *json = [FEMSerializer serializeObject:person usingMapping:mapping]; +``` + +Or convert collection to a JSON: +```objective-c +FEMMapping *mapping = [Person defaultMapping]; +NSArray *persons = ...; +NSArray *json = [FEMSerializer serializeCollection:persons usingMapping:mapping]; +``` + +## Mapping +Mapping is a core of this project which consists of 3 classes: +- `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. +- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from Object to JSON and back. +- `FEMRelationship` - class that describes relationship between two `FEMMapping` instances. + Converting a NSDictionary or NSArray to a object class or collection now becomes easy: From 72f2f6d66a329f3be148a226f3d31dfc223b7232 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 09:08:50 +0300 Subject: [PATCH 73/95] Readme update --- FastEasyMapping/Source/Utility/FEMTypes.h | 2 +- README.md | 56 ++++++++++++++++++++--- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/FastEasyMapping/Source/Utility/FEMTypes.h b/FastEasyMapping/Source/Utility/FEMTypes.h index 2e02cb2..2f6556a 100644 --- a/FastEasyMapping/Source/Utility/FEMTypes.h +++ b/FastEasyMapping/Source/Utility/FEMTypes.h @@ -1,4 +1,4 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import -typedef id(^FEMMapBlock)(id value); \ No newline at end of file +typedef __nullable id (^FEMMapBlock)(id value __nonnull); \ No newline at end of file diff --git a/README.md b/README.md index ee33f62..861cab6 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ or add as a static library. * `FEMMapping` * `` - - `FEMAttribute' + - `FEMAttribute` - `FEMRelationship` ### Deserialization _(JSON to Object)_ @@ -141,7 +141,7 @@ In order to map _JSON to Object_ and vice versa we have to describe mapping rule @end ``` -Now we can deserialize Object from JSON easily: +Now we can deserialize _JSON to Object_ easily: ```objective-c FEMMapping *mapping = [Person defaultMapping]; @@ -154,7 +154,7 @@ Or collection of objects: NSArray *persons = [FEMDeserializer collectionFromRepresentation:json mapping:mapping context:managedObjectContext]; ``` -Or update object: +Or even update object: ```objective-c [FEMDeserializer fillObject:person fromRepresentation:json mapping:mapping]; @@ -162,14 +162,14 @@ Or update object: ### Serialization -Now we want to convert an _Object to JSON_ having mapping defined above: +Also we can serialize an _Object to JSON_ using mapping defined above: ```objective-c FEMMapping *mapping = [Person defaultMapping]; Person *person = ...; NSDictionary *json = [FEMSerializer serializeObject:person usingMapping:mapping]; ``` -Or convert collection to a JSON: +Or collection to JSON: ```objective-c FEMMapping *mapping = [Person defaultMapping]; NSArray *persons = ...; @@ -177,9 +177,53 @@ NSArray *json = [FEMSerializer serializeCollection:persons usingMapping:mapping] ``` ## Mapping +### Attribute Mapping +`FEMAttribute` is a core class of FEM. Briefly it is a description of relationship between the Object's `property` and the JSON's `keyPath`. Also it encapsulates knowledge of how the value needs to be mapped from _Object to JSON_ and back via blocks. + +```objective-c +typedef __nullable id (^FEMMapBlock)(id value __nonnull); + +@interface FEMAttribute : NSObject + +@property (nonatomic, copy, nonnull) NSString *property; +@property (nonatomic, copy, nullable) NSString *keyPath; + +- (nonnull instancetype)initWithProperty:(nonnull NSString *)property keyPath:(nullable NSString *)keyPath map:(nullable FEMMapBlock)map reverseMap:(nullable FEMMapBlock)reverseMap; + +- (nullable id)mapValue:(nullable id)value; +- (nullable id)reverseMapValue:(nullable id)value; + +@end +``` + +Alongside with `property` and `keyPath` value you can pass mapping blocks that allow to describe completely custom mappings. + +Examples: + +- Mapping of value with same keys and type: +```objective-c +FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; +// or +FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"url" keyPath:@"url" map:NULL, reverseMap:NULL]; +``` + +- Mapping of value with different keys and same type: +```objective-c +FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"urlString" toKeyPath:@"URL"]; +// or +FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"urlString" keyPath:@"URL" map:NULL, reverseMap:NULL]; +``` + + + +#### Map and Reverse Map + +#### Nil Keypath + + Mapping is a core of this project which consists of 3 classes: - `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. -- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from Object to JSON and back. +- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from _Object to JSON_ and back. - `FEMRelationship` - class that describes relationship between two `FEMMapping` instances. From 29cbfe4428c18a85574b8483d4365cf1439b3ddd Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:32:51 +0300 Subject: [PATCH 74/95] Reordering of FEMRelationship header --- FastEasyMapping/Source/Core/Mapping/FEMRelationship.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FastEasyMapping/Source/Core/Mapping/FEMRelationship.h b/FastEasyMapping/Source/Core/Mapping/FEMRelationship.h index f2c64b9..cff130c 100644 --- a/FastEasyMapping/Source/Core/Mapping/FEMRelationship.h +++ b/FastEasyMapping/Source/Core/Mapping/FEMRelationship.h @@ -9,12 +9,12 @@ @interface FEMRelationship : NSObject -@property (nonatomic, copy, nonnull) FEMAssignmentPolicy assignmentPolicy; - -@property (nonatomic) BOOL weak; @property (nonatomic, strong, nonnull) FEMMapping *mapping; @property (nonatomic, getter=isToMany) BOOL toMany; +@property (nonatomic) BOOL weak; +@property (nonatomic, copy, nonnull) FEMAssignmentPolicy assignmentPolicy; + - (nonnull instancetype)initWithProperty:(nonnull NSString *)property mapping:(nonnull FEMMapping *)mapping; - (nonnull instancetype)initWithProperty:(nonnull NSString *)property From c451e5e72353d9ccb43e2f950715898ea7166936 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:34:52 +0300 Subject: [PATCH 75/95] Remove ambiguity for custom Attribute map blocks --- FastEasyMapping/Source/Utility/FEMRepresentationUtility.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m index 8056679..546dd94 100644 --- a/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m +++ b/FastEasyMapping/Source/Utility/FEMRepresentationUtility.m @@ -69,5 +69,11 @@ void _FEMRepresentationCollectPresentedPrimaryKeys(id representation, FEMMapping id FEMRepresentationValueForAttribute(id representation, FEMAttribute *attribute) { id value = attribute.keyPath ? [representation valueForKeyPath:attribute.keyPath] : representation; - return [attribute mapValue:value]; + // nil is a valid value for missing keys. therefore attribute is discarded + if (value != nil) { + // if by mistake nil returned we still have to map it to the NSNull to indicate missing value + return [attribute mapValue:value] ?: [NSNull null]; + } + + return value; } \ No newline at end of file From fe6ad25170383f2eaa8fcdeaa0be60dd743c7779 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:35:15 +0300 Subject: [PATCH 76/95] Nil values treated as NSNull by Serializer --- FastEasyMapping/Source/Core/Serializer/FEMSerializer.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m index 383789a..4156037 100644 --- a/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m +++ b/FastEasyMapping/Source/Core/Serializer/FEMSerializer.m @@ -47,7 +47,7 @@ + (id)serializeCollection:(NSArray *)collection usingMapping:(FEMMapping *)mappi + (void)setValueOnRepresentation:(NSMutableDictionary *)representation fromObject:(id)object withFieldMapping:(FEMAttribute *)fieldMapping { id returnedValue = [object valueForKey:fieldMapping.property]; if (returnedValue) { - returnedValue = [fieldMapping reverseMapValue:returnedValue]; + returnedValue = [fieldMapping reverseMapValue:returnedValue] ?: [NSNull null]; [self setValue:returnedValue forKeyPath:fieldMapping.keyPath inRepresentation:representation]; } From e0eaf53867defbf7549ac18520fed3f9ded45396 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:35:32 +0300 Subject: [PATCH 77/95] Add nullability specifiers to FEMMapBlock --- FastEasyMapping/Source/Utility/FEMTypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/Utility/FEMTypes.h b/FastEasyMapping/Source/Utility/FEMTypes.h index 2f6556a..7c52d8f 100644 --- a/FastEasyMapping/Source/Utility/FEMTypes.h +++ b/FastEasyMapping/Source/Utility/FEMTypes.h @@ -1,4 +1,4 @@ // For License please refer to LICENSE file in the root of FastEasyMapping project #import -typedef __nullable id (^FEMMapBlock)(id value __nonnull); \ No newline at end of file +typedef __nullable id (^FEMMapBlock)(__nonnull id value); \ No newline at end of file From ca6bf6a9f7972da517a4e0ae6dd9f5dcbc7c36dd Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:35:46 +0300 Subject: [PATCH 78/95] Add description of attribute & relationship to readme --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 861cab6..a735e41 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ NSArray *json = [FEMSerializer serializeCollection:persons usingMapping:mapping] ``` ## Mapping -### Attribute Mapping +### FEMAttribute `FEMAttribute` is a core class of FEM. Briefly it is a description of relationship between the Object's `property` and the JSON's `keyPath`. Also it encapsulates knowledge of how the value needs to be mapped from _Object to JSON_ and back via blocks. ```objective-c @@ -200,23 +200,76 @@ Alongside with `property` and `keyPath` value you can pass mapping blocks that a Examples: -- Mapping of value with same keys and type: +#### Mapping of value with same keys and type: ```objective-c FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; // or FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"url" keyPath:@"url" map:NULL, reverseMap:NULL]; ``` -- Mapping of value with different keys and same type: +#### Mapping of value with different keys and same type: ```objective-c FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"urlString" toKeyPath:@"URL"]; // or FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"urlString" keyPath:@"URL" map:NULL, reverseMap:NULL]; ``` +#### Mapping of different types: +Quite often value type in JSON needs to be converted to more useful internal representation. For example HEX to `UIColor`, `String` to `NSURL`, `Integer` to `enum` and so on. For this purpose you can use `map` and `reverseMap` properties. For example lets describe attribute that maps String to `NSDate` using `NSDateFormatter`: +```objective-c +NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; +[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; +[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; +[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]; + +FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"updateDate" keyPath:@"timestamp" map:^id(id value) { + if ([value isKindOfClass:[NSString class]]) { + return [formatter dateFromString:value]; + } + return nil; +} reverseMap:^id(id value) { + return [formatter stringFromDate:value]; +}]; +``` +First of all we've defined [NSDateFormatter](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/) that fits our requirements. Next step is to define Attribute instance with correct mapping. Briefly `map` block is invoked during deserialization (_JSON to Object_) while `reverseMap` is used for serialization process. Both are quite stratforward with but with few gotchas: + +- `map` can receive `NSNull` instance. This is a valid case for `null` value in JSON. +- `map` won't be invoked for missing keys. Therefore if JSON doesn't contain `keyPath` specified by your attribute, reverse mapping not called. +- you can return from `map` either `nil` or `NSNull` for empty values +- `reverseMap` invoked only when `property` contains non-nil value. +- you can return from `reverseMap` either `nil` or `NSNull`. Both will produce `{"keyPath": null}` + + +### FEMRelationship +`FEMRelationship` is a class that describes relationship between two `FEMMapping` instances. +```objective-c +@interface FEMRelationship + +@property (nonatomic, copy, nonnull) NSString *property; +@property (nonatomic, copy, nullable) NSString *keyPath; + +@property (nonatomic, strong, nonnull) FEMMapping *mapping; +@property (nonatomic, getter=isToMany) BOOL toMany; + +@property (nonatomic) BOOL weak; +@property (nonatomic, copy, nonnull) FEMAssignmentPolicy assignmentPolicy; + +@end +``` + +Relationship also bound to a `property` and `keyPath`. Obviously it has a reference to Object's `FEMMapping` and flag that indicates whethere it is a to-many relationship. Moreover it allows you to specify assignment policy and "weakifying" behaviour of the relationship. + +Example: + +```objective-c +FEMMapping *childMapping = ...; + +FEMRelationship *childRelationship = [[FEMRelationship alloc] initWithProperty:@"parentProperty" keyPath:@"jsonKeyPath" mapping:childMapping]; +childRelationship.toMany = YES; +``` +### FEMMapping -#### Map and Reverse Map #### Nil Keypath @@ -224,7 +277,7 @@ FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"urlString" ke Mapping is a core of this project which consists of 3 classes: - `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. - `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from _Object to JSON_ and back. -- `FEMRelationship` - class that describes relationship between two `FEMMapping` instances. +- `FEMRelationship` - Converting a NSDictionary or NSArray to a object class or collection now becomes easy: From 591f6e97562a5570bfd4fb2db86c1d40a4db513d Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 10:52:57 +0300 Subject: [PATCH 79/95] Add description of additing an attribute to mapping --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index a735e41..ee9a2e2 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,32 @@ First of all we've defined [NSDateFormatter](https://developer.apple.com/library - `reverseMap` invoked only when `property` contains non-nil value. - you can return from `reverseMap` either `nil` or `NSNull`. Both will produce `{"keyPath": null}` +#### Adding attribute to FEMMapping +There are several shortcuts that allows you to add attributes easier to the mapping itself: +##### Excplicit +```objective-c +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; +[mapping addAttribute:attribute]; +``` + +```objective-c +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +[mapping addAttributeWithProperty:@"property" keyPath:@"keyPath"]; +``` + + +##### As Dictionary +```objective-c +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +[mapping addAttributesFromDictionary:@{@"property": @"keyPath"}]; +``` + +##### As Array +```objective-c +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +[mapping addAttributesFromArray:@[@"propertyAndKeyPathAreTheSame"]]; +``` ### FEMRelationship `FEMRelationship` is a class that describes relationship between two `FEMMapping` instances. From 3f355df97ec50ae09f863004e56d2658d203c4b7 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 12:02:01 +0300 Subject: [PATCH 80/95] Add description of assignment policy --- README.md | 59 +++++++++++++++++++++++-------------------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index ee9a2e2..61e6ae1 100644 --- a/README.md +++ b/README.md @@ -248,12 +248,12 @@ FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; [mapping addAttribute:attribute]; ``` +##### Implicit ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; [mapping addAttributeWithProperty:@"property" keyPath:@"keyPath"]; ``` - ##### As Dictionary ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; @@ -294,56 +294,47 @@ FEMRelationship *childRelationship = [[FEMRelationship alloc] initWithProperty:@ childRelationship.toMany = YES; ``` -### FEMMapping - +#### Assignment policy +Assignment policy describes how deserialized relationship value should be assigned to a property. FEM supports 5 policies out of the box: -#### Nil Keypath +- `FEMAssignmentPolicyAssign` - replace Old property's value by New. Designed for to-one and to-many relationship. +- `FEMAssignmentPolicyObjectMerge` - assigns New relationship value unless it is nil. Designed for to-one relationship. +- `FEMAssignmentPolicyCollectionMerge` - merges a New and Old values of relationship. Supported collections are: [NSSet](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/), [NSArray](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/), [NSOrderedSet](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSOrderedSet_Class/) and their successors. Designed for to-many relationship. +- `FEMAssignmentPolicyObjectReplace` - replaces Old value with New by deleting Old. Designed for to-one relationship. +- `FEMAssignmentPolicyCollectionReplace` - deletes objects not presented in [union](https://en.wikipedia.org/wiki/Union_(set_theory)) of New and Old values sets. Union set is used as a New value. Supported collections are: [NSSet](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/), [NSArray](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/), [NSOrderedSet](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSOrderedSet_Class/) and their successors. Designed for to-many relationship. +#### Adding relationship to FEMMapping -Mapping is a core of this project which consists of 3 classes: -- `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. -- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from _Object to JSON_ and back. -- `FEMRelationship` - - - -Converting a NSDictionary or NSArray to a object class or collection now becomes easy: - +##### Excplicit ```objective-c -Person *person = [FEMManagedObjectDeserializer deserializeObjectExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider personMapping] - context:context]; +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +FEMMapping *carMapping = [[FEMMapping alloc] initWithObjectClass:[Car class]]; -NSArray *cars = [FEMManagedObjectDeserializer deserializeCollectionExternalRepresentation:externalRepresentation - usingMapping:[MappingProvider carMapping] - context:moc]; +FEMRelationship *carRelationship = [[FEMRelationship alloc] initWithProperty:@"car" keyPath:@"car" mapping:carMapping]; +[mapping addRelationship:carRelationship]; ``` - -Filling an existent object: - +##### Implicit ```objective-c -Person *person = // fetch somehow; +FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; +FEMMapping *phoneMapping = [[FEMMapping alloc] initWithObjectClass:[Phone class]]; -FEMManagedObjectMapping *mapping = [MappingProvider personMapping]; -[FEMManagedObjectDeserializer fillObject:person fromExternalRepresentation:externalRepresentation usingMapping:mapping]; +[mapping addToManyRelationshipMapping:phoneMapping property:@"phones" keyPath:@"phones"]; ``` -### Assignment Policy +### FEMMapping + -Now relationship can use one of three predefined assignment policies: `FEMAssignmentPolicyAssign`, `FEMAssignmentPolicyMerge` and `FEMAssignmentPolicyReplace`. +#### Nil Keypath -## Deserialization. NSObject -If you are using NSObject use `FEMObjectMapping` instead of `FEMManagedObjectMapping` and `FEMObjectDeserializer` instead of `FEMManagedObjectDeserializer`. +Mapping is a core of this project which consists of 3 classes: +- `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. +- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from _Object to JSON_ and back. +- `FEMRelationship` - -## Serialization -For both NSManagedObject and NSObject serialization to JSON looks the same: -```objective-c -NSDictionary *representation = [FEMSerializer serializeObject:car usingMapping:[MappingProvider carMapping]]; -NSArray *collectionRepresentation = [FEMSerializer serializeCollection:cars usingMapping:[MappingProvider carMapping]]; -``` # Changelog From e98f8f2c115ecab90164b789169582c2b548de47 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 12:06:30 +0300 Subject: [PATCH 81/95] Minor changes in readme --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 61e6ae1..28037d2 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"urlString" ke ``` #### Mapping of different types: -Quite often value type in JSON needs to be converted to more useful internal representation. For example HEX to `UIColor`, `String` to `NSURL`, `Integer` to `enum` and so on. For this purpose you can use `map` and `reverseMap` properties. For example lets describe attribute that maps String to `NSDate` using `NSDateFormatter`: +Quite often value type in JSON needs to be converted to more useful internal representation. For example HEX to `UIColor`, `String` to `NSURL`, `Integer` to `enum` and so on. For this purpose you can use `map` and `reverseMap` properties. For example lets describe attribute that maps `String` to [NSDate](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/) using [NSDateFormatter](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/): ```objective-c NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; @@ -241,14 +241,14 @@ First of all we've defined [NSDateFormatter](https://developer.apple.com/library #### Adding attribute to FEMMapping There are several shortcuts that allows you to add attributes easier to the mapping itself: -##### Excplicit +##### Excplicitly ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; [mapping addAttribute:attribute]; ``` -##### Implicit +##### Implicitly ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; [mapping addAttributeWithProperty:@"property" keyPath:@"keyPath"]; @@ -261,6 +261,7 @@ FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; ``` ##### As Array +Useful when the `property` is equal to the `keyPath`: ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; [mapping addAttributesFromArray:@[@"propertyAndKeyPathAreTheSame"]]; @@ -305,7 +306,7 @@ Assignment policy describes how deserialized relationship value should be assign #### Adding relationship to FEMMapping -##### Excplicit +##### Excplicitly ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; FEMMapping *carMapping = [[FEMMapping alloc] initWithObjectClass:[Car class]]; @@ -314,7 +315,7 @@ FEMRelationship *carRelationship = [[FEMRelationship alloc] initWithProperty:@"c [mapping addRelationship:carRelationship]; ``` -##### Implicit +##### Implicitly ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; FEMMapping *phoneMapping = [[FEMMapping alloc] initWithObjectClass:[Phone class]]; From ff696e0511133a9fee618e99750008fa2ca13b17 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 12:35:28 +0300 Subject: [PATCH 82/95] Add FEMMapping description --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 28037d2..1563fd3 100644 --- a/README.md +++ b/README.md @@ -298,8 +298,8 @@ childRelationship.toMany = YES; #### Assignment policy Assignment policy describes how deserialized relationship value should be assigned to a property. FEM supports 5 policies out of the box: -- `FEMAssignmentPolicyAssign` - replace Old property's value by New. Designed for to-one and to-many relationship. -- `FEMAssignmentPolicyObjectMerge` - assigns New relationship value unless it is nil. Designed for to-one relationship. +- `FEMAssignmentPolicyAssign` - replace Old property's value by New. Designed for to-one and to-many relationship. Default policy. +- `FEMAssignmentPolicyObjectMerge` - assigns New relationship value unless it is `nil`. Designed for to-one relationship. - `FEMAssignmentPolicyCollectionMerge` - merges a New and Old values of relationship. Supported collections are: [NSSet](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/), [NSArray](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/), [NSOrderedSet](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSOrderedSet_Class/) and their successors. Designed for to-many relationship. - `FEMAssignmentPolicyObjectReplace` - replaces Old value with New by deleting Old. Designed for to-one relationship. - `FEMAssignmentPolicyCollectionReplace` - deletes objects not presented in [union](https://en.wikipedia.org/wiki/Union_(set_theory)) of New and Old values sets. Union set is used as a New value. Supported collections are: [NSSet](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSSet_Class/), [NSArray](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/), [NSOrderedSet](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSOrderedSet_Class/) and their successors. Designed for to-many relationship. @@ -324,6 +324,45 @@ FEMMapping *phoneMapping = [[FEMMapping alloc] initWithObjectClass:[Phone class] ``` ### FEMMapping +Generally `FEMMapping` is a class that describes mapping for `Class` or `Entity` by encapsulating set of attributes and relationships. In addition to this it defines possibilities for objects uniquing (supported by CoreData only). + +#### Root Path +Sometimes desired JSON is nested by a keyPath. In this case you can use `rootPath` property. Lets modify Person JSON by nesting Person representation: +```json +{ + result: { + "name": "Lucas", + "user_email": "lucastoc@gmail.com", + "car": { + "model": "i30", + "year": "2013" + } + } +} +``` + +Mapping will looks like: +```objective-c +@implementation Person (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + mapping.rootPath = @"result"; + + [mapping addAttributesFromArray:@[@"name"]]; + [mapping addAttributesFromDictionary:@{@"email": @"user_email"}]; + [mapping addRelationshipMapping:[Car defaultMapping] forProperty:@"car" keyPath:@"car"]; + + return mapping; +} + +@end +``` + +> `FEMMapping.rootPath` is ignore during relationship mapping. Use `FEMRelationship.keyPath` instead! + +### Uniquing + #### Nil Keypath From 09f53b764ef57b0940477efbdf12e4bfeabece90 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 14:50:01 +0300 Subject: [PATCH 83/95] Add uniquing to readme --- README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1563fd3..faf5deb 100644 --- a/README.md +++ b/README.md @@ -359,22 +359,91 @@ Mapping will looks like: @end ``` -> `FEMMapping.rootPath` is ignore during relationship mapping. Use `FEMRelationship.keyPath` instead! +> IMPORTANT: `FEMMapping.rootPath` is ignore during relationship mapping. Use `FEMRelationship.keyPath` instead! ### Uniquing +It is a common case when you're deserializing JSON into CoreData and don't want to duplicate data in your database. This can be easily achieved by utilizing `FEMMapping.primaryKey`. It informs `FEMDeserializer` to track primary keys and avoid data copying. For example lets make Person's `email` a primary key attribute: +```objective-c +@implementation Person (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + mapping.primaryKey = @"email"; + [mapping addAttributesFromArray:@[@"name"]]; + [mapping addAttributesFromDictionary:@{@"email": @"user_email"}]; + + [mapping addRelationshipMapping:[Car defaultMapping] forProperty:@"car" keyPath:@"car"]; + + return mapping; +} + +@end +``` + +Starting from second import `FEMDeserializer` will update existing `Person`. + +### Relationship bindings by PK +Sometimes object representation contains a relationship described by a PK of the target entity: +``` +{ + "result": { + "id": 314 + "title": "https://github.com" + "category": 4 + } +} +``` + +As you can see from JSON we have two objects: `Website` and `Category`. Whereas `Website` can be imported easily, there is an external reference to a `Category` represented by its primary key `id`. Can we bind website to the corresponding category? Yep! We just need to treat `category` keyPath as a full description of object: + +First of all lets declare our classes: +```objective-c +@interface Website: NSManagedObject + +@property (nonatomic, strong) NSNumber *identifier; +@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) Category *category; +@end +@interface Category: NSManagedObject -#### Nil Keypath +@property (nonatomic, strong) NSNumber *identifier; +@property (nonatomic, strong) NSString *title; +@property (nonatomic, strong) NSSet *websites +@end +``` + +Now it is time to define mapping for `Website`: + +```objective-c +@interface Website (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Website"]; + mapping.primaryKey = @"identifier"; + [mapping addAttributesFromDictionary:@{@"identifier": @"id", @"title": @"title"}]; + + FEMMapping *categoryMapping = [[FEMMapping alloc] initWithEntityName:@"Category"]; + categoryMapping.primaryKey = @"identifier"; + [categoryMapping addAttributesFromDictionary:@{@"identifier": @"category"}]; + + [mapping addRelationshipMapping:categoryMapping property:@"category" keyPath:nil]; + + return mapping; +} + +@end + +``` -Mapping is a core of this project which consists of 3 classes: -- `FEMMapping` - class that describes an Object. It encapsulates all Object's attributes and relationships. -- `FEMAttribute` - description of relationship between an Object's `property` and a JSON's `keyPath`. Also it encapsulates rules of how the value needs to be mapped from _Object to JSON_ and back. -- `FEMRelationship` - +By specifying `nil` as a `keyPath` for the category `Website`'s representation is treated as a `Category` at the same time. In this way it is easy to bind objects that are passed by PKs (which is quite common for network). +#### Weak relationship +> We recommend to index your primary key in datamodel to speedup keys lookup. Supported values for primary keys are Strings and Integers. # Changelog From ce6b0544a01b9185218c58babaaab8bd9ecd1de8 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:05:53 +0300 Subject: [PATCH 84/95] Add convenienced initializers --- .../Source/Core/Deserializer/FEMDeserializer.h | 5 ++++- .../Source/Core/Deserializer/FEMDeserializer.m | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h index 09213d5..1197f59 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.h @@ -20,7 +20,10 @@ @interface FEMDeserializer : NSObject @property (nonatomic, strong, readonly, nonnull) FEMObjectStore *store; -- (nonnull instancetype)initWithStore:(nonnull FEMObjectStore *)store; +- (nonnull instancetype)initWithStore:(nonnull FEMObjectStore *)store NS_DESIGNATED_INITIALIZER; + +- (nonnull instancetype)init; +- (nonnull instancetype)initWithContext:(nonnull NSManagedObjectContext *)context; @property (nonatomic, unsafe_unretained, nullable) id delegate; diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index b69c2c6..2066c86 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -34,6 +34,14 @@ - (id)initWithStore:(FEMObjectStore *)store { return self; } +- (nonnull instancetype)init { + return [self initWithStore:[[FEMObjectStore alloc] init]]; +} + +- (nonnull instancetype)initWithContext:(NSManagedObjectContext *)context { + return [self initWithStore:[[FEMManagedObjectStore alloc] initWithContext:context]]; +} + #pragma mark - Delegate - (void)setDelegate:(id )delegate { From 8a8f8c405ea5de71d6e5cc5e1341d4f74f78385f Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:06:07 +0300 Subject: [PATCH 85/95] Add weak relationships to README --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index faf5deb..f35b497 100644 --- a/README.md +++ b/README.md @@ -324,7 +324,19 @@ FEMMapping *phoneMapping = [[FEMMapping alloc] initWithObjectClass:[Phone class] ``` ### FEMMapping -Generally `FEMMapping` is a class that describes mapping for `Class` or `Entity` by encapsulating set of attributes and relationships. In addition to this it defines possibilities for objects uniquing (supported by CoreData only). +Generally `FEMMapping` is a class that describes mapping for `NSObject` or `NSManagedObject` by encapsulating set of attributes and relationships. In addition to this it defines possibilities for objects uniquing (supported by CoreData only). + +The only difference between `NSObject` and `NSManagedObject` is in `init` methods: + +##### NSObject +```objective-c +FEMMapping *objectMapping = [[FEMMapping alloc] initWithObjectClass:[CustomNSObjectSuccessor class]]; +``` + +##### NSManagedObject +```objective-c +FEMMapping *managedObjectMapping = [[FEMMapping alloc] initWithEntityName:@"EntityName"]; +``` #### Root Path Sometimes desired JSON is nested by a keyPath. In this case you can use `rootPath` property. Lets modify Person JSON by nesting Person representation: @@ -380,6 +392,8 @@ It is a common case when you're deserializing JSON into CoreData and don't want @end ``` +> We recommend to index your primary key in datamodel to speedup keys lookup. Supported values for primary keys are Strings and Integers. + Starting from second import `FEMDeserializer` will update existing `Person`. ### Relationship bindings by PK @@ -394,7 +408,7 @@ Sometimes object representation contains a relationship described by a PK of the } ``` -As you can see from JSON we have two objects: `Website` and `Category`. Whereas `Website` can be imported easily, there is an external reference to a `Category` represented by its primary key `id`. Can we bind website to the corresponding category? Yep! We just need to treat `category` keyPath as a full description of object: +As you can see from JSON we have two objects: `Website` and `Category`. Whereas `Website` can be imported easily, there is an external reference to a `Category` represented by its primary key `id`. Can we bind website to the corresponding category? Yep! We just need to treat Website's representation as a Category: First of all lets declare our classes: ```objective-c @@ -418,7 +432,7 @@ First of all lets declare our classes: Now it is time to define mapping for `Website`: ```objective-c -@interface Website (Mapping) +@implementation Website (Mapping) + (FEMMapping *)defaultMapping { FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Website"]; @@ -441,9 +455,32 @@ Now it is time to define mapping for `Website`: By specifying `nil` as a `keyPath` for the category `Website`'s representation is treated as a `Category` at the same time. In this way it is easy to bind objects that are passed by PKs (which is quite common for network). #### Weak relationship +In example above we have one issue: what if our database doesn't contain `Category` with `PK = 4`? By default `FEMDeserializer` creates new objects during deserialization lazily. In our case it leads to insertion of `Category` instance without any data except `identifier`. In order to prevent such inconsistencies we can set `FEMRelationship.weak` to YES: +```objective-c +@implementation Website (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Website"]; + mapping.primaryKey = @"identifier"; + [mapping addAttributesFromDictionary:@{@"identifier": @"id", @"title": @"title"}]; + + FEMMapping *categoryMapping = [[FEMMapping alloc] initWithEntityName:@"Category"]; + categoryMapping.primaryKey = @"identifier"; + categoryMapping.weak = YES; + [categoryMapping addAttributesFromDictionary:@{@"identifier": @"category"}]; + + [mapping addRelationshipMapping:categoryMapping property:@"category" keyPath:nil]; + + return mapping; +} + +@end + +``` + +As the result it'll bind `Website` to corresponding `Category` only in case the latter exists. -> We recommend to index your primary key in datamodel to speedup keys lookup. Supported values for primary keys are Strings and Integers. # Changelog From 1dd4b8fdc02027cfad199b694937e7749353f832 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:38:03 +0300 Subject: [PATCH 86/95] Add delegate to readme --- README.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f35b497..63b5a71 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ Mapping will looks like: > IMPORTANT: `FEMMapping.rootPath` is ignore during relationship mapping. Use `FEMRelationship.keyPath` instead! -### Uniquing +## Uniquing It is a common case when you're deserializing JSON into CoreData and don't want to duplicate data in your database. This can be easily achieved by utilizing `FEMMapping.primaryKey`. It informs `FEMDeserializer` to track primary keys and avoid data copying. For example lets make Person's `email` a primary key attribute: ```objective-c @implementation Person (Mapping) @@ -454,7 +454,7 @@ Now it is time to define mapping for `Website`: By specifying `nil` as a `keyPath` for the category `Website`'s representation is treated as a `Category` at the same time. In this way it is easy to bind objects that are passed by PKs (which is quite common for network). -#### Weak relationship +### Weak relationship In example above we have one issue: what if our database doesn't contain `Category` with `PK = 4`? By default `FEMDeserializer` creates new objects during deserialization lazily. In our case it leads to insertion of `Category` instance without any data except `identifier`. In order to prevent such inconsistencies we can set `FEMRelationship.weak` to YES: ```objective-c @@ -481,9 +481,92 @@ In example above we have one issue: what if our database doesn't contain `Catego As the result it'll bind `Website` to corresponding `Category` only in case the latter exists. +## Delegation +You can customize deserialization process by implementing `FEMDeserializerDelegate` protocol: +```objective-c +@protocol FEMDeserializerDelegate + +@optional +- (void)deserializer:(nonnull FEMDeserializer *)deserializer willMapObjectFromRepresentation:(nonnull id)representation mapping:(nonnull FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer didMapObject:(nonnull id)object fromRepresentation:(nonnull id)representation mapping:(nonnull FEMMapping *)mapping; + +- (void)deserializer:(nonnull FEMDeserializer *)deserializer willMapCollectionFromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; +- (void)deserializer:(nonnull FEMDeserializer *)deserializer didMapCollection:(nonnull NSArray *)collection fromRepresentation:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping; + +@end +``` + +However, if you're using Delegate you also have to instantiate `FEMDeserializer` manually: +##### NSObject +```objective-c +FEMDeserializer *deserializer = [[FEMDeserializer alloc] init]; +deserializer.delegate = self; +``` + +##### NSManagedObject +```objective-c +FEMDeserializer *deserializer = [[FEMDeserializer alloc] initWithContext:managedObjectContext]; +deserializer.delegate = self; +``` + +Note, that delegate methods will be called on every object and collection during deserialization. Lets use `Person` example: +``` +{ + "name": "Lucas", + "user_email": "lucastoc@gmail.com", + "phones": [ + { + "ddi": "55", + "ddd": "85", + "number": "1111-1111" + } + ] +} +``` + +Mapping: +```objective-c +@implementation Person (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Person"]; + [mapping addAttributesFromArray:@[@"name"]]; + [mapping addAttributesFromDictionary:@{@"email": @"user_email"}]; + [mapping addToManyRelationshipMapping:[Person defaultMapping] forProperty:@"phones" keyPath:@"phones"]; + + return mapping; +} + +@end + +@implementation Phone (Mapping) + ++ (FEMMapping *)defaultMapping { + FEMMapping *mapping = [[FEMMapping alloc] initWithEntityName:@"Phone"]; + [mapping addAttributesFromArray:@[@"number", @"ddd", @"ddi"]]; + + return mapping; +} + +@end +``` + +During deserialization of persons collection order will be next: + +1. deserializer:willMapCollectionFromRepresentation:`Persons Array` mapping:`Person mapping` +2. deserializer:willMapObjectFromRepresentation:`Person Dictionary` mapping:`Person mapping` +3. deserializer:willMapCollectionFromRepresentation:`Phones Array` mapping:`Phone mapping` +4. deserializer:willMapObjectFromRepresentation:`Phone Dictionary` mapping:`Phone mapping` +5. deserializer:didMapObject:`Phone instance` fromRepresentation:`Phone Dictionary` mapping:`Phone mapping` +6. deserializer:didMapObject:`Person instance` fromRepresentation:`Person Dictionary` mapping:`Person mapping` +7. deserializer:didMapCollection:`Persons instances Array` fromRepresentation:`Persons Array` mapping:`Person mapping` + # Changelog +### 1.0 +- Refactoring of + ### 0.5.1 - Rename [FEMAttributeMapping](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h) to [FEMAttribute](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h), [FEMRelationshipMapping](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h) to [FEMRelationship](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h) - [Shorten FEMMapping mutation methods](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/FEMMapping.h#42) From ebb9c692ea8ec6229382f0e67bca695de136c037 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:38:11 +0300 Subject: [PATCH 87/95] Remove extra header --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m | 1 - 1 file changed, 1 deletion(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 2066c86..e009bae 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -10,7 +10,6 @@ #import "FEMRelationshipAssignmentContext+Internal.h" #import "FEMRepresentationUtility.h" #import "FEMManagedObjectStore.h" -#import "FEMMappingUtility.h" #import "NSObject+FEMKVCExtension.h" @implementation FEMDeserializer { From 9a9dd343172ba349ad2b41cf38e729223a78d20f Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:43:44 +0300 Subject: [PATCH 88/95] Replace ugly transaction method by 3 separate methods --- FastEasyMapping/Source/Core/Store/FEMObjectStore.h | 4 +++- FastEasyMapping/Source/Core/Store/FEMObjectStore.m | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index 7df9aec..f409722 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -8,7 +8,9 @@ @interface FEMObjectStore : NSObject -- (nullable NSError *)performMappingTransaction:(nonnull NSArray *)representation mapping:(nonnull FEMMapping *)mapping transaction:(nonnull void (^)(void))transaction; +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation; +- (void)beginTransaction; +- (nullable NSError *)commitTransaction; - (nonnull id)newObjectForMapping:(nonnull FEMMapping *)mapping; - (nonnull FEMRelationshipAssignmentContext *)newAssignmentContext; diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m index 0c80084..d7aa0b6 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -5,8 +5,11 @@ @implementation FEMObjectStore -- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { - transaction(); +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation {} + +- (void)beginTransaction {} + +- (NSError *)commitTransaction { return nil; } From 05ecd5cd7dd809e49cc36d7d6ed906ae72647c01 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:43:58 +0300 Subject: [PATCH 89/95] Implement new transaction methods --- .../Source/Core/Store/FEMManagedObjectStore.m | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 665df0f..671e0b2 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -27,16 +27,27 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { return self; } -#pragma mark - - -- (NSError *)performMappingTransaction:(NSArray *)representation mapping:(FEMMapping *)mapping transaction:(void (^)(void))transaction { - return [super performMappingTransaction:representation mapping:mapping transaction:^{ - _cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:self.context]; - transaction(); - _cache = nil; - }]; +#pragma mark - Transaction + +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation { + _cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:self.context]; } +- (void)beginTransaction {} + +- (NSError *)commitTransaction { + _cache = nil; + + NSError *error = nil; + if (self.saveContextOnCommit && self.context.hasChanges && ![self.context save:&error]) { + return error; + } + + return nil; +} + + + - (id)newObjectForMapping:(FEMMapping *)mapping { validateMapping(mapping); From 2bc7c7e6723c07ebb118d7ce2199b4dba2e6c7d6 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:47:17 +0300 Subject: [PATCH 90/95] Update FEMDeserializer to latest syntax --- .../Core/Deserializer/FEMDeserializer.m | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index e009bae..775d8a8 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -160,11 +160,13 @@ - (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FE - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - __block id object = nil; - [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - object = [self _objectFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; - }]; + [self.store prepareTransactionForMapping:mapping representation:@[representation]]; + [self.store beginTransaction]; + + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + id object = [self _objectFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; + + [self.store commitTransaction]; return object; } @@ -174,10 +176,13 @@ - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation ma [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; } - [self.store performMappingTransaction:@[representation] mapping:mapping transaction:^{ - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - [self _fillObject:object fromRepresentation:root mapping:mapping]; - }]; + [self.store prepareTransactionForMapping:mapping representation:@[representation]]; + [self.store beginTransaction]; + + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + [self _fillObject:object fromRepresentation:root mapping:mapping]; + + [self.store commitTransaction]; if (_delegateFlags.didMapObject) { [self.delegate deserializer:self didMapObject:object fromRepresentation:representation mapping:mapping]; @@ -187,11 +192,13 @@ - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation ma } - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { - __block NSArray *objects = nil; - [self.store performMappingTransaction:representation mapping:mapping transaction:^{ - id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); - objects = [self _collectionFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; - }]; + [self.store prepareTransactionForMapping:mapping representation:representation]; + [self.store beginTransaction]; + + id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); + NSArray *objects = [self _collectionFromRepresentation:root mapping:mapping allocateIfNeeded:YES]; + + [self.store commitTransaction]; return objects; } From 1f109a14cdde9417931a1a2d1bc9f786cb62ac38 Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:48:23 +0300 Subject: [PATCH 91/95] Renaming --- FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m | 6 +++--- FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m | 2 +- FastEasyMapping/Source/Core/Store/FEMObjectStore.h | 2 +- FastEasyMapping/Source/Core/Store/FEMObjectStore.m | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m index 775d8a8..4e258a1 100644 --- a/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m +++ b/FastEasyMapping/Source/Core/Deserializer/FEMDeserializer.m @@ -160,7 +160,7 @@ - (NSArray *)_collectionFromRepresentation:(NSArray *)representation mapping:(FE - (id)objectFromRepresentation:(NSDictionary *)representation mapping:(FEMMapping *)mapping { - [self.store prepareTransactionForMapping:mapping representation:@[representation]]; + [self.store prepareTransactionForMapping:mapping ofRepresentation:@[representation]]; [self.store beginTransaction]; id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); @@ -176,7 +176,7 @@ - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation ma [self.delegate deserializer:self willMapObjectFromRepresentation:representation mapping:mapping]; } - [self.store prepareTransactionForMapping:mapping representation:@[representation]]; + [self.store prepareTransactionForMapping:mapping ofRepresentation:@[representation]]; [self.store beginTransaction]; id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); @@ -192,7 +192,7 @@ - (id)fillObject:(id)object fromRepresentation:(NSDictionary *)representation ma } - (NSArray *)collectionFromRepresentation:(NSArray *)representation mapping:(FEMMapping *)mapping { - [self.store prepareTransactionForMapping:mapping representation:representation]; + [self.store prepareTransactionForMapping:mapping ofRepresentation:representation]; [self.store beginTransaction]; id root = FEMRepresentationRootForKeyPath(representation, mapping.rootPath); diff --git a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m index 671e0b2..fd649df 100644 --- a/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMManagedObjectStore.m @@ -29,7 +29,7 @@ - (instancetype)initWithContext:(NSManagedObjectContext *)context { #pragma mark - Transaction -- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation { +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping ofRepresentation:(nonnull NSArray *)representation { _cache = [[FEMManagedObjectCache alloc] initWithMapping:mapping representation:representation context:self.context]; } diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h index f409722..c635c39 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.h +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.h @@ -8,7 +8,7 @@ @interface FEMObjectStore : NSObject -- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation; +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping ofRepresentation:(nonnull NSArray *)representation; - (void)beginTransaction; - (nullable NSError *)commitTransaction; diff --git a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m index d7aa0b6..77eb4b8 100644 --- a/FastEasyMapping/Source/Core/Store/FEMObjectStore.m +++ b/FastEasyMapping/Source/Core/Store/FEMObjectStore.m @@ -5,7 +5,7 @@ @implementation FEMObjectStore -- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping representation:(nonnull NSArray *)representation {} +- (void)prepareTransactionForMapping:(nonnull FEMMapping *)mapping ofRepresentation:(nonnull NSArray *)representation {} - (void)beginTransaction {} From dce42198c49b307838d0c84483770b9b2ebcc3cd Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:56:53 +0300 Subject: [PATCH 92/95] Add changelog for 1.0 --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63b5a71..56b71dc 100644 --- a/README.md +++ b/README.md @@ -561,11 +561,20 @@ During deserialization of persons collection order will be next: 6. deserializer:didMapObject:`Person instance` fromRepresentation:`Person Dictionary` mapping:`Person mapping` 7. deserializer:didMapCollection:`Persons instances Array` fromRepresentation:`Persons Array` mapping:`Person mapping` - # Changelog ### 1.0 -- Refactoring of +- [Nullability](https://developer.apple.com/swift/blog/?id=25) support for easier Swift integration. +- Replacing of `FEMObjectDeserializer` and `FEMManagedObjectDeserializer` by `FEMDeserializer`. +- Replacing of `FEMObjectMapping` and `FEMManagedObjectMapping` by `FEMMapping`. +- Added Delegation for `FEMDeserializer`. +- `FEMDeserializer` supports weak relationships. +- Fixed bug when `nil` value for custom `FEMAttribute` map is ignored during deserialization. +- Fixed bug when `nil` value for custom `FEMAttribute` reverse map is ignored during serialization. +- Refactoring of internals. +- Numerious renaming in favour of shorter method names. +- Update tests and examples to latest syntax. +- Add full description to README. ### 0.5.1 - Rename [FEMAttributeMapping](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttributeMapping.h) to [FEMAttribute](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Attribute/FEMAttribute.h), [FEMRelationshipMapping](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationshipMapping.h) to [FEMRelationship](https://github.com/Yalantis/FastEasyMapping/blob/release/0.5.1/FastEasyMapping/Source/Core/Mapping/Relationship/FEMRelationship.h) From 8e9066085cb4101bc78f768759d2f0f8d0cb828e Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 31 Aug 2015 15:59:47 +0300 Subject: [PATCH 93/95] Add ``` for delegation order description --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 56b71dc..746600d 100644 --- a/README.md +++ b/README.md @@ -553,6 +553,7 @@ Mapping: During deserialization of persons collection order will be next: +``` 1. deserializer:willMapCollectionFromRepresentation:`Persons Array` mapping:`Person mapping` 2. deserializer:willMapObjectFromRepresentation:`Person Dictionary` mapping:`Person mapping` 3. deserializer:willMapCollectionFromRepresentation:`Phones Array` mapping:`Phone mapping` @@ -560,6 +561,7 @@ During deserialization of persons collection order will be next: 5. deserializer:didMapObject:`Phone instance` fromRepresentation:`Phone Dictionary` mapping:`Phone mapping` 6. deserializer:didMapObject:`Person instance` fromRepresentation:`Person Dictionary` mapping:`Person mapping` 7. deserializer:didMapCollection:`Persons instances Array` fromRepresentation:`Persons Array` mapping:`Person mapping` +``` # Changelog From bca63e8283907d6f576288e958d75acd7acab7c0 Mon Sep 17 00:00:00 2001 From: Dima Date: Mon, 31 Aug 2015 16:03:54 +0300 Subject: [PATCH 94/95] Update delegation order description --- README.md | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 746600d..258e7f5 100644 --- a/README.md +++ b/README.md @@ -553,15 +553,13 @@ Mapping: During deserialization of persons collection order will be next: -``` -1. deserializer:willMapCollectionFromRepresentation:`Persons Array` mapping:`Person mapping` -2. deserializer:willMapObjectFromRepresentation:`Person Dictionary` mapping:`Person mapping` -3. deserializer:willMapCollectionFromRepresentation:`Phones Array` mapping:`Phone mapping` -4. deserializer:willMapObjectFromRepresentation:`Phone Dictionary` mapping:`Phone mapping` -5. deserializer:didMapObject:`Phone instance` fromRepresentation:`Phone Dictionary` mapping:`Phone mapping` -6. deserializer:didMapObject:`Person instance` fromRepresentation:`Person Dictionary` mapping:`Person mapping` -7. deserializer:didMapCollection:`Persons instances Array` fromRepresentation:`Persons Array` mapping:`Person mapping` -``` +1. willMapCollectionFromRepresentation:`Persons Array` mapping:`Person mapping` +2. willMapObjectFromRepresentation:`Person Dictionary` mapping:`Person mapping` +3. willMapCollectionFromRepresentation:`Phones Array` mapping:`Phone mapping` +4. willMapObjectFromRepresentation:`Phone Dictionary` mapping:`Phone mapping` +5. didMapObject:`Phone instance` fromRepresentation:`Phone Dictionary` mapping:`Phone mapping` +6. didMapObject:`Person instance` fromRepresentation:`Person Dictionary` mapping:`Person mapping` +7. didMapCollection:`Persons instances Array` fromRepresentation:`Persons Array` mapping:`Person mapping` # Changelog From a29977537d4a2cb31e8e9909c44b378b1cdefed0 Mon Sep 17 00:00:00 2001 From: zen Date: Tue, 1 Sep 2015 11:25:25 +0300 Subject: [PATCH 95/95] Readme grammar fixes --- README.md | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 258e7f5..9040cc9 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,11 @@ [![Build Status](https://travis-ci.org/Yalantis/FastEasyMapping.png)](https://travis-ci.org/Yalantis/FastEasyMapping) ### Note -This is fork of [EasyMapping](https://github.com/lucasmedeirosleite/EasyMapping) - flexible and easy way of JSON mapping. +This is a fork of [EasyMapping](https://github.com/lucasmedeirosleite/EasyMapping), a flexible and easy framework for JSON mapping. + +## Reason +It turns out, that almost all popular libraries for JSON mapping are SLOW. The main reason for that is multiple trips to database during the lookup of existing objects. We [decided](https://yalantis.com/blog/from-json-to-core-data-fast-and-effectively/) to take an already existing [flexible solution](https://github.com/lucasmedeirosleite/EasyMapping) (i.e. EasyMapping) and improve its overall performance. -## Reason to be -It turns out, that almost all popular libraries for JSON mapping SLOW. The main reason is often trips to database during lookup of existing objects. So we [decided](http://yalantis.com/blog/2014/03/17/from-json-to-core-data-fast-and-effectively/) to take already existing [flexible solution](https://github.com/lucasmedeirosleite/EasyMapping) and improve overall performance.

FastEasyMapping

@@ -44,7 +45,7 @@ or add as a static library. ## Usage ### Deserialization -Nowadays `NSObject` and `NSManagedObject` mapping supported out of the box. Lets take a look on how basic mapping looks like:. For example, we have JSON: +Today NSObject and NSManagedObject mapping are supported out of the box. Lets take a look at how a basic mapping looks like: For example, we have JSON: ```json { @@ -99,7 +100,7 @@ and corresponding [CoreData](https://www.objc.io/issues/4-core-data/core-data-ov @end ``` -In order to map _JSON to Object_ and vice versa we have to describe mapping rules: +In order to map _JSON to Object_ and vice versa we have to describe the mapping rules: ```objective-c @implementation Person (Mapping) @@ -148,13 +149,13 @@ FEMMapping *mapping = [Person defaultMapping]; Person *person = [FEMDeserializer objectFromRepresentation:json mapping:mapping context:managedObjectContext]; ``` -Or collection of objects: +Or collection of Objects: ```objective-c NSArray *persons = [FEMDeserializer collectionFromRepresentation:json mapping:mapping context:managedObjectContext]; ``` -Or even update object: +Or even update an Object: ```objective-c [FEMDeserializer fillObject:person fromRepresentation:json mapping:mapping]; @@ -162,7 +163,7 @@ Or even update object: ### Serialization -Also we can serialize an _Object to JSON_ using mapping defined above: +Also we can serialize an _Object to JSON_ using the mapping defined above: ```objective-c FEMMapping *mapping = [Person defaultMapping]; Person *person = ...; @@ -200,14 +201,14 @@ Alongside with `property` and `keyPath` value you can pass mapping blocks that a Examples: -#### Mapping of value with same keys and type: +#### Mapping of value with the same keys and type: ```objective-c FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"url"]; // or FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"url" keyPath:@"url" map:NULL, reverseMap:NULL]; ``` -#### Mapping of value with different keys and same type: +#### Mapping of value with different keys and the same type: ```objective-c FEMAttribute *attribute = [FEMAttribute mappingOfProperty:@"urlString" toKeyPath:@"URL"]; // or @@ -234,13 +235,13 @@ FEMAttribute *attribute = [[FEMAttribute alloc] initWithProperty:@"updateDate" k First of all we've defined [NSDateFormatter](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/) that fits our requirements. Next step is to define Attribute instance with correct mapping. Briefly `map` block is invoked during deserialization (_JSON to Object_) while `reverseMap` is used for serialization process. Both are quite stratforward with but with few gotchas: - `map` can receive `NSNull` instance. This is a valid case for `null` value in JSON. -- `map` won't be invoked for missing keys. Therefore if JSON doesn't contain `keyPath` specified by your attribute, reverse mapping not called. -- you can return from `map` either `nil` or `NSNull` for empty values -- `reverseMap` invoked only when `property` contains non-nil value. -- you can return from `reverseMap` either `nil` or `NSNull`. Both will produce `{"keyPath": null}` +- map won't be invoked for missing keys. Therefore, if JSON doesn't contain keyPath specified by your attribute, reverse mapping not called. +- from map you can return either `nil` or `NSNull` for empty values +- `reverseMap` invoked only when `property` contains a non-nil value. +- from `reverseMap` you can return either `nil` or `NSNull`. Both will produce `{"keyPath": null}` #### Adding attribute to FEMMapping -There are several shortcuts that allows you to add attributes easier to the mapping itself: +There are several shortcuts that allow you to add attributes easier to the mapping itself: ##### Excplicitly ```objective-c FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; @@ -284,7 +285,7 @@ FEMMapping *mapping = [[FEMMapping alloc] initWithObjectClass:[Person class]]; @end ``` -Relationship also bound to a `property` and `keyPath`. Obviously it has a reference to Object's `FEMMapping` and flag that indicates whethere it is a to-many relationship. Moreover it allows you to specify assignment policy and "weakifying" behaviour of the relationship. +Relationship is also bound to a `property` and `keyPath`. Obviously, it has a reference to Object's `FEMMapping` and a flag that indicates whether it’s a to-many relationship. Moreover, it allows you to specify assignment policy and "weakifying" behaviour of the relationship. Example: @@ -324,7 +325,7 @@ FEMMapping *phoneMapping = [[FEMMapping alloc] initWithObjectClass:[Phone class] ``` ### FEMMapping -Generally `FEMMapping` is a class that describes mapping for `NSObject` or `NSManagedObject` by encapsulating set of attributes and relationships. In addition to this it defines possibilities for objects uniquing (supported by CoreData only). +Generally `FEMMapping` is a class that describes mapping for `NSObject` or `NSManagedObject` by encapsulating a set of attributes and relationships. In addition, it defines the possibilities for objects uniquing (supported by CoreData only). The only difference between `NSObject` and `NSManagedObject` is in `init` methods: @@ -339,8 +340,8 @@ FEMMapping *managedObjectMapping = [[FEMMapping alloc] initWithEntityName:@"Enti ``` #### Root Path -Sometimes desired JSON is nested by a keyPath. In this case you can use `rootPath` property. Lets modify Person JSON by nesting Person representation: -```json +Sometimes a desired JSON is nested by a keyPath. In this case you can use `rootPath` property. Let’s modify Person JSON by nesting Person representation: +``` { result: { "name": "Lucas", @@ -353,7 +354,7 @@ Sometimes desired JSON is nested by a keyPath. In this case you can use `rootPat } ``` -Mapping will looks like: +Mapping will look like this: ```objective-c @implementation Person (Mapping) @@ -407,10 +408,9 @@ Sometimes object representation contains a relationship described by a PK of the } } ``` +As you can see, from JSON we have two objects: `Website` and `Category`. If `Website` can be imported easily, there is an external reference to a `Category` represented by its primary key `id`. Can we bind the `Website` to the corresponding category? Yep! We just need to treat Website's representation as a Category: -As you can see from JSON we have two objects: `Website` and `Category`. Whereas `Website` can be imported easily, there is an external reference to a `Category` represented by its primary key `id`. Can we bind website to the corresponding category? Yep! We just need to treat Website's representation as a Category: - -First of all lets declare our classes: +First of all let’s declare our classes: ```objective-c @interface Website: NSManagedObject @@ -455,7 +455,7 @@ Now it is time to define mapping for `Website`: By specifying `nil` as a `keyPath` for the category `Website`'s representation is treated as a `Category` at the same time. In this way it is easy to bind objects that are passed by PKs (which is quite common for network). ### Weak relationship -In example above we have one issue: what if our database doesn't contain `Category` with `PK = 4`? By default `FEMDeserializer` creates new objects during deserialization lazily. In our case it leads to insertion of `Category` instance without any data except `identifier`. In order to prevent such inconsistencies we can set `FEMRelationship.weak` to YES: +In the example above there is an issue: what if our database doesn't contain `Category` with `PK = 4`? By default `FEMDeserializer` creates new objects during deserialization lazily. In our case this leads to insertion of `Category` instance without any data except `identifier`. In order to prevent such inconsistencies we can set `FEMRelationship.weak` to `YES`: ```objective-c @implementation Website (Mapping) @@ -478,8 +478,7 @@ In example above we have one issue: what if our database doesn't contain `Catego @end ``` - -As the result it'll bind `Website` to corresponding `Category` only in case the latter exists. +As a result it'll bind the `Website` with the corresponding `Category` only if the latter exists. ## Delegation You can customize deserialization process by implementing `FEMDeserializerDelegate` protocol: @@ -550,8 +549,7 @@ Mapping: @end ``` - -During deserialization of persons collection order will be next: +During deserialization of persons collection order will be the following: 1. willMapCollectionFromRepresentation:`Persons Array` mapping:`Person mapping` 2. willMapObjectFromRepresentation:`Person Dictionary` mapping:`Person mapping`