Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command line option to specify the import for a custom base class rather than assuming it is local to the project #135

Merged
merged 1 commit into from Oct 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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