Skip to content

Commit 48fc1ff

Browse files
authored
Merge pull request #378 from q231950/master
[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))
2 parents aaea23b + c816e7d commit 48fc1ff

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

mogenerator.h

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
- (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_ verbose:(BOOL)verbose_;
1818
@end
1919

20+
@interface NSEntityDescription (userInfo)
21+
/// @return Whether or not the entity should be ignored during code generation
22+
- (BOOL)isIgnored;
23+
@end
24+
2025
@interface NSEntityDescription (customBaseClass)
2126
- (BOOL)hasCustomClass;
2227
- (BOOL)hasSuperentity;

mogenerator.m

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
static const NSString *const kAdditionalImportsKey = @"additionalImports";
2020
static const NSString *const kCustomBaseClass = @"mogenerator.customBaseClass";
2121
static const NSString *const kReadOnly = @"mogenerator.readonly";
22+
static const NSString *const kIgnored = @"mogenerator.ignore";
2223

2324
@interface NSEntityDescription (fetchedPropertiesAdditions)
2425
- (NSDictionary*)fetchedPropertiesByName;
@@ -135,6 +136,15 @@ - (NSArray*)entitiesWithACustomSubclassInConfiguration:(NSString*)configuration_
135136
}
136137
@end
137138

139+
@implementation NSEntityDescription (userInfo)
140+
- (BOOL)isIgnored {
141+
NSString *readonlyUserinfoValue = [[self userInfo] objectForKey:kIgnored];
142+
if (readonlyUserinfoValue != nil) {
143+
return YES;
144+
}
145+
return NO;
146+
}
147+
@end
138148

139149
@implementation NSEntityDescription (customBaseClass)
140150
- (BOOL)hasCustomBaseCaseImport {
@@ -1192,6 +1202,9 @@ - (int)application:(DDCliApplication*)app runWithArguments:(NSArray*)arguments {
11921202
NSArray *entitiesWithCustomSubclass = [model entitiesWithACustomSubclassInConfiguration:configuration verbose:YES];
11931203
for (NSEntityDescription *entity in entitiesWithCustomSubclass)
11941204
{
1205+
if ([entity isIgnored]) {
1206+
continue;
1207+
}
11951208
NSString *generatedMachineH = [machineH executeWithObject:entity sender:nil];
11961209
NSString *generatedMachineM = [machineM executeWithObject:entity sender:nil];
11971210
NSString *generatedHumanH = [humanH executeWithObject:entity sender:nil];

test/Rakefile

+7
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,25 @@ def gen_and_compile_swift(mogenPath, extra_mogen_args)
4545
puts run_or_die './testbin'
4646
end
4747

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

4954
desc 'Generate, Compile and Run Objective-C'
5055
task :objc do
5156
Rake::Task[:clean].execute
5257
gen_and_compile_objc(MOGENERATOR_PATH, '', '')
58+
assert_entity_user_info_respected
5359
Rake::Task[:clean].execute
5460
end
5561

5662
desc 'Generate, Compile and Run Swift'
5763
task :swift do
5864
Rake::Task[:clean].execute
5965
gen_and_compile_swift(MOGENERATOR_PATH, '')
66+
assert_entity_user_info_respected
6067
Rake::Task[:clean].execute
6168
end
6269

test/test.xcdatamodel/contents

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<relationship name="children" optional="YES" toMany="YES" deletionRule="Cascade" destinationEntity="Child" indexed="YES" syncable="YES"/>
5656
<relationship name="orderedChildren" optional="YES" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="Child" inverseName="parent" inverseEntity="Child" indexed="YES" syncable="YES"/>
5757
</entity>
58+
<entity name="Uncle" representedClassName="UncleMO" parentEntity="Human" syncable="YES">
59+
<attribute name="attribute" optional="YES" attributeType="String" syncable="YES"/>
60+
<userInfo>
61+
<entry key="mogenerator.ignore" value="value"/>
62+
</userInfo>
63+
</entity>
5864
<fetchRequest name="allHumans" entity="Human"/>
5965
<fetchRequest name="byHumanName" entity="Human" predicateString="humanName == $humanName"/>
6066
<fetchRequest name="byParent" entity="Child" predicateString="parent == $parent"/>
@@ -69,5 +75,6 @@
6975
<element name="EntityWithBaseClass" positionX="342" positionY="18" width="128" height="60"/>
7076
<element name="Human" positionX="169" positionY="18" width="128" height="105"/>
7177
<element name="Parent" positionX="34" positionY="114" width="128" height="270"/>
78+
<element name="Uncle" positionX="243" positionY="-36" width="128" height="60"/>
7279
</elements>
7380
</model>

0 commit comments

Comments
 (0)