Skip to content

Commit

Permalink
Merge pull request #378 from q231950/master
Browse files Browse the repository at this point in the history
[NEW] To better interoperate with Xcode's newish built-in code generation, mogenerator will now ignore any entity which has a userInfo that has an entry with an `mogenerator.ignore` key. ([Martin Kim Dung-Pham](#378))
  • Loading branch information
rentzsch authored Oct 1, 2018
2 parents aaea23b + c816e7d commit 48fc1ff
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mogenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_ verbose:(BOOL)verbose_;
@end

@interface NSEntityDescription (userInfo)
/// @return Whether or not the entity should be ignored during code generation
- (BOOL)isIgnored;
@end

@interface NSEntityDescription (customBaseClass)
- (BOOL)hasCustomClass;
- (BOOL)hasSuperentity;
Expand Down
13 changes: 13 additions & 0 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 @@ -135,6 +136,15 @@ - (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_
}
@end

@implementation NSEntityDescription (userInfo)
- (BOOL)isIgnored {
NSString *readonlyUserinfoValue = [[self userInfo] objectForKey:kIgnored];
if (readonlyUserinfoValue != nil) {
return YES;
}
return NO;
}
@end

@implementation NSEntityDescription (customBaseClass)
- (BOOL)hasCustomBaseCaseImport {
Expand Down Expand Up @@ -1192,6 +1202,9 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments {
NSArray *entitiesWithCustomSubclass = [model entitiesWithACustomSubclassInConfiguration:configuration verbose:YES];
for (NSEntityDescription *entity in entitiesWithCustomSubclass)
{
if ([entity isIgnored]) {
continue;
}
NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil];
NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil];
NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil];
Expand Down
7 changes: 7 additions & 0 deletions test/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ def gen_and_compile_swift(mogenPath, extra_mogen_args)
puts run_or_die './testbin'
end

def assert_entity_user_info_respected
# mogenerator.ignore
includes_uncle = Dir.entries('./MOs').any? { |file| file.include?('Uncle') }
raise 'Failed: Ignored entities should not be generated' if includes_uncle
end

desc 'Generate, Compile and Run Objective-C'
task :objc do
Rake::Task[:clean].execute
gen_and_compile_objc(MOGENERATOR_PATH, '', '')
assert_entity_user_info_respected
Rake::Task[:clean].execute
end

desc 'Generate, Compile and Run Swift'
task :swift do
Rake::Task[:clean].execute
gen_and_compile_swift(MOGENERATOR_PATH, '')
assert_entity_user_info_respected
Rake::Task[:clean].execute
end

Expand Down
7 changes: 7 additions & 0 deletions test/test.xcdatamodel/contents
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<relationship name="children" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="Child" indexed="YES" syncable="YES"/>
<relationship name="orderedChildren" optional="YES" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="Child" inverseName="parent" inverseEntity="Child" indexed="YES" syncable="YES"/>
</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"/>
<fetchRequest name="byParent" entity="Child" predicateString="parent == $parent"/>
Expand All @@ -69,5 +75,6 @@
<element name="EntityWithBaseClass" positionX="342" positionY="18" width="128" height="60"/>
<element name="Human" positionX="169" positionY="18" width="128" height="105"/>
<element name="Parent" positionX="34" positionY="114" width="128" height="270"/>
<element name="Uncle" positionX="243" positionY="-36" width="128" height="60"/>
</elements>
</model>

0 comments on commit 48fc1ff

Please sign in to comment.