nano-store 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitignore +1 -0
  2. data/.gitmodules +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +24 -0
  5. data/README.md +5 -0
  6. data/Rakefile +21 -1
  7. data/lib/nano_store.rb +2 -0
  8. data/lib/nano_store/finder.rb +76 -0
  9. data/lib/nano_store/model.rb +1 -32
  10. data/lib/nano_store/version.rb +1 -1
  11. data/nano-store.gemspec +1 -0
  12. data/spec/finder_spec.rb +67 -0
  13. data/spec/model_spec.rb +0 -30
  14. data/vendor/Podfile.lock +5 -0
  15. data/vendor/Pods/Headers/NanoStore/NSFNanoBag.h +306 -0
  16. data/vendor/Pods/Headers/NanoStore/NSFNanoBag_Private.h +37 -0
  17. data/vendor/Pods/Headers/NanoStore/NSFNanoEngine.h +542 -0
  18. data/vendor/Pods/Headers/NanoStore/NSFNanoEngine_Private.h +69 -0
  19. data/vendor/Pods/Headers/NanoStore/NSFNanoExpression.h +125 -0
  20. data/vendor/Pods/Headers/NanoStore/NSFNanoExpression_Private.h +35 -0
  21. data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals.h +323 -0
  22. data/vendor/Pods/Headers/NanoStore/NSFNanoGlobals_Private.h +99 -0
  23. data/vendor/Pods/Headers/NanoStore/NSFNanoObject.h +298 -0
  24. data/vendor/Pods/Headers/NanoStore/NSFNanoObjectProtocol.h +119 -0
  25. data/vendor/Pods/Headers/NanoStore/NSFNanoObject_Private.h +35 -0
  26. data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate.h +123 -0
  27. data/vendor/Pods/Headers/NanoStore/NSFNanoPredicate_Private.h +35 -0
  28. data/vendor/Pods/Headers/NanoStore/NSFNanoResult.h +137 -0
  29. data/vendor/Pods/Headers/NanoStore/NSFNanoResult_Private.h +43 -0
  30. data/vendor/Pods/Headers/NanoStore/NSFNanoSearch.h +381 -0
  31. data/vendor/Pods/Headers/NanoStore/NSFNanoSearch_Private.h +48 -0
  32. data/vendor/Pods/Headers/NanoStore/NSFNanoSortDescriptor.h +124 -0
  33. data/vendor/Pods/Headers/NanoStore/NSFNanoStore.h +475 -0
  34. data/vendor/Pods/Headers/NanoStore/NSFNanoStore_Private.h +57 -0
  35. data/vendor/Pods/Headers/NanoStore/NanoStore.h +463 -0
  36. data/vendor/Pods/Headers/NanoStore/NanoStore_Private.h +37 -0
  37. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.h +542 -0
  38. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoEngine.m +1781 -0
  39. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.h +137 -0
  40. data/vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m +265 -0
  41. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoBag_Private.h +37 -0
  42. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoEngine_Private.h +69 -0
  43. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoExpression_Private.h +35 -0
  44. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoGlobals_Private.h +99 -0
  45. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoObject_Private.h +35 -0
  46. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoPredicate_Private.h +35 -0
  47. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoResult_Private.h +43 -0
  48. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoSearch_Private.h +48 -0
  49. data/vendor/Pods/NanoStore/Classes/Private/NSFNanoStore_Private.h +57 -0
  50. data/vendor/Pods/NanoStore/Classes/Private/NanoStore_Private.h +37 -0
  51. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.h +306 -0
  52. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoBag.m +485 -0
  53. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.h +125 -0
  54. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoExpression.m +103 -0
  55. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.h +323 -0
  56. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoGlobals.m +145 -0
  57. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.h +298 -0
  58. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObject.m +187 -0
  59. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoObjectProtocol.h +119 -0
  60. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.h +123 -0
  61. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoPredicate.m +130 -0
  62. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.h +381 -0
  63. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSearch.m +859 -0
  64. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.h +124 -0
  65. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoSortDescriptor.m +79 -0
  66. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.h +475 -0
  67. data/vendor/Pods/NanoStore/Classes/Public/NSFNanoStore.m +1375 -0
  68. data/vendor/Pods/NanoStore/Classes/Public/NanoStore.h +463 -0
  69. data/vendor/Pods/NanoStore/LICENSE +25 -0
  70. data/vendor/Pods/NanoStore/README.md +411 -0
  71. data/vendor/Pods/Pods-prefix.pch +3 -0
  72. data/vendor/Pods/Pods-resources.sh +15 -0
  73. data/vendor/Pods/Pods.bridgesupport +1215 -0
  74. data/vendor/Pods/Pods.xcconfig +4 -0
  75. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +974 -0
  76. metadata +89 -6
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  vendor/*/build-*
2
+ pkg/*
2
3
  .repl_history
3
4
  build
data/.gitmodules CHANGED
@@ -1,3 +0,0 @@
1
- [submodule "vendor/BubbleWrap"]
2
- path = vendor/BubbleWrap
3
- url = https://github.com/mattetti/BubbleWrap.git
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gemspec
4
- gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nano-store (0.3.0)
5
+ bubble-wrap (>= 0.1.1)
6
+ motion-cocoapods (>= 1.0.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ bubble-wrap (0.1.1)
12
+ cocoapods (0.5.1)
13
+ xcodeproj (~> 0.1.0)
14
+ motion-cocoapods (1.0.1)
15
+ cocoapods (>= 0.5.1)
16
+ motion-redgreen (0.0.2)
17
+ xcodeproj (0.1.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ motion-redgreen
24
+ nano-store!
data/README.md CHANGED
@@ -89,6 +89,11 @@ User.all # => [<User#1>, <User#2>]
89
89
 
90
90
  # find model by criteria
91
91
  users = User.find(:name, NSFEqualTo, "Bob")
92
+
93
+ # or use hash
94
+ users = User.find(:name => "Bob")
95
+ users = User.find(:name => { NSFEqualTo => "Ronald" })
96
+ users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })
92
97
  ````
93
98
 
94
99
  ### Update
data/Rakefile CHANGED
@@ -1 +1,21 @@
1
- require "bundler/gem_tasks"
1
+ $:.unshift("/Library/RubyMotion/lib")
2
+ require 'motion/project'
3
+ require 'motion-cocoapods'
4
+ require 'bubble-wrap'
5
+ require 'motion-redgreen'
6
+
7
+ Motion::Project::App.setup do |app|
8
+ app.name = 'NanoStoreDemo'
9
+
10
+ app.files += Dir.glob(File.join(app.project_dir, 'lib/nano_store/*.rb'))
11
+ app.pods do
12
+ dependency 'NanoStore'
13
+ end
14
+ end
15
+
16
+ desc "Build the gem"
17
+ task :gem do
18
+ sh "bundle exec gem build nano-store.gemspec"
19
+ sh "mkdir -p pkg"
20
+ sh "mv *.gem pkg/"
21
+ end
data/lib/nano_store.rb CHANGED
@@ -4,6 +4,8 @@ unless defined?(Motion::Project::Config)
4
4
  raise "This file must be required within a RubyMotion project Rakefile."
5
5
  end
6
6
 
7
+ require 'bubble-wrap'
8
+
7
9
  Motion::Project::App.setup do |app|
8
10
  Dir.glob(File.join(File.dirname(__FILE__), 'nano_store/*.rb')).each do |file|
9
11
  app.files.unshift(file)
@@ -0,0 +1,76 @@
1
+ module NanoStore
2
+ module FinderMethods
3
+ # find model by criteria
4
+ #
5
+ # Return array of models
6
+ #
7
+ # Examples:
8
+ # User.find(:name, NSFEqualTo, "Bob") # => [<User#1>]
9
+ # User.find(:name => "Bob") # => [<User#1>]
10
+ # User.find(:name => {NSFEqualTo => "Bob"}) # => [<User#1>]
11
+ #
12
+ def find(*arg)
13
+ if arg[0].is_a?(Hash)
14
+ # hash style
15
+ options = arg[0]
16
+ elsif arg[0] && arg[1] && arg[2]
17
+ # standard way to find
18
+ options = {arg[0] => {arg[1] => arg[2]}}
19
+ end
20
+ search = NSFNanoSearch.searchWithStore(self.store)
21
+ expressions = expressions_with_options(options)
22
+ search.setExpressions(expressions)
23
+ error_ptr = Pointer.new(:id)
24
+ searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
25
+ raise NanoStoreError, error_ptr[0].description if error_ptr[0]
26
+ searchResults.values
27
+ end
28
+
29
+ # find model keys by criteria
30
+ #
31
+ # Return array of keys
32
+ #
33
+ # Examples:
34
+ # User.find(:name, NSFEqualTo, "Bob") # => [<User#1>]
35
+ # User.find(:name => "Bob") # => [<User#1>]
36
+ # User.find(:name => {NSFEqualTo => "Bob"}) # => [<User#1>]
37
+ #
38
+ def find_keys(*arg)
39
+ if arg[0].is_a?(Hash)
40
+ # hash style
41
+ options = arg[0]
42
+ elsif arg[0] && arg[1] && arg[2]
43
+ # standard way to find
44
+ options = {arg[0] => {arg[1] => arg[2]}}
45
+ end
46
+ search = NSFNanoSearch.searchWithStore(self.store)
47
+ expressions = expressions_with_options(options)
48
+ search.setExpressions(expressions)
49
+ error_ptr = Pointer.new(:id)
50
+ searchResults = search.searchObjectsWithReturnType(NSFReturnKeys, error:error_ptr)
51
+ raise NanoStoreError, error_ptr[0].description if error_ptr[0]
52
+ searchResults
53
+ end
54
+
55
+ protected
56
+ def expressions_with_options(options)
57
+ expressions = []
58
+ options.each do |key, val|
59
+ attribute = NSFNanoPredicate.predicateWithColumn(NSFAttributeColumn, matching:NSFEqualTo, value:key.to_s)
60
+ expression = NSFNanoExpression.expressionWithPredicate(attribute)
61
+
62
+ if val.is_a?(Hash)
63
+ val.each do |operator, sub_val|
64
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:operator, value:sub_val)
65
+ expression.addPredicate(value, withOperator:NSFAnd)
66
+ end
67
+ else
68
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:val)
69
+ expression.addPredicate(value, withOperator:NSFAnd)
70
+ end
71
+ expressions << expression
72
+ end
73
+ return expressions
74
+ end
75
+ end # module FinderMethods
76
+ end # module NanoStore
@@ -87,38 +87,6 @@ module NanoStore
87
87
  raise NanoStoreError, error_ptr[0].description if error_ptr[0]
88
88
  searchResults.values
89
89
  end
90
-
91
- # find model by criteria
92
- #
93
- # Return array of models
94
- #
95
- # Example:
96
- #
97
- # User.find(:name, NSFEqualTo, "Bob") => [<User#1>]
98
- #
99
- def find(attribute, match, value)
100
- search = search_with_store(self.store, attribute, match, value)
101
- error_ptr = Pointer.new(:id)
102
- searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
103
- raise NanoStoreError, error_ptr[0].description if error_ptr[0]
104
- searchResults.values
105
- end
106
-
107
- # find model keys by criteria
108
- #
109
- # Return array of model keys
110
- #
111
- # Example:
112
- #
113
- # User.find(:name, NSFEqualTo, "Bob") => [<User#1>]
114
- #
115
- def find_keys(attribute, match, value)
116
- search = search_with_store(self.store, attribute, match, value)
117
- error_ptr = Pointer.new(:id)
118
- searchResults = search.searchObjectsWithReturnType(NSFReturnKeys, error:error_ptr)
119
- raise NanoStoreError, error_ptr[0].description if error_ptr[0]
120
- searchResults
121
- end
122
90
 
123
91
  def inherited(subclass)
124
92
  subclass.instance_variable_set(:@attributes, [])
@@ -138,5 +106,6 @@ module NanoStore
138
106
  class Model < NSFNanoObject
139
107
  include ModelInstanceMethods
140
108
  extend ModelClassMethods
109
+ extend ::NanoStore::FinderMethods
141
110
  end
142
111
  end
@@ -1,3 +1,3 @@
1
1
  module NanoStore
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
data/nano-store.gemspec CHANGED
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_dependency 'bubble-wrap', '>= 0.1.1'
18
18
  gem.add_dependency 'motion-cocoapods', '>= 1.0.1'
19
+ gem.add_development_dependency 'motion-redgreen'
19
20
  end
@@ -0,0 +1,67 @@
1
+ describe "Finder" do
2
+ def stub_user(name, age, created_at)
3
+ user = User.new
4
+ user.name = name
5
+ user.age = age
6
+ user.created_at = created_at
7
+ user
8
+ end
9
+
10
+ after do
11
+ NanoStore.shared_store = nil
12
+ end
13
+
14
+ before do
15
+ NanoStore.shared_store = NanoStore.store
16
+
17
+ user = stub_user("Bob", 10, Time.now)
18
+ user.save
19
+
20
+ user2 = stub_user("Amy", 11, Time.now)
21
+ user2.save
22
+
23
+ user3 = stub_user("Carl", 4, Time.now)
24
+ user3.save
25
+ end
26
+
27
+ it "search object traditional way: supply key, operator and value" do
28
+ users = User.find(:name, NSFEqualTo, "Bob")
29
+ users.should.not.be.nil
30
+ user = users.first
31
+ user.should.not.be.nil
32
+ user.name.should.be == "Bob"
33
+ user.age.should.be == 10
34
+ end
35
+
36
+ it "search object with simple hash" do
37
+ user = User.find(:name => "Carl").first
38
+ user.name.should.be == "Carl"
39
+ user.age.should.be == 4
40
+ end
41
+
42
+ it "search object with multiple parameters" do
43
+ stub_user("Ronald", 18, Time.now).save
44
+ stub_user("Ronald", 29, Time.now).save
45
+ stub_user("Ronald", 36, Time.now).save
46
+ stub_user("Ronald", 39, Time.now).save
47
+ stub_user("Ronald", 49, Time.now).save
48
+ stub_user("Ronald", 59, Time.now).save
49
+
50
+ users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })
51
+ users.size.should == 1
52
+ user = users.first
53
+ user.name.should.be == "Ronald"
54
+ user.age.should.be == 59
55
+
56
+ users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFLessThan => 30 })
57
+ users.size.should == 2
58
+ user = users.first
59
+ user.name.should.be == "Ronald"
60
+ end
61
+
62
+ it "find object" do
63
+ user = User.find(:name, NSFEqualTo, "Bob").first
64
+ user.name.should == "Bob"
65
+ end
66
+
67
+ end
data/spec/model_spec.rb CHANGED
@@ -67,21 +67,6 @@ describe NanoStore::Model do
67
67
  user2.key.should == user.key
68
68
  end
69
69
 
70
- it "find object" do
71
- user = stub_user("Bob", 10, Time.now)
72
- user.save
73
-
74
- users = User.find(:name, NSFEqualTo, "Bob")
75
- users.should.not.be.nil
76
- users.count.should == 1
77
- users.first.name.should == user.name
78
-
79
- users = User.find_keys(:name, NSFEqualTo, "Bob")
80
- users.should.not.be.nil
81
- users.count.should == 1
82
- users.first.should == user.key
83
- end
84
-
85
70
  it "delete object" do
86
71
  user = stub_user("Bob", 10, Time.now)
87
72
  user.save
@@ -112,19 +97,4 @@ describe NanoStore::Model do
112
97
  users.collect(&:key).include?(user2.key)
113
98
  end
114
99
 
115
- it "search object" do
116
- user = stub_user("Bob", 10, Time.now)
117
- user.save
118
-
119
- user2 = stub_user("Amy", 11, Time.now)
120
- user2.save
121
-
122
- User.count.should == 2
123
- users = User.find(:name, NSFEqualTo, "Bob")
124
- users.should.not.be.nil
125
- user = users.first
126
- user.should.not.be.nil
127
- user.name.should.be == "Bob"
128
- user.age.should.be == 10
129
- end
130
100
  end
@@ -0,0 +1,5 @@
1
+ PODS:
2
+ - NanoStore (2.0.1)
3
+
4
+ DEPENDENCIES:
5
+ - NanoStore
@@ -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