Permalink
Browse files

Merge branch 'transformer-inversion' into core-data-adapter

Conflicts:
	Mantle.xcodeproj/project.pbxproj
  • Loading branch information...
2 parents 658099e + b5432d6 commit df5f950b102f16f7718b0fc15253bcd58e4778ad @jspahrsummers jspahrsummers committed May 18, 2013
@@ -67,6 +67,12 @@
D090E63F15F73269005282F9 /* EXTScope.m in Sources */ = {isa = PBXBuildFile; fileRef = D090E63C15F73265005282F9 /* EXTScope.m */; };
D0ABD7A11746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0ABD7A01746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m */; };
D0ABD7A21746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0ABD7A01746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m */; };
+ D0BFC36717476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BFC36617476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m */; };
+ D0BFC36817476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BFC36617476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m */; };
+ D0BFC36F17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = D0BFC36D17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ D0BFC37017476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = D0BFC36D17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ D0BFC37117476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BFC36E17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m */; };
+ D0BFC37217476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = D0BFC36E17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m */; };
D0C27CF6161107E5002FE587 /* MTLDictionaryManipulationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0C27CF5161107E5002FE587 /* MTLDictionaryManipulationSpec.m */; };
D0C27CF7161107E5002FE587 /* MTLDictionaryManipulationSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = D0C27CF5161107E5002FE587 /* MTLDictionaryManipulationSpec.m */; };
D0C27D0A16110973002FE587 /* NSDictionary+MTLManipulationAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = D0C27D0816110973002FE587 /* NSDictionary+MTLManipulationAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -262,6 +268,9 @@
D090E63C15F73265005282F9 /* EXTScope.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = EXTScope.m; path = extobjc/EXTScope.m; sourceTree = "<group>"; };
D090E63D15F73265005282F9 /* metamacros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = metamacros.h; path = extobjc/metamacros.h; sourceTree = "<group>"; };
D0ABD7A01746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLManagedObjectAdapterSpec.m; sourceTree = "<group>"; };
+ D0BFC36617476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLValueTransformerInversionAdditionsSpec.m; sourceTree = "<group>"; };
+ D0BFC36D17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValueTransformer+MTLInversionAdditions.h"; sourceTree = "<group>"; };
+ D0BFC36E17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSValueTransformer+MTLInversionAdditions.m"; sourceTree = "<group>"; };
D0C27CF5161107E5002FE587 /* MTLDictionaryManipulationSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLDictionaryManipulationSpec.m; sourceTree = "<group>"; };
D0C27D0816110973002FE587 /* NSDictionary+MTLManipulationAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+MTLManipulationAdditions.h"; sourceTree = "<group>"; };
D0C27D0916110973002FE587 /* NSDictionary+MTLManipulationAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+MTLManipulationAdditions.m"; sourceTree = "<group>"; };
@@ -514,6 +523,7 @@
D0760EC315FFCA250060F550 /* MTLModelSpec.m */,
D0F1174C1614C8000092520B /* MTLPredefinedTransformerAdditionsSpec.m */,
D08B5AB116002A23001FE685 /* MTLValueTransformerSpec.m */,
+ D0BFC36617476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m */,
);
name = Specs;
sourceTree = "<group>";
@@ -527,6 +537,8 @@
D0C27D0916110973002FE587 /* NSDictionary+MTLManipulationAdditions.m */,
1ED5B5CE163A4E3C0072668E /* NSObject+MTLComparisonAdditions.h */,
1ED5B5CF163A4E3C0072668E /* NSObject+MTLComparisonAdditions.m */,
+ D0BFC36D17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h */,
+ D0BFC36E17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m */,
D0F117471614C5600092520B /* NSValueTransformer+MTLPredefinedTransformerAdditions.h */,
D0F117481614C5600092520B /* NSValueTransformer+MTLPredefinedTransformerAdditions.m */,
);
@@ -585,6 +597,7 @@
D01BD09D16CB432D00EC95C7 /* MTLJSONAdapter.h in Headers */,
D01BD0AF16CB52E800EC95C7 /* MTLModel+NSCoding.h in Headers */,
D0E51937170A06CF00E8897B /* MTLManagedObjectAdapter.h in Headers */,
+ D0BFC36F17476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -602,6 +615,7 @@
D01BD09E16CB432D00EC95C7 /* MTLJSONAdapter.h in Headers */,
D01BD0B016CB52E800EC95C7 /* MTLModel+NSCoding.h in Headers */,
D0E51938170A06CF00E8897B /* MTLManagedObjectAdapter.h in Headers */,
+ D0BFC37017476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -857,6 +871,7 @@
D01BD0B116CB52E800EC95C7 /* MTLModel+NSCoding.m in Sources */,
D058FE2116EFB3D2009DFB47 /* MTLReflection.m in Sources */,
D0E51939170A06CF00E8897B /* MTLManagedObjectAdapter.m in Sources */,
+ D0BFC37117476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -877,6 +892,7 @@
D021D938170F806B00C37E36 /* TestModel.xcdatamodeld in Sources */,
D021D944170F878E00C37E36 /* MTLCoreDataTestModels.m in Sources */,
D0ABD7A11746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m in Sources */,
+ D0BFC36717476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -896,6 +912,7 @@
D01BD0B216CB52E800EC95C7 /* MTLModel+NSCoding.m in Sources */,
D058FE2216EFB3D2009DFB47 /* MTLReflection.m in Sources */,
D0E5193A170A06CF00E8897B /* MTLManagedObjectAdapter.m in Sources */,
+ D0BFC37217476B4700F5DC5D /* NSValueTransformer+MTLInversionAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -916,6 +933,7 @@
D021D939170F806B00C37E36 /* TestModel.xcdatamodeld in Sources */,
D021D945170F878E00C37E36 /* MTLCoreDataTestModels.m in Sources */,
D0ABD7A21746D56E006BEA7D /* MTLManagedObjectAdapterSpec.m in Sources */,
+ D0BFC36817476A5F00F5DC5D /* MTLValueTransformerInversionAdditionsSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -14,4 +14,5 @@
#import <Mantle/NSArray+MTLManipulationAdditions.h>
#import <Mantle/NSDictionary+MTLManipulationAdditions.h>
#import <Mantle/NSObject+MTLComparisonAdditions.h>
+#import <Mantle/NSValueTransformer+MTLInversionAdditions.h>
#import <Mantle/NSValueTransformer+MTLPredefinedTransformerAdditions.h>
@@ -0,0 +1,21 @@
+//
+// NSValueTransformer+MTLInversionAdditions.h
+// Mantle
+//
+// Created by Justin Spahr-Summers on 2013-05-18.
+// Copyright (c) 2013 GitHub. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSValueTransformer (MTLInversionAdditions)
+
+// Flips the direction of the receiver's transformation, such that
+// -transformedValue: will become -reverseTransformedValue:, and vice-versa.
+//
+// The receiver must allow reverse transformation.
+//
+// Returns an inverted transformer.
+- (NSValueTransformer *)mtl_invertedTransformer;
+
+@end
@@ -0,0 +1,24 @@
+//
+// NSValueTransformer+MTLInversionAdditions.m
+// Mantle
+//
+// Created by Justin Spahr-Summers on 2013-05-18.
+// Copyright (c) 2013 GitHub. All rights reserved.
+//
+
+#import "NSValueTransformer+MTLInversionAdditions.h"
+#import "MTLValueTransformer.h"
+
+@implementation NSValueTransformer (MTLInversionAdditions)
+
+- (NSValueTransformer *)mtl_invertedTransformer {
+ NSParameterAssert(self.class.allowsReverseTransformation);
+
+ return [MTLValueTransformer reversibleTransformerWithForwardBlock:^(id value) {
+ return [self reverseTransformedValue:value];
+ } reverseBlock:^(id value) {
+ return [self transformedValue:value];
+ }];
+}
+
+@end
@@ -0,0 +1,57 @@
+//
+// MTLValueTransformerInversionAdditionsSpec.m
+// Mantle
+//
+// Created by Justin Spahr-Summers on 2013-05-18.
+// Copyright (c) 2013 GitHub. All rights reserved.
+//
+
+@interface TestTransformer : NSValueTransformer
+@end
+
+@implementation TestTransformer
+
++ (BOOL)allowsReverseTransformation {
+ return YES;
+}
+
++ (Class)transformedValueClass {
+ return NSString.class;
+}
+
+- (id)transformedValue:(id)value {
+ return @"forward";
+}
+
+- (id)reverseTransformedValue:(id)value {
+ return @"reverse";
+}
+
+@end
+
+SpecBegin(MTLValueTransformerInversionAdditions)
+
+__block TestTransformer *transformer;
+
+beforeEach(^{
+ transformer = [[TestTransformer alloc] init];
+ expect(transformer).notTo.beNil();
+});
+
+it(@"should invert a transformer", ^{
+ NSValueTransformer *inverted = transformer.mtl_invertedTransformer;
+ expect(inverted).notTo.beNil();
+
+ expect([inverted transformedValue:nil]).to.equal(@"reverse");
+ expect([inverted reverseTransformedValue:nil]).to.equal(@"forward");
+});
+
+it(@"should invert an inverted transformer", ^{
+ NSValueTransformer *inverted = transformer.mtl_invertedTransformer.mtl_invertedTransformer;
+ expect(inverted).notTo.beNil();
+
+ expect([inverted transformedValue:nil]).to.equal(@"forward");
+ expect([inverted reverseTransformedValue:nil]).to.equal(@"reverse");
+});
+
+SpecEnd

0 comments on commit df5f950

Please sign in to comment.