Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow per-entity definition of custom base class #94

Merged
merged 1 commit into from

2 participants

@protocool

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.

@rentzsch
Owner

Looks good, thanks!

@rentzsch rentzsch merged commit 029b653 into rentzsch:master
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.
Showing with 8 additions and 2 deletions.
  1. +1 −0  mogenerator.h
  2. +7 −2 mogenerator.m
View
1  mogenerator.h
@@ -23,6 +23,7 @@
@interface NSEntityDescription (customBaseClass)
- (BOOL)hasCustomSuperentity;
- (NSString*)customSuperentity;
+- (NSString*)forcedCustomBaseClass;
- (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_;
- (NSArray*)prettyFetchRequests;
@end
View
9 mogenerator.m
@@ -67,7 +67,8 @@ - (BOOL)hasCustomSuperentity {
}
}
- (NSString*)customSuperentity {
- if(!gCustomBaseClassForced) {
+ NSString *forcedBaseClass = [self forcedCustomBaseClass];
+ if(!forcedBaseClass) {
NSEntityDescription *superentity = [self superentity];
if (superentity) {
return [superentity managedObjectClassName];
@@ -75,9 +76,13 @@ - (NSString*)customSuperentity {
return gCustomBaseClass ? gCustomBaseClass : @"NSManagedObject";
}
} else {
- return gCustomBaseClassForced;
+ return forcedBaseClass;
}
}
+- (NSString*)forcedCustomBaseClass {
+ NSString* userInfoCustomBaseClass = [[self userInfo] objectForKey:@"mogenerator.customBaseClass"];
+ return userInfoCustomBaseClass ? userInfoCustomBaseClass : gCustomBaseClassForced;
+}
/** @TypeInfo NSAttributeDescription */
- (NSArray*)noninheritedAttributes {
NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]];
Something went wrong with that request. Please try again.