Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Added cycle detection support

- To run a cycle detection on strong (non-transient) relationships, include the following tag into the template:
<$checkNonTransientRelationshipCycles $>
- This will cause mogenerator to exit with failure status if cycles are found.
  • Loading branch information...
commit 4e9f4f5cd77a7da7176da1a5221d11a38618e3d6 1 parent d5c21ba
@nzhuk nzhuk authored
View
2  contributed templates/Nikita Zhuk/ponso/templates/machine.h.motemplate
@@ -10,7 +10,7 @@
#import <Foundation/Foundation.h>
#import "ModelObject.h"
-
+<$checkNonTransientRelationshipCycles $>
<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
<$endforeach do$>
View
4 ponso/MKCNSEntityDescriptionAdditions.h
@@ -25,4 +25,8 @@
/** @TypeInfo NSAttributeDescription */
@property(nonatomic, readonly) NSArray *noninheritedRelationshipsInIDKeyPathTopologicalOrder;
+// Checks if the managed object model of the receiver contains cycles in non-transient relationships.
+// If cycles are found, an exception is raised.
+- (void)checkNonTransientRelationshipCycles;
+
@end
View
29 ponso/MKCNSEntityDescriptionAdditions.m
@@ -38,6 +38,22 @@ - (BOOL)includeRelationship:(NSRelationshipDescription *)relationship
@end
+@interface MKCNSRelationshipDescriptionNonTransientDependencyFilter : NSObject <MKCNSRelationshipDescriptionDependencyFilter> @end
+@implementation MKCNSRelationshipDescriptionNonTransientDependencyFilter
+
+- (BOOL)includeRelationship:(NSRelationshipDescription *)relationship
+{
+ if([[relationship entity] isEqual:[relationship destinationEntity]])
+ return NO;
+
+ if([relationship isTransient])
+ return NO;
+
+ return YES;
+}
+
+@end
+
@implementation NSEntityDescription(MKCNSEntityDescriptionAdditions)
/** @TypeInfo NSAttributeDescription */
@@ -80,4 +96,17 @@ - (NSArray*)noninheritedRelationshipsInIDKeyPathTopologicalOrder
return sortedRelationships;
}
+- (void)checkNonTransientRelationshipCycles
+{
+ id dependencyFilter = [[[MKCNSRelationshipDescriptionNonTransientDependencyFilter alloc] init] autorelease];
+ NSArray *entities = [[self managedObjectModel] entitiesInTopologicalOrderUsingDependencyFilter:dependencyFilter];
+
+ if(entities == nil)
+ {
+ NSString *desc = @"Cycles were found in non-transient relationships.";
+
+ [[NSException exceptionWithName:@"StrongRelationshipCyclesFoundException" reason:desc userInfo:nil] raise];
+ }
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.