From a71b0835e5db93dd6be8b857541980f2f826a4ae Mon Sep 17 00:00:00 2001 From: Martin Kim Dung-Pham Date: Wed, 26 Sep 2018 08:47:31 +0200 Subject: [PATCH] Move ignored flag into entities as `mogenerator.ignore` user info key --- mogenerator.h | 2 +- mogenerator.m | 18 ++++++++++-------- test/Rakefile | 12 ++++-------- test/test.xcdatamodel/contents | 3 +++ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/mogenerator.h b/mogenerator.h index 5aed9c97..003ebb4a 100644 --- a/mogenerator.h +++ b/mogenerator.h @@ -27,6 +27,7 @@ - (NSString*)additionalHeaderFileName; - (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_; - (NSArray*)prettyFetchRequests; +- (BOOL)isIgnored; @end @interface NSAttributeDescription (typing) @@ -67,7 +68,6 @@ NSString *baseClass; NSString *baseClassImport; NSString *baseClassForce; - NSString *ignoredEntities; NSString *includem; NSString *includeh; NSString *templatePath; diff --git a/mogenerator.m b/mogenerator.m index 0139e1d4..61ad5d08 100644 --- a/mogenerator.m +++ b/mogenerator.m @@ -19,6 +19,7 @@ static const NSString *const kAdditionalImportsKey = @"additionalImports"; static const NSString *const kCustomBaseClass = @"mogenerator.customBaseClass"; static const NSString *const kReadOnly = @"mogenerator.readonly"; +static const NSString *const kIgnored = @"mogenerator.ignore"; @interface NSEntityDescription (fetchedPropertiesAdditions) - (NSDictionary*)fetchedPropertiesByName; @@ -418,6 +419,14 @@ - (NSArray*)prettyFetchRequests { } return result; } + +- (BOOL)isIgnored { + NSString *readonlyUserinfoValue = [[self userInfo] objectForKey:kIgnored]; + if (readonlyUserinfoValue != nil) { + return YES; + } + return NO; +} @end @implementation NSAttributeDescription (typing) @@ -796,7 +805,6 @@ - (void)application:(DDCliApplication*)app {@"base-class", 0, DDGetoptRequiredArgument}, {@"base-class-import", 0, DDGetoptRequiredArgument}, {@"base-class-force", 0, DDGetoptRequiredArgument}, - {@"ignored-entities", 0, DDGetoptRequiredArgument}, // For compatibility: {@"baseClass", 0, DDGetoptRequiredArgument}, {@"includem", 0, DDGetoptRequiredArgument}, @@ -851,7 +859,6 @@ - (void)printUsage { "--base-class-force CLASS Same as --base-class except will force all entities to\n" " have the specified base class. Even if a super entity\n" " exists\n" - "--ignored-entities LIST Comma separated list of of entity names. Entities will be ignored when generating classes\n" "--includem FILE Generate aggregate include file for .m files for both\n" " human and machine generated source files\n" "--includeh FILE Generate aggregate include file for .h files for human\n" @@ -1048,11 +1055,6 @@ - (void)validateOutputPath:(NSString*)path forType:(NSString*)type } } -- (BOOL)isIgnoredEntity:(NSString *)entityName { - NSArray *entities = [ignoredEntities componentsSeparatedByString:@","]; - return [entities containsObject:entityName] || [entities containsObject:[NSString stringWithFormat:@"_%@", entityName]]; -} - - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { if (_help) { [self printUsage]; @@ -1199,7 +1201,7 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments { NSArray *entitiesWithCustomSubclass = [model entitiesWithACustomSubclassInConfiguration:configuration verbose:YES]; for (NSEntityDescription *entity in entitiesWithCustomSubclass) { - if ([self isIgnoredEntity:entity.name]) { + if ([entity isIgnored]) { continue; } NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil]; diff --git a/test/Rakefile b/test/Rakefile index 60625cff..6c1b1717 100644 --- a/test/Rakefile +++ b/test/Rakefile @@ -26,9 +26,7 @@ run_or_die 'xcodebuild -project ../mogenerator.xcodeproj -scheme mogenerator cle run_or_die 'xcodebuild -project ../mogenerator.xcodeproj -scheme mogenerator' def gen_and_compile_objc(mogenPath, extra_mogen_args, extra_llvm_args) - status = '*** Testing Objective-C' - status << ' with parameters' if extra_mogen_args.length > 0 - puts status + puts = '*** Testing Objective-C' ENV['MOMC_NO_INVERSE_RELATIONSHIP_WARNINGS'] = '1' run_or_die "#{mogenPath.gsub(/ /, '\\ ')} --model test.xcdatamodel --output MOs --baseClass MyBaseClass #{extra_mogen_args}" run_or_die 'cp ./objc/Gender.* ./objc/MyBaseClass.* MOs' @@ -62,13 +60,11 @@ task :swift do Rake::Task[:clean].execute end -desc 'Generate, Compile and Run with parameters' +desc 'Generate, Compile and test ignored entities' task :objc do Rake::Task[:clean].execute - gen_and_compile_objc(MOGENERATOR_PATH, '--ignored-entities Uncle,Aunt', '') - includes_uncle = Dir.entries('./MOs').any? do |file| - file.include?('Uncle') || file.include?('Aunt') - end + gen_and_compile_objc(MOGENERATOR_PATH, '', '') + includes_uncle = Dir.entries('./MOs').any? { |file| file.include?('Uncle') } raise 'Failed: Ignored entities should not be generated' if includes_uncle Rake::Task[:clean].execute end diff --git a/test/test.xcdatamodel/contents b/test/test.xcdatamodel/contents index a62d35c2..73ba0625 100644 --- a/test/test.xcdatamodel/contents +++ b/test/test.xcdatamodel/contents @@ -57,6 +57,9 @@ + + +