Skip to content

Commit

Permalink
Merge pull request #135 from davidAtGVC/master
Browse files Browse the repository at this point in the history
[NEW] --base-class-import option to specify base classes that are in another location (subproject). David Aspinall
  • Loading branch information
rentzsch committed Oct 26, 2012
2 parents 2742b2e + 7d2e730 commit 6746f96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions mogenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
NSManagedObjectModel *model;
NSString *configuration;
NSString *baseClass;
NSString *baseClassImport;
NSString *baseClassForce;
NSString *includem;
NSString *includeh;
Expand Down
13 changes: 12 additions & 1 deletion mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

static NSString * const kTemplateVar = @"TemplateVar";
NSString *gCustomBaseClass;
NSString *gCustomBaseClassImport;
NSString *gCustomBaseClassForced;

@interface NSEntityDescription (fetchedPropertiesAdditions)
Expand Down Expand Up @@ -72,6 +73,12 @@ - (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString *)configuration


@implementation NSEntityDescription (customBaseClass)
- (BOOL)hasCustomBaseCaseImport {
return gCustomBaseClassImport == nil ? NO : YES;
}
- (NSString *)baseClassImport {
return gCustomBaseClassImport;
}
- (BOOL)hasCustomSuperentity {
NSString *forcedBaseClass = [self forcedCustomBaseClass];
if (!forcedBaseClass) {
Expand Down Expand Up @@ -499,7 +506,8 @@ - (void) application: (DDCliApplication *) app
// Long Short Argument options
{@"model", 'm', DDGetoptRequiredArgument},
{@"configuration", 'C', DDGetoptRequiredArgument},
{@"base-class", 0, DDGetoptRequiredArgument},
{@"base-class", 0, DDGetoptRequiredArgument},
{@"base-class-import", 0, DDGetoptRequiredArgument},
{@"base-class-force", 0, DDGetoptRequiredArgument},
// For compatibility:
{@"baseClass", 0, DDGetoptRequiredArgument},
Expand Down Expand Up @@ -530,6 +538,7 @@ - (void) printUsage;
" -m, --model MODEL Path to model\n"
" -C, --configuration CONFIG Only consider entities included in the named configuration\n"
" --base-class CLASS Custom base class\n"
" --base-class-import TEXT Imports base class as #import TEXT\n"
" --base-class-force CLASS Same as --base-class except will force all entities to have the specified base class. Even if a super entity exists\n"
" --includem FILE Generate aggregate include file for .m files for both human and machine generated source files\n"
" --includeh FILE Generate aggregate include file for .h files for human generated source files only\n"
Expand Down Expand Up @@ -695,8 +704,10 @@ - (int) application: (DDCliApplication *) app
if(baseClassForce) {
gCustomBaseClassForced = [baseClassForce retain];
gCustomBaseClass = gCustomBaseClassForced;
gCustomBaseClassImport = [baseClassImport retain];
} else {
gCustomBaseClass = [baseClass retain];
gCustomBaseClassImport = [baseClassImport retain];
}

NSString * mfilePath = includem;
Expand Down
2 changes: 1 addition & 1 deletion templates/machine.h.motemplate
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Make changes to <$managedObjectClassName$>.h instead.

#import <CoreData/CoreData.h>
<$if hasCustomSuperentity$>#import "<$customSuperentity$>.h"<$endif$>
<$if hasCustomSuperentity$>#import <$if hasCustomBaseCaseImport$><$baseClassImport$><$else$>"<$customSuperentity$>.h"<$endif$><$endif$>

extern const struct <$managedObjectClassName$>Attributes {<$foreach Attribute noninheritedAttributes do$>
<$if TemplateVar.arc$>__unsafe_unretained<$endif$> NSString *<$Attribute.name$>;<$endforeach do$>
Expand Down

0 comments on commit 6746f96

Please sign in to comment.