-
Notifications
You must be signed in to change notification settings - Fork 9
/
ActiveRecord.h
147 lines (119 loc) · 5.5 KB
/
ActiveRecord.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// ActiveRecord.h
// Shopify_Mobile
//
// Created by Matthew Newberry on 7/22/10.
// Copyright 2010 Shopify. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "ActiveConnection.h"
@class ActiveManager, ActiveResult, ActiveRequest;
const typedef enum {
Create = 0,
Read = 1,
Update = 2,
Destroy = 3
} Action;
@interface ActiveRecord : NSManagedObject <ActiveConnectionDelegate>{
id _delegate;
SEL _remoteDidFinishSelector;
SEL _remoteDidFailSelector;
int _batchPage;
}
@property (nonatomic, assign) id delegate;
@property (nonatomic, assign) SEL remoteDidFinishSelector;
@property (nonatomic, assign) SEL remoteDidFailSelector;
+ (void) save;
- (ActiveRecord *) save;
+ (ActiveManager *) activeManager;
+ (ActiveResult *) find:(id) query;
+ (id) findByID:(NSNumber *)itemID;
+ (id) findByID:(NSNumber *)itemID moc:(NSManagedObjectContext *)moc; // Sigh
+ (ActiveResult *) find:(id) query limit:(int) limit;
+ (ActiveResult *) find:(id) query sortBy:(NSString *)sortBy;
+ (ActiveResult *) find:(id) query sortBy:(NSString *)sortBy limit:(int)limit;
+ (ActiveResult *) find:(id) query sortBy:(NSString *)sortBy limit:(int)limit fields:(NSArray *)fields;
+ (ActiveResult *) find:(id) query sortBy:(NSString *)sortBy limit:(int)limit fields:(NSArray *)fields moc:(NSManagedObjectContext *) moc;
+ (int) count;
+ (int) count:(NSPredicate *) predicate;
+ (NSNumber *) average:(NSString *) property;
+ (NSNumber *) minimum:(NSString *) property;
+ (NSNumber *) maximum:(NSString *) property;
+ (NSNumber *) sum:(NSString *) property;
+ (id) first;
+ (id) last;
+ (NSArray *) all;
+ (BOOL) exists:(NSNumber *) itemID;
- (ActiveRecord *) threadSafe;
+ (id) blank;
+ (id) create:(id)parameters;
+ (id) create:(id)parameters withOptions:(NSDictionary*)options;
+ (id) build:(id)parameters;
+ (id) build:(id)parameters withOptions:(NSDictionary*)options;
+ (void) removeAll;
- (void) remove;
+ (void) remove:(NSPredicate *) predicate;
- (id) update:(NSDictionary *) data;
- (id) update:(NSDictionary *) data withOptions:(NSDictionary *) options;
+ (id) update:(NSDictionary *)data predicate:(NSPredicate *)predicate;
- (BOOL) shouldUpdateWith:(NSDictionary*)dict;
- (void) push;
- (void) push:(ActiveConnectionBlock)didFinishBlock didFailBlock:(ActiveConnectionBlock)didFailBlock;
- (ActiveRequest *) requestForPush;
- (ActiveResult *) fetch;
- (void) fetchRelationship:(NSString *) relationship delegate:(id) delegate didFinishSelector:(SEL) didFinishSelector didFailSelector:(SEL)didFailSelector;
- (void) fetchRelationship:(NSString *) relationship didFinishBlock:(ActiveConnectionBlock)didFinishBlock didFailBlock:(ActiveConnectionBlock)didFailBlock;
- (void) fetchProperties:(NSDictionary *) properties;
- (void) fetch:(id) delegate didFinishSelector:(SEL) didFinishSelector didFailSelector:(SEL)didFailSelector;
- (void) fetch:(ActiveConnectionBlock)didFinishBlock didFailBlock:(ActiveConnectionBlock)didFailBlock;
- (ActiveRequest *) requestForFetch;
+ (void) pull;
+ (void) pull:(id) delegate didParseObjectSelector:(SEL)didParseObjectSelector didFinishSelector:(SEL) didFinishSelector didFailSelector:(SEL)didFailSelector;
+ (void) pull:(ActiveConnectionDidParseObjectBlock)didParseObjectBlock didFinishBlock:(ActiveConnectionBlock)didFinishBlock didFailBlock:(ActiveConnectionBlock)didFailBlock;
+ (ActiveRequest *) requestForPull;
- (NSString *) relationshipForURLPath:(NSString *) urlPath;
+ (BOOL) seed;
+ (BOOL) seedGroup:(NSString *) groupName;
/* Utilities */
+ (NSString *) remoteURLForAction:(Action) action;
+ (NSString *) remoteURLForAction:(Action)action withContentFormat:(BOOL) withContentFormat;
- (NSString *) resourceURLForAction:(Action) action;
- (NSString *) resourceURLForAction:(Action)action withContentFormat:(BOOL) withContentFormat;
- (NSString *) relationshipURL:(NSString *) relationship forAction:(Action) action;
- (NSString *) relationshipURL:(NSString *)relationship forAction:(Action)action withContentFormat:(BOOL) withContentFormat;
+ (NSManagedObjectContext *) managedObjectContext;
+ (NSString *) entityName;
+ (NSString *) entityName: (BOOL) removePrefix;
+ (NSEntityDescription *) entityDescription;
+ (NSFetchRequest *) fetchRequest;
+ (NSString *) localNameForRemoteField:(NSString*)name;
+ (NSString *) remoteNameForLocalField:(NSString*)name;
+ (NSDictionary *) relationshipsByName;
+ (BOOL) hasRelationships;
+ (NSDictionary *) propertiesByName;
+ (NSDictionary *) attributesByName;
+ (NSPropertyDescription *) propertyDescriptionForField:(NSString*)field inModel:(Class)modelClass;
+ (NSPropertyDescription *) propertyDescriptionForField:(NSString*)field;
- (NSMutableDictionary *) properties:(NSDictionary *) options;
- (NSMutableDictionary *) properties:(NSDictionary*)options withoutObjects:(NSMutableArray*)withouts;
+ (NSDictionary *) defaultCreateOptions;
+ (NSDictionary *) defaultCreateOrUpdateOptions;
+ (NSDictionary *) defaultUpdateOptions;
+ (NSString *) localIDField;
+ (NSString *) remoteIDField;
+ (NSString *) defaultSort;
+ (NSString *) createdAtField;
+ (NSString *) updatedAtField;
+ (NSString *) dateFormat;
- (NSString *) dateFormatPreprocessor:(NSString *) date;
+ (NSString *) classPrefix;
- (void) didCreate:(id) parameters data:(NSDictionary *)data;
- (void) willCreate:(id) parameters data:(NSDictionary *)data;
- (void) didUpdate:(id) parameters data:(NSDictionary *)data;
- (void) willUpdate:(id) parameters data:(NSDictionary *)data;
+ (BOOL) remoteEnabled;
+ (BOOL) usesRootNode;
+ (NSString *) rootNodeName;
+ (BOOL) shouldParseEntityNameFromRelationships;
- (NSDictionary *) map;
@end