nano-store 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nano-store (0.3.2)
4
+ nano-store (0.3.5)
5
5
  bubble-wrap (>= 0.1.1)
6
- motion-cocoapods (>= 1.0.1)
6
+ motion-cocoapods (>= 1.0.2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -11,7 +11,7 @@ GEM
11
11
  bubble-wrap (0.1.1)
12
12
  cocoapods (0.5.1)
13
13
  xcodeproj (~> 0.1.0)
14
- motion-cocoapods (1.0.1)
14
+ motion-cocoapods (1.0.2)
15
15
  cocoapods (>= 0.5.1)
16
16
  motion-redgreen (0.0.2)
17
17
  xcodeproj (0.1.0)
@@ -1,7 +1,18 @@
1
1
  module NanoStore
2
2
  module FinderMethods
3
3
  def all(*args)
4
- find({}, *args)
4
+ if args[0].is_a?(Hash)
5
+ sort_options = args[0][:sort] || {}
6
+ else
7
+ sort_options = {}
8
+ end
9
+
10
+ if sort_options.empty?
11
+ self.store.objectsOfClassNamed(self.to_s)
12
+ else
13
+ sort_descriptors = sort_descriptor_with_options(sort_options)
14
+ self.store.objectsOfClassNamed(self.to_s, usingSortDescriptors:sort_descriptors)
15
+ end
5
16
  end
6
17
 
7
18
  # find model by criteria
@@ -46,7 +57,9 @@ module NanoStore
46
57
  error_ptr = Pointer.new(:id)
47
58
  searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
48
59
  raise NanoStoreError, error_ptr[0].description if error_ptr[0]
49
- searchResults
60
+
61
+ # workaround until we find way to only query specific class
62
+ searchResults.select {|obj| obj.class == self }
50
63
  end
51
64
 
52
65
  # find model keys by criteria
@@ -90,9 +103,13 @@ module NanoStore
90
103
  search.sort = sort_descriptors
91
104
 
92
105
  error_ptr = Pointer.new(:id)
93
- searchResults = search.searchObjectsWithReturnType(NSFReturnKeys, error:error_ptr)
106
+
107
+ search.attributesToBeReturned = ["NSFObjectClass", "NSFKey"]
108
+ searchResults = search.searchObjectsWithReturnType(NSFReturnObjects, error:error_ptr)
94
109
  raise NanoStoreError, error_ptr[0].description if error_ptr[0]
95
- searchResults
110
+
111
+ # workaround until we find way to only query specific class
112
+ searchResults.select {|obj| obj.class == self }.collect(&:key)
96
113
  end
97
114
 
98
115
  protected
@@ -101,7 +118,6 @@ module NanoStore
101
118
  options.each do |key, val|
102
119
  attribute = NSFNanoPredicate.predicateWithColumn(NSFAttributeColumn, matching:NSFEqualTo, value:key.to_s)
103
120
  expression = NSFNanoExpression.expressionWithPredicate(attribute)
104
-
105
121
  if val.is_a?(Hash)
106
122
  val.each do |operator, sub_val|
107
123
  value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:operator, value:sub_val)
@@ -23,7 +23,7 @@ module NanoStore
23
23
  name = matched[1]
24
24
  modifier = matched[2]
25
25
 
26
- if self.class.attributes.include?(name.to_sym) || name == "_id"
26
+ if self.class.attributes.include?(name.to_sym)
27
27
  if modifier == "="
28
28
  if args[0].nil?
29
29
  self.info.delete(name.to_sym)
@@ -84,15 +84,6 @@ module NanoStore
84
84
  subclass.instance_variable_set(:@attributes, [])
85
85
  subclass.instance_variable_set(:@store, nil)
86
86
  end
87
-
88
- private
89
- def search_with_store(store, attribute, match, value)
90
- search = NSFNanoSearch.searchWithStore(self.store)
91
- search.attribute = attribute.to_s
92
- search.match = match
93
- search.value = value
94
- search
95
- end
96
87
  end
97
88
 
98
89
  class Model < NSFNanoObject
@@ -1,3 +1,3 @@
1
1
  module NanoStore
2
- VERSION = "0.3.5"
2
+ VERSION = "0.3.6"
3
3
  end
data/nano-store.gemspec CHANGED
@@ -15,6 +15,6 @@ Gem::Specification.new do |gem|
15
15
  gem.version = NanoStore::VERSION
16
16
 
17
17
  gem.add_dependency 'bubble-wrap', '>= 0.1.1'
18
- gem.add_dependency 'motion-cocoapods', '>= 1.0.1'
18
+ gem.add_dependency 'motion-cocoapods', '>= 1.0.2'
19
19
  gem.add_development_dependency 'motion-redgreen'
20
20
  end
data/spec/finder_spec.rb CHANGED
@@ -1,4 +1,10 @@
1
1
  describe "Finder" do
2
+ class Car < NanoStore::Model
3
+ attribute :name
4
+ attribute :created_at
5
+ end
6
+
7
+
2
8
  def stub_user(name, age, created_at)
3
9
  user = User.new
4
10
  user.name = name
@@ -121,6 +127,19 @@ describe "Finder" do
121
127
  users.size.should == 9
122
128
  users.first.name.should == "Carl"
123
129
  end
130
+
131
+ it "#all only return objects of the class" do
132
+ Car.create(:name => "Honda")
133
+ Car.count.should == 1
134
+ Car.all.size.should == 1
135
+ end
136
+
137
+ it "#find only return objects of the class" do
138
+ Car.create(:name => "Honda")
139
+ Car.count.should == 1
140
+ Car.find({}).size.should == 1
141
+ Car.find_keys({}).size.should == 1
142
+ end
124
143
 
125
144
 
126
145
  end
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.5
4
+ version: 0.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bubble-wrap
16
- requirement: &70196040194380 !ruby/object:Gem::Requirement
16
+ requirement: &70301664740020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 0.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70196040194380
24
+ version_requirements: *70301664740020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: motion-cocoapods
27
- requirement: &70196040192580 !ruby/object:Gem::Requirement
27
+ requirement: &70301664739380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.1
32
+ version: 1.0.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70196040192580
35
+ version_requirements: *70301664739380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: motion-redgreen
38
- requirement: &70196040191580 !ruby/object:Gem::Requirement
38
+ requirement: &70301664738860 !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: *70196040191580
46
+ version_requirements: *70301664738860
47
47
  description: Wrapper for NanoStore, a lightweight schema-less key-value document database
48
48
  based on sqlite, for RubyMotion.
49
49
  email: