nano-store 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +3 -0
  2. data/.gitmodules +3 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +193 -0
  7. data/Rakefile +1 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/nano-store.rb +1 -0
  10. data/lib/nano_store/bag.rb +98 -0
  11. data/lib/nano_store/model.rb +142 -0
  12. data/lib/nano_store/nano_store.rb +36 -0
  13. data/lib/nano_store/store_extension.rb +150 -0
  14. data/lib/nano_store/version.rb +3 -0
  15. data/lib/nano_store.rb +14 -0
  16. data/nano-store.gemspec +17 -0
  17. data/resources/.gitignore +0 -0
  18. data/spec/bag_spec.rb +66 -0
  19. data/spec/model_spec.rb +130 -0
  20. data/spec/nano_store_spec.rb +48 -0
  21. data/spec/store_extension_spec.rb +110 -0
  22. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
  23. data/vendor/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
  24. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
  25. data/vendor/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
  26. data/vendor/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
  27. data/vendor/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
  28. data/vendor/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
  29. data/vendor/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
  30. data/vendor/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
  31. data/vendor/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
  32. data/vendor/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
  33. data/vendor/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
  34. data/vendor/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
  35. data/vendor/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
  36. data/vendor/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
  37. data/vendor/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
  38. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
  39. data/vendor/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
  40. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
  41. data/vendor/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
  42. data/vendor/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
  43. data/vendor/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
  44. data/vendor/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
  45. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
  46. data/vendor/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
  47. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
  48. data/vendor/NanoStore/Classes/Public/NSFNanoSearch.m +835 -0
  49. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
  50. data/vendor/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
  51. data/vendor/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
  52. data/vendor/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
  53. data/vendor/NanoStore/Classes/Public/NanoStore.h +463 -0
  54. data/vendor/NanoStore/LICENSE +25 -0
  55. data/vendor/NanoStore/NanoStore.bridgesupport +1215 -0
  56. data/vendor/NanoStore/README.md +411 -0
  57. metadata +118 -0
@@ -0,0 +1,35 @@
1
+ /*
2
+ NSFNanoSearch_Private.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NanoStore.h"
28
+
29
+ /** \cond */
30
+
31
+ @interface NSFNanoPredicate (Private)
32
+ // Just a placeholder.
33
+ @end
34
+
35
+ /** \endcond */
@@ -0,0 +1,43 @@
1
+ /*
2
+ NSFNanoResult_Private.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoResult.h"
28
+
29
+ /** \cond */
30
+
31
+ @interface NSFNanoResult (Private)
32
+ + (NSFNanoResult *)_resultWithDictionary:(NSDictionary *)results;
33
+ + (NSFNanoResult *)_resultWithError:(NSError *)error;
34
+
35
+ - (id)_initWithDictionary:(NSDictionary *)results;
36
+ - (id)_initWithError:(NSError *)error;
37
+
38
+ - (void)_setError:(NSError *)error;
39
+ - (void)_reset;
40
+ - (void)_calculateNumberOfRows;
41
+ @end
42
+
43
+ /** \endcond */
@@ -0,0 +1,48 @@
1
+ /*
2
+ NSFNanoSearch_Private.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NanoStore.h"
28
+
29
+ /** \cond */
30
+
31
+ @interface NSFNanoSearch (Private)
32
+ - (NSDictionary *)_retrieveDataWithError:(out NSError **)outError;
33
+ - (NSArray *)_dataWithKey:(NSString *)aKey attribute:(NSString *)anAttribute value:(NSString *)aValue matching:(NSFMatchType)match;
34
+ - (NSArray *)_dataWithKey:(NSString *)aKey attribute:(NSString *)anAttribute value:(NSString *)aValue matching:(NSFMatchType)match returning:(NSFReturnType)returnedObjectType;
35
+ - (NSDictionary *)_retrieveDataAdded:(NSFDateMatchType)aDateMatch calendarDate:(NSDate *)aDate error:(out NSError **)outError;
36
+ - (NSString *)_preparedSQL;
37
+ - (NSString *)_prepareSQLQueryStringWithKey:(NSString *)aKey attribute:(NSString *)anAttribute value:(id)aValue matching:(NSFMatchType)match;
38
+ - (NSString *)_prepareSQLQueryStringWithExpressions:(NSArray *)someExpressions;
39
+ - (NSArray *)_resultsFromSQLQuery:(NSString *)theSQLStatement;
40
+ + (NSString *)_prepareSQLQueryStringWithKeys:(NSArray *)someKeys;
41
+ + (NSString *)_querySegmentForColumn:(NSString *)aColumn value:(id)aValue matching:(NSFMatchType)match;
42
+ + (NSString *)_querySegmentForAttributeColumnWithValue:(id)anAttributeValue matching:(NSFMatchType)match valueColumnWithValue:(id)aValue;
43
+ - (NSDictionary *)_dictionaryForKeyPath:(NSString *)keyPath value:(id)value;
44
+ + (NSString *)_quoteStrings:(NSArray *)strings joiningWithDelimiter:(NSString *)delimiter;
45
+ - (id)_sortResultsIfApplicable:(NSDictionary *)results returnType:(NSFReturnType)theReturnType;
46
+ @end
47
+
48
+ /** \endcond */
@@ -0,0 +1,57 @@
1
+ /*
2
+ NSFNanoStore_Private.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoStore.h"
28
+
29
+ /** \cond */
30
+
31
+ @interface NSFNanoStore (Private)
32
+ + (NSFNanoStore *)_debug;
33
+ - (NSFNanoResult *)_executeSQL:(NSString *)theSQLStatement;
34
+ - (NSString*)_nestedDescriptionWithPrefixedSpace:(NSString *)prefixedSpace;
35
+ - (BOOL)_initializePreparedStatementsWithError:(out NSError **)outError;
36
+ - (void)_releasePreparedStatements;
37
+ - (void)_setIsOurTransaction:(BOOL)value;
38
+ - (BOOL)_isOurTransaction;
39
+ - (BOOL)_setupCachingSchema;
40
+ - (BOOL)_storeDictionary:(NSDictionary *)someInfo forKey:(NSString *)aKey forClassNamed:(NSString *)classType usingSQLite3Statement:(sqlite3_stmt *)storeValuesStatement error:(out NSError **)outError;
41
+ - (BOOL)__storeDictionaries:(NSArray *)someObjects forKeys:(NSArray *)someKeys error:(out NSError **)outError;
42
+ - (BOOL)_bindValue:(id)aValue forAttribute:(NSString *)anAttribute parameterNumber:(NSInteger)aParamNumber usingSQLite3Statement:(sqlite3_stmt *)aStatement;
43
+ - (BOOL)_checkNanoStoreIsReadyAndReturnError:(out NSError **)outError;
44
+ - (NSFNanoDatatype)_NSFDatatypeOfObject:(id)value;
45
+ - (NSString *)_stringFromValue:(id)aValue;
46
+ + (NSString *)_calendarDateToString:(NSDate *)aDate;
47
+ - (void)_flattenCollection:(NSDictionary *)info keys:(NSMutableArray **)flattenedKeys values:(NSMutableArray **)flattenedValues;
48
+ - (void)_flattenCollection:(id)someObject keyPath:(NSMutableArray **)aKeyPath keys:(NSMutableArray **)someKeys values:(NSMutableArray **)someValues;
49
+ - (BOOL)_prepareSQLite3Statement:(sqlite3_stmt **)aStatement theSQLStatement:(NSString *)aSQLQuery;
50
+ - (void)_executeSQLite3StepUsingSQLite3Statement:(sqlite3_stmt *)aStatement;
51
+ - (BOOL)_addObjectsFromArray:(NSArray *)someObjects forceSave:(BOOL)forceSave error:(out NSError **)outError;
52
+ + (NSDictionary *)_defaultTestData;
53
+ - (BOOL)_backupFileStoreToDirectoryAtPath:(NSString *)aPath extension:(NSString *)anExtension compact:(BOOL)flag error:(out NSError **)outError;
54
+ - (BOOL)_backupMemoryStoreToDirectoryAtPath:(NSString *)aPath extension:(NSString *)anExtension compact:(BOOL)flag error:(out NSError **)outError;
55
+ @end
56
+
57
+ /** \endcond */
@@ -0,0 +1,37 @@
1
+ /*
2
+ NanoStore_Private.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ #import "NSFNanoGlobals_Private.h"
28
+ #import "NSFNanoSearch_Private.h"
29
+ #import "NSFNanoResult_Private.h"
30
+ #import "NSFNanoStore_Private.h"
31
+ #import "NSFNanoBag_Private.h"
32
+ #import "NSFNanoPredicate_Private.h"
33
+ #import "NSFNanoExpression_Private.h"
34
+ #import "NSFNanoGlobals_Private.h"
35
+ #import "NSFNanoEngine_Private.h"
36
+ #import "NSFNanoObject_Private.h"
37
+ #import "NSFNanoStore_Private.h"
@@ -0,0 +1,306 @@
1
+ /*
2
+ NSFNanoBag.h
3
+ NanoStore
4
+
5
+ Copyright (c) 2010 Webbo, L.L.C. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification, are permitted
8
+ provided that the following conditions are met:
9
+
10
+ * Redistributions of source code must retain the above copyright notice, this list of conditions
11
+ and the following disclaimer.
12
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
13
+ and the following disclaimer in the documentation and/or other materials provided with the distribution.
14
+ * Neither the name of Webbo nor the names of its contributors may be used to endorse or promote
15
+ products derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
18
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
20
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24
+ SUCH DAMAGE.
25
+ */
26
+
27
+ /*! @file NSFNanoBag.h
28
+ @brief A bag is a loose collection of objects stored in a document store.
29
+ */
30
+
31
+ /** @class NSFNanoBag
32
+ * A bag is a loose collection of objects stored in a document store.
33
+ *
34
+ * @note
35
+ * The objects must conform to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink. For your convenience, NanoStore provides you with NSFNanoObject, which is the standard
36
+ * way of storing and retrieving objects from/to a bag.
37
+ *
38
+ * @par
39
+ * It's more efficient to make your storage objects \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant, thus eliminating the need to convert your objects to/from
40
+ * objects of type NSFNanoObject.
41
+ *
42
+ * @details <b>Example:</b>
43
+ @code
44
+ // Instantiate a NanoStore and open it
45
+ NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFMemoryStoreType path:nil error:nil];
46
+ [nanoStore removeAllObjectsFromStoreAndReturnError:nil];
47
+
48
+ // Add some data to a bag
49
+ NSFNanoBag *bag = [NSFNanoBag bag];
50
+ NSDictionary *info = ...;
51
+ NSFNanoObject *obj1 = [NSFNanoObject nanoObjectWithDictionary:info];
52
+ NSFNanoObject *obj2 = [NSFNanoObject nanoObjectWithDictionary:info];
53
+ NSFNanoObject *obj3 = [NSFNanoObject nanoObjectWithDictionary:info];
54
+ [bag addObjectsFromArray:[NSArray arrayWithObjects:obj1, obj2, obj3, nil] error:nil];
55
+
56
+ // Add the bag and its objects to the document store
57
+ [nanoStore addObject:bag error:nil];
58
+
59
+ // Obtain the bags from the document store
60
+ NSArray *bags = [nanoStore bags];
61
+
62
+ // Close the document store
63
+ [nanoStore closeWithError:nil];
64
+ @endcode
65
+ */
66
+
67
+ #import "NSFNanoObjectProtocol.h"
68
+
69
+ @interface NSFNanoBag : NSObject <NSFNanoObjectProtocol, NSCopying>
70
+
71
+ /** * The store where the bag is located. */
72
+ @property (nonatomic, weak, readonly) NSFNanoStore *store;
73
+ /** * The name of the bag. */
74
+ @property (nonatomic, copy, readwrite) NSString *name;
75
+ /** * The UUID of the bag. */
76
+ @property (nonatomic, copy, readonly) NSString *key;
77
+ /** * Dictionary of NSString (key) and id<NSFNanoObjectProtocol> (value). */
78
+ @property (nonatomic, readonly) NSDictionary *savedObjects;
79
+ /** * Dictionary of NSString (key) and id<NSFNanoObjectProtocol> (value). */
80
+ @property (nonatomic, readonly) NSDictionary *unsavedObjects;
81
+ /** * Dictionary of NSString (key) and id<NSFNanoObjectProtocol> (value). */
82
+ @property (nonatomic, readonly) NSDictionary *removedObjects;
83
+ /** * To determine whether the bag has uncommited changes. */
84
+ @property (nonatomic, assign, readonly) BOOL hasUnsavedChanges;
85
+
86
+ /** @name Creating and Initializing Bags
87
+ */
88
+
89
+ //@{
90
+
91
+ /** * Creates and returns an empty bag.
92
+ * @return An empty bag upon success, nil otherwise.
93
+ */
94
+
95
+ + (NSFNanoBag *)bag;
96
+
97
+ /** * Creates and returns a bag adding to it the objects contained in the given array.
98
+ * @param theObjects an array of objects conforming to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink.
99
+ * @return A bag only containing the objects with conform to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink upon success, nil otherwise.
100
+ * @see \link initBagWithNanoObjects: - (NSFNanoBag*)initBagWithNanoObjects:(NSArray *)theObjects \endlink
101
+ */
102
+
103
+ + (NSFNanoBag *)bagWithObjects:(NSArray *)theObjects;
104
+
105
+ /** * Creates and returns an empty bag with the specified name
106
+ * @param theName the name of the bag. Can be nil.
107
+ * @return An empty bag upon success, nil otherwise.
108
+ */
109
+
110
+ + bagWithName:(NSString *)theName;
111
+
112
+ /** * Creates and returns a bag with the specified name adding to it the objects contained in the given array.
113
+ * @param theName the name of the bag. Can be nil.
114
+ * @param theObjects an array of objects conforming to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink.
115
+ * @return A bag only containing the objects with conform to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink upon success, nil otherwise.
116
+ * @see \link initBagWithNanoObjects: - (NSFNanoBag*)initBagWithNanoObjects:(NSArray *)theObjects \endlink
117
+ */
118
+
119
+ + bagWithName:(NSString *)theName andObjects:(NSArray *)theObjects;
120
+
121
+ /** * Initializes a newly allocated bag with the specified name adding to it the objects contained in the given array.
122
+ * @param theName the name of the bag. Can be nil.
123
+ * @param theObjects an array of objects conforming to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink.
124
+ * @return A bag only containing the objects with conform to the \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink upon success, nil otherwise.
125
+ * @see \link bagWithObjects: + (NSFNanoBag*)bagWithObjects:(NSArray *)theObjects \endlink
126
+ */
127
+
128
+ - (id)initBagWithName:(NSString *)theName andObjects:(NSArray *)someObjects;
129
+
130
+ //@}
131
+
132
+ /** @name Adding and Removing Objects
133
+ */
134
+
135
+ //@{
136
+
137
+ /** * Adds an \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant object to the bag.
138
+ * @param theObject is added to the bag.
139
+ * @param outError is used if an error occurs. May be NULL.
140
+ * @return YES upon success, NO otherwise.
141
+ * @warning This value cannot be nil and it must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
142
+ * @throws NSFNonConformingNanoObjectProtocolException is thrown if the object is non-\link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink compliant.
143
+ * @see \link addObjectsFromArray:error: - (BOOL)addObjectsFromArray:(NSArray *)theObjects error:(out NSError **)outError \endlink
144
+ */
145
+
146
+ - (BOOL)addObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError;
147
+
148
+ /** * Adds a series of \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant objects to the bag.
149
+ * @param theObjects is an array of objects to be added to the bag. The objects must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
150
+ * @param outError is used if an error occurs. May be NULL.
151
+ * @return YES upon success, NO otherwise.
152
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
153
+ * @throws NSFNonConformingNanoObjectProtocolException is thrown if the object is non-\link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink compliant.
154
+ * @see \link addObject:error: - (BOOL)addObject:(id <NSFNanoObjectProtocol>)theObject error:(out NSError **)outError \endlink
155
+ */
156
+
157
+ - (BOOL)addObjectsFromArray:(NSArray *)theObjects error:(out NSError **)outError;
158
+
159
+ /** * Removes the specified object from the bag.
160
+ * @param theObject the object to be removed from the bag.
161
+ * @warning The object must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
162
+ * @see \link removeObjectsInArray: - (void)removeObjectsInArray:(NSArray *)theObjects \endlink
163
+ * @see \link removeObjectWithKey: - (void)removeObjectWithKey:(NSString *)theObjectKey \endlink
164
+ * @see \link removeObjectsWithKeysInArray: - (void)removeObjectsWithKeysInArray:(NSArray *)theKeys \endlink
165
+ * @see \link removeAllObjects - (void)removeAllObjects \endlink
166
+ */
167
+
168
+ - (void)removeObject:(id <NSFNanoObjectProtocol>)theObject;
169
+
170
+ /** * Empties the bag of all its elements.
171
+ * @see \link removeObject: - (void)removeObject:(id <NSFNanoObjectProtocol>)theObject \endlink
172
+ * @see \link removeObjectsInArray: - (void)removeObjectsInArray:(NSArray *)theObjects \endlink
173
+ * @see \link removeObjectWithKey: - (void)removeObjectWithKey:(NSString *)theObjectKey \endlink
174
+ * @see \link removeObjectsWithKeysInArray: - (void)removeObjectsWithKeysInArray:(NSArray *)theKeys \endlink
175
+ */
176
+
177
+ - (void)removeAllObjects;
178
+
179
+ /** * Removes the list of objects from the bag.
180
+ * @param theObjects the list of objects to be removed from the bag.
181
+ * @warning The objects of the array must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
182
+ * @see \link removeObject: - (void)removeObject:(id <NSFNanoObjectProtocol>)theObject \endlink
183
+ * @see \link removeObjectWithKey: - (void)removeObjectWithKey:(NSString *)theObjectKey \endlink
184
+ * @see \link removeObjectsWithKeysInArray: - (void)removeObjectsWithKeysInArray:(NSArray *)theKeys \endlink
185
+ * @see \link removeAllObjects - (void)removeAllObjects \endlink
186
+ */
187
+
188
+ - (void)removeObjectsInArray:(NSArray *)theObjects;
189
+
190
+ /** * Removes the object with a given key from the bag.
191
+ * @param theObjectKey the key of the object to be removed from the bag.
192
+ * @warning The object referenced by theObjectKey must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
193
+ * @see \link removeObject: - (void)removeObject:(id <NSFNanoObjectProtocol>)theObject \endlink
194
+ * @see \link removeObjectsInArray: - (void)removeObjectsInArray:(NSArray *)theObjects \endlink
195
+ * @see \link removeObjectsWithKeysInArray: - (void)removeObjectsWithKeysInArray:(NSArray *)theKeys \endlink
196
+ * @see \link removeAllObjects - (void)removeAllObjects \endlink
197
+ */
198
+
199
+ - (void)removeObjectWithKey:(NSString *)theObjectKey;
200
+
201
+ /** * Removes from the bag the objects specified by elements in a given array.
202
+ * @param theKeys an array of objects specifying the keys to remove from the bag
203
+ * @warning The objects referenced by theKeys must be \link NSFNanoObjectProtocol::initNanoObjectFromDictionaryRepresentation:forKey:store: NSFNanoObjectProtocol\endlink-compliant.
204
+ * @see \link removeObject: - (void)removeObject:(id <NSFNanoObjectProtocol>)theObject \endlink
205
+ * @see \link removeObjectsInArray: - (void)removeObjectsInArray:(NSArray *)theObjects \endlink
206
+ * @see \link removeObjectWithKey: - (void)removeObjectWithKey:(NSString *)theObjectKey \endlink
207
+ * @see \link removeAllObjects - (void)removeAllObjects \endlink
208
+ */
209
+
210
+ - (void)removeObjectsWithKeysInArray:(NSArray *)theKeys;
211
+
212
+ //@}
213
+
214
+ /** @name Saving, Reloading and Undoing
215
+ */
216
+
217
+ //@{
218
+
219
+ /** * Saves the bag and its contents. Also, saves all the changes made since the last save.
220
+ * @param outError is used if an error occurs. May be NULL.
221
+ * @return YES upon success, NO otherwise.
222
+ * @note Check property hasUnsavedChanges to find out whether the bag has unsaved contents.
223
+ * @see \link reloadBagWithError: - (BOOL)reloadBagWithError:(out NSError **)outError \endlink
224
+ * @see \link undoChangesWithError: - (BOOL)undoChangesWithError:(out NSError **)outError \endlink
225
+ */
226
+
227
+ - (BOOL)saveAndReturnError:(out NSError **)outError;
228
+
229
+ /** * Refreshes the bag to match the contents stored in the document store. The unsaved contents are preserved.
230
+ * @param outError is used if an error occurs. May be NULL.
231
+ * @return YES upon success, NO otherwise.
232
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
233
+ * @see \link saveAndReturnError: - (BOOL)saveAndReturnError:(out NSError **)outError \endlink
234
+ * @see \link undoChangesWithError: - (BOOL)undoChangesWithError:(out NSError **)outError \endlink
235
+ */
236
+
237
+ - (BOOL)reloadBagWithError:(out NSError **)outError;
238
+
239
+ /** * Discards the changes made in the bag.
240
+ * @param outError is used if an error occurs. May be NULL.
241
+ * @return YES upon success, NO otherwise.
242
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
243
+ * @see \link saveAndReturnError: - (BOOL)saveAndReturnError:(out NSError **)outError \endlink
244
+ * @see \link reloadBagWithError: - (BOOL)reloadBagWithError:(out NSError **)outError \endlink
245
+ */
246
+
247
+ - (BOOL)undoChangesWithError:(out NSError **)outError;
248
+
249
+ //@}
250
+
251
+ /** @name Inflating and Deflating
252
+ */
253
+
254
+ //@{
255
+
256
+ /** * Inflates the bag by reconstructing the objects flattened with - (void)deflateBag;
257
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
258
+ * @see \link deflateBag - (void)deflateBag \endlink
259
+ */
260
+
261
+ - (void)inflateBag;
262
+
263
+ /** * Releases memory by "flattening" the objects from the bag.
264
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
265
+ * @see \link inflateBag - (void)inflateBag \endlink
266
+ */
267
+
268
+ - (void)deflateBag;
269
+
270
+ //@}
271
+
272
+ /** @name Miscellaneous
273
+ */
274
+
275
+ //@{
276
+
277
+ /** * Returns the number of objects currently in the bag.
278
+ * @return The number of objects currently in the bag.
279
+ */
280
+
281
+ - (NSUInteger)count;
282
+
283
+ /** * Compares the receiving bag to another bag.
284
+ * @param otherNanoBag is a bag.
285
+ * @return YES if the contents of otherNanoBag are equal to the contents of the receiving bag, otherwise NO.
286
+ */
287
+
288
+ - (BOOL)isEqualToNanoBag:(NSFNanoBag *)otherNanoBag;
289
+
290
+ /** * Returns a dictionary that contains the information stored in the bag.
291
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
292
+ * @see \link description - (NSString *)description \endlink
293
+ */
294
+
295
+ - (NSDictionary *)dictionaryRepresentation;
296
+
297
+ /** * Returns a string representation of the bag.
298
+ * @note Check properties savedObjects, unsavedObjects and removedObjects to find out the current state of the bag.
299
+ * @see \link dictionaryRepresentation - (NSDictionary *)dictionaryRepresentation \endlink
300
+ */
301
+
302
+ - (NSString *)description;
303
+
304
+ //@}
305
+
306
+ @end