Skip to content
This repository

Allow per-entity definition of custom base class #94

Merged
merged 1 commit into from about 2 years ago

2 participants

Trevor Squires Jonathan 'Wolf' Rentzsch
Trevor Squires

I often use a custom base class to supply general utility routines for my managed objects.

Occasionally those utility routines are specific to a certain subset of my Entities.

This pull request allows you to override the custom base class per-Entity by way of a key/value pair in the Entity userInfo (mogenerator.customBaseClass).

It treats the userInfo-defined custom base class as a 'forced' custom base class for just that Entity, overriding any command line argument for --base-class-force.

Jonathan 'Wolf' Rentzsch
Owner

Looks good, thanks!

Jonathan 'Wolf' Rentzsch rentzsch merged commit 029b653 into from
Jonathan 'Wolf' Rentzsch rentzsch closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
1  mogenerator.h
@@ -23,6 +23,7 @@
23 23
 @interface NSEntityDescription (customBaseClass)
24 24
 - (BOOL)hasCustomSuperentity;
25 25
 - (NSString*)customSuperentity;
  26
+- (NSString*)forcedCustomBaseClass;
26 27
 - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_;
27 28
 - (NSArray*)prettyFetchRequests;
28 29
 @end
9  mogenerator.m
@@ -67,7 +67,8 @@ - (BOOL)hasCustomSuperentity {
67 67
 	}
68 68
 }
69 69
 - (NSString*)customSuperentity {
70  
-	if(!gCustomBaseClassForced) {
  70
+	NSString *forcedBaseClass = [self forcedCustomBaseClass];
  71
+	if(!forcedBaseClass) {
71 72
 		NSEntityDescription *superentity = [self superentity];
72 73
 		if (superentity) {
73 74
 			return [superentity managedObjectClassName];
@@ -75,9 +76,13 @@ - (NSString*)customSuperentity {
75 76
 			return gCustomBaseClass ? gCustomBaseClass : @"NSManagedObject";
76 77
 		}
77 78
 	} else {
78  
-		return gCustomBaseClassForced;
  79
+		return forcedBaseClass;
79 80
 	}
80 81
 }
  82
+- (NSString*)forcedCustomBaseClass {
  83
+	NSString* userInfoCustomBaseClass = [[self userInfo] objectForKey:@"mogenerator.customBaseClass"];
  84
+	return userInfoCustomBaseClass ? userInfoCustomBaseClass : gCustomBaseClassForced;
  85
+}
81 86
 /** @TypeInfo NSAttributeDescription */
82 87
 - (NSArray*)noninheritedAttributes {
83 88
 	NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.