28 #import <ActiveSupportKit/ActiveSupportKit.h>
32 - (NSManagedObjectID *)objectIDForResource:(
ARResource *)resource withContext:(NSManagedObjectContext *)context
35 NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
36 return [
self newObjectIDForEntity:entity referenceObject:[resource
ID]];
39 - (NSManagedObjectID *)objectIDForCachedResource:(
ARResource *)resource withContext:(NSManagedObjectContext *)context
46 - (
ARResource *)cachedResourceForObjectID:(NSManagedObjectID *)objectID error:(NSError **)outError
51 NSNumber *ID = [
self referenceObjectForObjectID:objectID];
60 if (outError && *outError == nil)
73 NSDate *updatedAt = ASDateFromRFC3339String(ASNilForNull([[resource attributes] objectForKey:
@"updated_at"]));
76 version = [updatedAt timeIntervalSinceReferenceDate] * 1000;
85 - (void)refreshObject:(NSManagedObject *)object
88 [[object managedObjectContext] refreshObject:object mergeChanges:NO];
91 - (NSDictionary *)foreignKeysForObject:(NSManagedObject *)object resource:(
ARResource *)resource
93 NSMutableDictionary *foreignKeys = [NSMutableDictionary dictionary];
94 for (NSPropertyDescription *property in [[
object entity] properties])
96 if ([property isKindOfClass:[NSRelationshipDescription
class]] && [(NSRelationshipDescription *)property maxCount] == 1)
99 NSString *foreignKey = [[ASInflector defaultInflector] foreignKey:attributeName separateClassNameAndIDWithUnderscore:YES];
100 NSManagedObject *destination = [object valueForKey:[(NSRelationshipDescription *)property name]];
101 if (ASNilForNull([[resource attributes] objectForKey:foreignKey]) == nil && destination)
103 NSNumber *destinationID = [
self referenceObjectForObjectID:[destination objectID]];
104 [foreignKeys setObject:destinationID forKey:foreignKey];
108 return [foreignKeys copy];