Skip to content

Commit

Permalink
Move ignored flag into entities
Browse files Browse the repository at this point in the history
as `mogenerator.ignore` user info key
  • Loading branch information
Martin Kim Dung-Pham committed Sep 26, 2018
1 parent 00aa081 commit a71b083
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mogenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- (NSString*)additionalHeaderFileName;
- (void)_processPredicate:(NSPredicate*)predicate_ bindings:(NSMutableArray*)bindings_;
- (NSArray*)prettyFetchRequests;
- (BOOL)isIgnored;
@end

@interface NSAttributeDescription (typing)
Expand Down Expand Up @@ -67,7 +68,6 @@
NSString *baseClass;
NSString *baseClassImport;
NSString *baseClassForce;
NSString *ignoredEntities;
NSString *includem;
NSString *includeh;
NSString *templatePath;
Expand Down
18 changes: 10 additions & 8 deletions mogenerator.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -1048,11 +1055,6 @@ - (void)validateOutputPath:(NSString*)path forType:(NSString*)type
}
}

- (BOOL)isIgnoredEntity:(NSString *)entityName {
NSArray<NSString *> *entities = [ignoredEntities componentsSeparatedByString:@","];
return [entities containsObject:entityName] || [entities containsObject:[NSString stringWithFormat:@"_%@", entityName]];
}

- (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments {
if (_help) {
[self printUsage];
Expand Down Expand Up @@ -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];
Expand Down
12 changes: 4 additions & 8 deletions test/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/test.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
</entity>
<entity name="Uncle" representedClassName="UncleMO" parentEntity="Human" syncable="YES">
<attribute name="attribute" optional="YES" attributeType="String" syncable="YES"/>
<userInfo>
<entry key="mogenerator.ignore" value="value"/>
</userInfo>
</entity>
<fetchRequest name="allHumans" entity="Human"/>
<fetchRequest name="byHumanName" entity="Human" predicateString="humanName == $humanName"/>
Expand Down

0 comments on commit a71b083

Please sign in to comment.