Skip to content

Commit

Permalink
Merge pull request #104 from sixten/master
Browse files Browse the repository at this point in the history
[NEW] Option to limit processing to a specified configuration. (Sixten Otto)
  • Loading branch information
rentzsch committed Apr 18, 2012
2 parents 00e21f6 + bb7cbdd commit 1a86e88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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

0 comments on commit 1a86e88

Please sign in to comment.