nano-store 0.3.10 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .rake_tasks~
1
2
  vendor/*/build-*
2
3
  vendor/Pods/Pods.xcodeproj/project.pbxproj
3
4
  pkg/*
data/Rakefile CHANGED
@@ -7,10 +7,10 @@ require 'motion-redgreen'
7
7
 
8
8
  Motion::Project::App.setup do |app|
9
9
  app.name = 'NanoStoreDemo'
10
-
10
+ app.redgreen_style = :full
11
11
  app.files += Dir.glob(File.join(app.project_dir, 'lib/nano_store/*.rb'))
12
12
  app.pods do
13
- dependency 'NanoStore', '~> 2.1.1'
13
+ dependency 'NanoStore', '~> 2.1.4'
14
14
  end
15
15
  end
16
16
 
@@ -41,26 +41,26 @@ module NanoStore
41
41
  else
42
42
  sort_options = {}
43
43
  end
44
+ elsif arg.empty?
45
+ options = {}
46
+ sort_options = {}
44
47
  else
45
48
  raise "unexpected parameters #{arg}"
46
49
  end
47
50
  search = NSFNanoSearch.searchWithStore(self.store)
48
51
 
49
- unless options.empty?
50
- expressions = expressions_with_options(options)
51
- search.expressions = expressions
52
- end
52
+ expressions = expressions_with_options(options)
53
+ search.expressions = expressions
53
54
 
54
55
  sort_descriptors = sort_descriptor_with_options(sort_options)
55
56
  search.sort = sort_descriptors
56
- search.filterClass = self.object_class_name
57
+ search.filterClass = self.bare_class_name
57
58
 
58
59
  error_ptr = Pointer.new(:id)
59
60
  searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
60
61
  raise NanoStoreError, error_ptr[0].description if error_ptr[0]
61
62
 
62
- # workaround to filter class until nanostore implement class filter
63
- searchResults.select {|r| r.class.to_s == self.to_s }
63
+ searchResults
64
64
  end
65
65
 
66
66
  # find model keys by criteria
@@ -83,48 +83,43 @@ module NanoStore
83
83
  end
84
84
  elsif arg[0] && arg[1] && arg[2]
85
85
  # standard way to find
86
- options = {arg[0] => {arg[1] => arg[2]}}
86
+ options = {arg[0] => {arg[1] => arg[2]}}
87
87
  if arg[4] && arg[4].is_a?(Hash)
88
88
  sort_options = arg[4][:sort] || {}
89
89
  else
90
90
  sort_options = {}
91
91
  end
92
+ elsif arg.empty?
93
+ options = {}
94
+ sort_options = {}
92
95
  else
93
96
  raise "unexpected parameters #{arg}"
94
97
  end
95
98
 
96
99
  search = NSFNanoSearch.searchWithStore(self.store)
97
100
 
98
- unless options.empty?
99
- expressions = expressions_with_options(options)
100
- search.expressions = expressions
101
- end
101
+ expressions = expressions_with_options(options)
102
+ search.expressions = expressions
102
103
 
103
104
  sort_descriptors = sort_descriptor_with_options(sort_options)
104
105
  search.sort = sort_descriptors
105
- search.filterClass = self.object_class_name
106
+ search.filterClass = self.bare_class_name
106
107
 
107
108
  error_ptr = Pointer.new(:id)
108
-
109
- search.attributesToBeReturned = ["NSFObjectClass", "NSFKey"]
110
- searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
109
+ searchResults = search.searchObjectsWithReturnType(NSFReturnKeys, error:error_ptr)
111
110
  raise NanoStoreError, error_ptr[0].description if error_ptr[0]
112
-
113
- # workaround to filter class until nanostore implement class filter
114
- searchResults.select {|r| r.class.to_s == self.to_s }.collect(&:key)
111
+
112
+ searchResults
115
113
  end
116
114
 
117
115
  def bare_class_name
118
- self.to_s.split("::").last.capitalize
119
- end
120
-
121
- def object_class_name
122
- "k#{bare_class_name}"
116
+ self.to_s.split("::").last
123
117
  end
124
118
 
125
119
  private
126
120
  def expressions_with_options(options)
127
121
  expressions = []
122
+
128
123
  options.each do |key, val|
129
124
  attribute = NSFNanoPredicate.predicateWithColumn(NSFAttributeColumn, matching:NSFEqualTo, value:key.to_s)
130
125
  expression = NSFNanoExpression.expressionWithPredicate(attribute)
@@ -1,3 +1,3 @@
1
1
  module NanoStore
2
- VERSION = "0.3.10"
2
+ VERSION = "0.3.11"
3
3
  end
data/spec/finder_spec.rb CHANGED
@@ -31,10 +31,15 @@ describe "Finder" do
31
31
  user3.save
32
32
  end
33
33
 
34
+ it "create object in their class" do
35
+ NanoStore.shared_store.allObjectClasses.should == ["User"]
36
+ Car.create(:name => "Bob")
37
+ NanoStore.shared_store.allObjectClasses.sort.should == ["User", "Car"].sort
38
+ end
39
+
34
40
  it "search object traditional way: supply key, operator and value" do
35
41
  users = User.find(:name, NSFEqualTo, "Bob")
36
42
  users.should.not.be.nil
37
-
38
43
  user = users.first
39
44
  user.should.not.be.nil
40
45
  user.name.should.be == "Bob"
@@ -46,7 +51,16 @@ describe "Finder" do
46
51
  user.name.should.be == "Carl"
47
52
  user.age.should.be == 4
48
53
  end
49
-
54
+
55
+ it "search object with simple hash with two class" do
56
+ Car.create(:name => "Carl")
57
+ users = User.find(:name => "Carl")
58
+ users.size.should.be == 1
59
+ user = users.first
60
+ user.name.should.be == "Carl"
61
+ user.age.should.be == 4
62
+ end
63
+
50
64
  it "search object with array (OR)" do
51
65
  users = User.find(:name => ["Carl", "Amy"])
52
66
  users.size.should == 2
@@ -105,8 +119,12 @@ describe "Finder" do
105
119
  end
106
120
 
107
121
  it "find object" do
108
- user = User.find(:name, NSFEqualTo, "Bob").first
122
+ users = User.find(:name, NSFEqualTo, "Bob")
123
+ users.size.should == 1
124
+
125
+ user = users.first
109
126
  user.name.should == "Bob"
127
+ user.class.should == User
110
128
  end
111
129
 
112
130
  it "find all objects" do
@@ -130,17 +148,22 @@ describe "Finder" do
130
148
  end
131
149
 
132
150
  it "#all only return objects of the class" do
133
- Car.create(:name => "Honda")
151
+ car = Car.create(:name => "Honda")
134
152
  Car.count.should == 1
135
153
  Car.all.size.should == 1
154
+ Car.all.first.key.should == car.key
136
155
  end
137
156
 
138
157
  it "#find only return objects of the class" do
139
- Car.create(:name => "Honda")
140
- Car.count.should == 1
141
- Car.find({}).size.should == 1
142
- Car.find_keys({}).size.should == 1
158
+ car = Car.create(:name => "Honda")
159
+ Car.find.size.should == 1
160
+ Car.find.first.key.should == car.key
161
+ end
162
+
163
+ it "#find_keys only return objects of the class" do
164
+ car = Car.create(:name => "Honda")
165
+ Car.find_keys.size.should == 1
166
+ Car.find_keys.first.should == car.key
143
167
  end
144
-
145
168
 
146
169
  end
data/spec/model_spec.rb CHANGED
@@ -5,6 +5,11 @@ describe NanoStore::Model do
5
5
  attribute :age
6
6
  attribute :created_at
7
7
  end
8
+
9
+ class Plane < NanoStore::Model
10
+ attribute :name
11
+ attribute :age
12
+ end
8
13
 
9
14
  def stub_user(name, age, created_at)
10
15
  user = User.new
@@ -92,10 +97,16 @@ describe NanoStore::Model do
92
97
 
93
98
  user = stub_user("Kyu", 14, Time.now)
94
99
  user.save
100
+
101
+ plane = Plane.create(:name => "A730", :age => 20)
95
102
 
96
103
  User.count.should == 3
97
104
  User.delete({:age => {NSFGreaterThan => 10}})
98
105
  User.count.should == 1
106
+
107
+ User.delete({})
108
+ User.count.should == 0
109
+ Plane.count.should == 1
99
110
  end
100
111
 
101
112
 
data/vendor/Podfile.lock CHANGED
@@ -1,5 +1,5 @@
1
1
  PODS:
2
- - NanoStore (2.1.1)
2
+ - NanoStore (2.1.4)
3
3
 
4
4
  DEPENDENCIES:
5
- - NanoStore (~> 2.1.1)
5
+ - NanoStore (~> 2.1.4)
@@ -419,13 +419,25 @@
419
419
 
420
420
  switch (aDateMatch) {
421
421
  case NSFBeforeDate:
422
- theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ < '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
422
+ if (self.filterClass.length > 0) {
423
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ < '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
424
+ } else {
425
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ < '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
426
+ }
423
427
  break;
424
428
  case NSFOnDate:
425
- theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ = '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
429
+ if (self.filterClass.length > 0) {
430
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ = '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
431
+ } else {
432
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ = '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
433
+ }
426
434
  break;
427
435
  case NSFAfterDate:
428
- theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ > '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
436
+ if (self.filterClass.length > 0) {
437
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE (NSFObjectClass = '%@') AND %@ > '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, self.filterClass, NSFCalendarDate, normalizedDateString];
438
+ } else {
439
+ theSQLStatement = [[NSString alloc]initWithFormat:@"SELECT %@, %@, %@ FROM %@ WHERE %@ > '%@'", NSFKey, NSFPlist, NSFObjectClass, NSFKeys, NSFCalendarDate, normalizedDateString];
440
+ }
429
441
  break;
430
442
  }
431
443
 
@@ -582,6 +594,10 @@
582
594
  } else {
583
595
  theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFPlist,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theSQLStatement];
584
596
  }
597
+ } else {
598
+ if (self.filterClass.length > 0) {
599
+ theSQLStatement = [NSString stringWithFormat:@"SELECT (NSFKEY) FROM NSFKeys WHERE (NSFObjectClass = '%@') AND NSFKEY IN (%@)", self.filterClass, theSQLStatement];
600
+ }
585
601
  }
586
602
 
587
603
  return theSQLStatement;
@@ -594,21 +610,30 @@
594
610
  NSMutableString *parentheses = [NSMutableString new];
595
611
  NSFReturnType returnType = returnedObjectType;
596
612
 
597
- for (i = 0; i < count; i++) {
598
- NSFNanoExpression *expression = [someExpressions objectAtIndex:i];
599
- NSMutableString *theSQL = nil;;
600
-
601
- if (NSFReturnObjects == returnType)
602
- theSQL = [[NSMutableString alloc]initWithFormat:@"SELECT NSFKEY FROM NSFValues WHERE %@", [expression description]];
603
- else
604
- theSQL = [[NSMutableString alloc]initWithFormat:@"SELECT DISTINCT (NSFKEY) FROM NSFValues WHERE %@", [expression description]];
605
-
606
- if ((count > 1) && (i < count-1)) {
607
- [theSQL appendString:@" AND NSFKEY IN ("];
608
- [parentheses appendString:@")"];
613
+ if (count == 0) {
614
+ if (NSFReturnObjects == returnType) {
615
+ [sqlComponents addObject:@"SELECT NSFKEY FROM NSFValues"];
616
+ } else {
617
+ [sqlComponents addObject:@"SELECT DISTINCT (NSFKEY) FROM NSFValues"];
618
+ }
619
+ } else {
620
+ for (i = 0; i < count; i++) {
621
+ NSFNanoExpression *expression = [someExpressions objectAtIndex:i];
622
+ NSMutableString *theSQL = nil;;
623
+
624
+ if (NSFReturnObjects == returnType) {
625
+ theSQL = [[NSMutableString alloc]initWithFormat:@"SELECT NSFKEY FROM NSFValues WHERE %@", [expression description]];
626
+ } else {
627
+ theSQL = [[NSMutableString alloc]initWithFormat:@"SELECT DISTINCT (NSFKEY) FROM NSFValues WHERE %@", [expression description]];
628
+ }
629
+
630
+ if ((count > 1) && (i < count-1)) {
631
+ [theSQL appendString:@" AND NSFKEY IN ("];
632
+ [parentheses appendString:@")"];
633
+ }
634
+
635
+ [sqlComponents addObject:theSQL];
609
636
  }
610
-
611
- [sqlComponents addObject:theSQL];
612
637
  }
613
638
 
614
639
  if ([parentheses length] > 0)
@@ -616,8 +641,17 @@
616
641
 
617
642
  NSString *theValue = [sqlComponents componentsJoinedByString:@""];
618
643
 
619
- if (NSFReturnObjects == returnType)
620
- theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFPlist,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theValue];
644
+ if (NSFReturnObjects == returnType) {
645
+ if (self.filterClass.length > 0) {
646
+ theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFPlist,NSFObjectClass FROM NSFKeys WHERE (NSFObjectClass = '%@') AND NSFKey IN (%@)", self.filterClass, theValue];
647
+ } else {
648
+ theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFPlist,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theValue];
649
+ }
650
+ } else {
651
+ if (self.filterClass.length > 0) {
652
+ theValue = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey) FROM NSFKeys WHERE (NSFObjectClass = '%@') AND NSFKey IN (%@)", self.filterClass, theValue];
653
+ }
654
+ }
621
655
 
622
656
  return theValue;
623
657
  }
@@ -634,6 +668,7 @@
634
668
  NSMutableString *theSQLStatement = [NSMutableString stringWithString:@"SELECT DISTINCT (NSFKEY) FROM NSFValues WHERE NSFKey IN ("];
635
669
  [theSQLStatement appendString:[preparedKeys componentsJoinedByString:@","]];
636
670
  [theSQLStatement appendString:@")"];
671
+
637
672
  theSQLStatement = [NSString stringWithFormat:@"SELECT DISTINCT (NSFKey),NSFPlist,NSFObjectClass FROM NSFKeys WHERE NSFKey IN (%@)", theSQLStatement];
638
673
 
639
674
  return theSQLStatement;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nano-store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.3.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap
16
- requirement: &70355674794300 !ruby/object:Gem::Requirement
16
+ requirement: &70222531211820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70355674794300
24
+ version_requirements: *70222531211820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: motion-cocoapods
27
- requirement: &70355674793680 !ruby/object:Gem::Requirement
27
+ requirement: &70222531210900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70355674793680
35
+ version_requirements: *70222531210900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: motion-redgreen
38
- requirement: &70355674793260 !ruby/object:Gem::Requirement
38
+ requirement: &70222531209960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70355674793260
46
+ version_requirements: *70222531209960
47
47
  description: Wrapper for NanoStore, a lightweight schema-less key-value document database
48
48
  based on sqlite, for RubyMotion.
49
49
  email: