-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathobjc-repo-m.ejs
69 lines (59 loc) · 2.69 KB
/
objc-repo-m.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// <%- meta.objcRepoName %>.m
//
#import "<%- meta.objcRepoName %>.h"
@implementation <%- meta.objcRepoName %>
+ (instancetype)repository {
return [self repositoryWithClassName:@"<%- meta.pluralName %>"];
}
- (<%- meta.objcModelName %> *)modelWithDictionary:(NSDictionary *)dictionary {
return (<%- meta.objcModelName %> *)[super modelWithDictionary:dictionary];
}
- (SLRESTContract *)contract {
SLRESTContract *contract = [super contract];
<% meta.methods.forEach(function (method) {
if (method.objcGenerated) {
-%>
[contract addItem:[SLRESTContractItem itemWithPattern:[NSString stringWithFormat:@"/%@<%- method.routes[0].path %>", self.className]
verb:@"<%- method.routes[0].verb.toUpperCase() %>"]
forMethod:[NSString stringWithFormat:@"%@.<%- method.name %>", self.className]];
<% }
});
-%>
return contract;
}
<% meta.objcMethods.forEach(function(method) { -%>
- <%- method.prototype %> {
[self invokeStaticMethod:@"<%- method.rawName %>"
parameters:@{ <%- method.paramAssignments %> }
<% if (method.bodyParamAssignments) { -%>
bodyParameters:<%- method.bodyParamAssignments %>
<% } -%>
success:^(id value) {
<% if (method.objcReturnType === meta.objcModelName) { -%>
NSAssert([value isKindOfClass:[NSDictionary class]], @"Received non-Dictionary: %@", value);
success((<%- meta.objcModelName %>*)[self modelWithDictionary:value]);
<% } else if (method.objcReturnType === 'NSDictionary') { -%>
NSAssert([value isKindOfClass:[NSDictionary class]], @"Received non-Dictionary: %@", value);
success((NSDictionary *)value);
<% } else if (method.objcReturnType === 'NSArray') { -%>
NSAssert([value isKindOfClass:[NSArray class]], @"Received non-Array: %@", value);
NSMutableArray *models = [NSMutableArray array];
[value enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[models addObject:[self modelWithDictionary:obj]];
}];
success(models);
<% } else if (method.objcReturnType === 'BOOL') { -%>
success(((NSNumber *)value[@"<%- method.returnArg %>"]).boolValue);
<% } else if (method.objcReturnType === 'NSNumber') { -%>
success(((NSNumber *)value[@"<%- method.returnArg %>"]));
<% } else if (method.objcReturnType === 'void') { -%>
success();
<% } -%>
}
failure:failure];
}
<%
});
-%>
@end