nano-store 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -90,11 +90,14 @@ User.all # => [<User#1>, <User#2>]
90
90
  # find model by criteria
91
91
  users = User.find(:name, NSFEqualTo, "Bob")
92
92
 
93
- # or use hash
93
+ # or use Hash
94
94
  users = User.find(:name => "Bob")
95
95
  users = User.find(:name => { NSFEqualTo => "Ronald" })
96
96
  users = User.find(:name => { NSFEqualTo => "Ronald" }, :age => { NSFGreaterThan => 50 })
97
97
 
98
+ # or use Array for matching multiple values
99
+ users = User.find(:name => ["Bob", "Ronald", "Ken"])
100
+
98
101
  # Optionally sort the result with additional hash parameters
99
102
  users = User.find({:age => { NSFGreaterThan => 10 }}, {:sort => {:age => :desc}})
100
103
  ````
@@ -107,6 +107,14 @@ module NanoStore
107
107
  value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:operator, value:sub_val)
108
108
  expression.addPredicate(value, withOperator:NSFAnd)
109
109
  end
110
+ elsif val.is_a?(Array)
111
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:val.pop)
112
+ expression.addPredicate(value, withOperator:NSFAnd)
113
+
114
+ val.each do |sub_val|
115
+ value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:sub_val)
116
+ expression.addPredicate(value, withOperator:NSFOr)
117
+ end
110
118
  else
111
119
  value = NSFNanoPredicate.predicateWithColumn(NSFValueColumn, matching:NSFEqualTo, value:val)
112
120
  expression.addPredicate(value, withOperator:NSFAnd)
@@ -117,20 +125,14 @@ module NanoStore
117
125
  end
118
126
 
119
127
  SORT_MAPPING = {
120
- 'ASC' => true,
121
- 'DESC' => false,
122
- :ASC => true,
123
- :DESC => false,
124
128
  'asc' => true,
125
129
  'desc' => false,
126
- :asc => true,
127
- :desc => false,
128
130
  }
129
131
 
130
132
  def sort_descriptor_with_options(options)
131
133
  sorter = options.collect do |opt_key, opt_val|
132
- if SORT_MAPPING.keys.include?(opt_val)
133
- NSFNanoSortDescriptor.alloc.initWithAttribute(opt_key.to_s, ascending:SORT_MAPPING[opt_val])
134
+ if SORT_MAPPING.keys.include?(opt_val.to_s.downcase)
135
+ NSFNanoSortDescriptor.alloc.initWithAttribute(opt_key.to_s, ascending:SORT_MAPPING[opt_val.to_s.downcase])
134
136
  else
135
137
  raise "unsupported sort parameters: #{opt_val}"
136
138
  end
@@ -1,3 +1,3 @@
1
1
  module NanoStore
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
data/spec/finder_spec.rb CHANGED
@@ -39,6 +39,16 @@ describe "Finder" do
39
39
  user.name.should.be == "Carl"
40
40
  user.age.should.be == 4
41
41
  end
42
+
43
+ it "search object with array (OR)" do
44
+ users = User.find(:name => ["Carl", "Amy"])
45
+ users.size.should == 2
46
+
47
+ users.collect(&:name).include?("Carl").should == true
48
+ users.collect(&:name).include?("Amy").should == true
49
+ users.collect(&:name).include?("Bob").should == false
50
+ end
51
+
42
52
 
43
53
  it "search object with multiple parameters" do
44
54
  stub_user("Ronald", 18, Time.now).save
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.4
4
+ version: 0.3.5
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: &70220199532500 !ruby/object:Gem::Requirement
16
+ requirement: &70196040194380 !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: *70220199532500
24
+ version_requirements: *70196040194380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: motion-cocoapods
27
- requirement: &70220199530260 !ruby/object:Gem::Requirement
27
+ requirement: &70196040192580 !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: *70220199530260
35
+ version_requirements: *70196040192580
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: motion-redgreen
38
- requirement: &70220199528680 !ruby/object:Gem::Requirement
38
+ requirement: &70196040191580 !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: *70220199528680
46
+ version_requirements: *70196040191580
47
47
  description: Wrapper for NanoStore, a lightweight schema-less key-value document database
48
48
  based on sqlite, for RubyMotion.
49
49
  email: