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

Option to limit processing to a specified configuration #104

Merged
merged 1 commit into from
Apr 18, 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
3 changes: 2 additions & 1 deletion mogenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "DDCommandLineInterface.h"

@interface NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_;
- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString *)configuration_ verbose:(BOOL)verbose_;
@end

@interface NSEntityDescription (customBaseClass)
Expand Down Expand Up @@ -56,6 +56,7 @@
NSString *origModelBasePath;
NSString *tempMOMPath;
NSManagedObjectModel *model;
NSString *configuration;
NSString *baseClass;
NSString *baseClassForce;
NSString *includem;
Expand Down
28 changes: 22 additions & 6 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,28 @@ - (NSDictionary *)fetchedPropertiesByName
@end

@implementation NSManagedObjectModel (entitiesWithACustomSubclassVerbose)
- (NSArray*)entitiesWithACustomSubclassVerbose:(BOOL)verbose_ {
- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString *)configuration_ verbose:(BOOL)verbose_ {
NSMutableArray *result = [NSMutableArray array];
NSArray* allEntities = nil;

if(verbose_ && [[self entities] count] == 0){
ddprintf(@"No entities found in model. No files will be generated.\n(model description: %@)\n", self);
if(nil == configuration_) {
allEntities = [self entities];
}
else if(NSNotFound != [[self configurations] indexOfObject:configuration_]){
allEntities = [self entitiesForConfiguration:configuration_];
}
else {
if(verbose_){
ddprintf(@"No configuration %@ found in model. No files will be generated.\n(model configurations: %@)\n", configuration_, [self configurations]);
}
return nil;
}

if(verbose_ && [allEntities count] == 0){
ddprintf(@"No entities found in model (or in specified configuration). No files will be generated.\n(model description: %@)\n", self);
}

nsenumerate ([self entities], NSEntityDescription, entity) {
nsenumerate (allEntities, NSEntityDescription, entity) {
NSString *entityClassName = [entity managedObjectClassName];

if ([entityClassName isEqualToString:@"NSManagedObject"] || [entityClassName isEqualToString:gCustomBaseClass]){
Expand Down Expand Up @@ -458,6 +472,7 @@ - (void) application: (DDCliApplication *) app
{
// Long Short Argument options
{@"model", 'm', DDGetoptRequiredArgument},
{@"configuration", 'C', DDGetoptRequiredArgument},
{@"base-class", 0, DDGetoptRequiredArgument},
{@"base-class-force", 0, DDGetoptRequiredArgument},
// For compatibility:
Expand Down Expand Up @@ -487,6 +502,7 @@ - (void) printUsage;
ddprintf(@"%@: Usage [OPTIONS] <argument> [...]\n", DDCliApp);
printf("\n"
" -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-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"
Expand Down Expand Up @@ -695,7 +711,7 @@ - (int) application: (DDCliApplication *) app
}
}
}
nsenumerate ([model entitiesWithACustomSubclassVerbose:NO], NSEntityDescription, entity) {
nsenumerate ([model entitiesWithACustomSubclassInConfiguration:configuration verbose:NO], NSEntityDescription, entity) {
[entityFilesByName removeObjectForKey:[entity managedObjectClassName]];
}
nsenumerate(entityFilesByName, NSSet, ophanedFiles) {
Expand Down Expand Up @@ -753,7 +769,7 @@ - (int) application: (DDCliApplication *) app
*machineMFiles = [NSMutableArray array],
*machineHFiles = [NSMutableArray array];

nsenumerate ([model entitiesWithACustomSubclassVerbose:YES], NSEntityDescription, entity) {
nsenumerate ([model entitiesWithACustomSubclassInConfiguration:configuration verbose:YES], NSEntityDescription, entity) {
NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil];
NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil];
NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil];
Expand Down