uorm 0.0.13 → 0.0.14
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/Gemfile.lock +3 -3
- data/lib/uorm/crud.rb +5 -5
- data/lib/uorm/crud/callbacks.rb +8 -0
- data/lib/uorm/crud/persistance_helper.rb +2 -2
- data/lib/uorm/hash.rb +0 -1
- data/lib/uorm/mongo/persistance.rb +3 -1
- data/lib/uorm/redis/persistance.rb +11 -4
- data/spec/redis_spec.rb +22 -3
- data/uorm.gemspec +1 -1
- metadata +4 -5
- data/lib/uorm/redis/adapter.rb +0 -8
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
uorm (0.0.
|
4
|
+
uorm (0.0.14)
|
5
5
|
em-synchrony
|
6
6
|
|
7
7
|
GEM
|
@@ -11,7 +11,7 @@ GEM
|
|
11
11
|
bson_ext (1.8.2)
|
12
12
|
bson (~> 1.8.2)
|
13
13
|
columnize (0.3.6)
|
14
|
-
debugger (1.
|
14
|
+
debugger (1.3.0)
|
15
15
|
columnize (>= 0.3.1)
|
16
16
|
debugger-linecache (~> 1.1.1)
|
17
17
|
debugger-ruby_core_source (~> 1.1.7)
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
rspec-core (2.12.2)
|
36
36
|
rspec-expectations (2.12.1)
|
37
37
|
diff-lcs (~> 1.1.3)
|
38
|
-
rspec-mocks (2.12.
|
38
|
+
rspec-mocks (2.12.2)
|
39
39
|
|
40
40
|
PLATFORMS
|
41
41
|
ruby
|
data/lib/uorm/crud.rb
CHANGED
@@ -11,15 +11,15 @@ module Uorm
|
|
11
11
|
base.instance_eval do
|
12
12
|
def all args = {}, &block
|
13
13
|
if block_given?
|
14
|
-
persistance.all(args) { |attrs| yield new(attrs) if attrs }
|
14
|
+
persistance.all(args) { |attrs| Fiber.new { yield new(attrs) }.resume if attrs }
|
15
15
|
else
|
16
|
-
persistance.all(args).map { |attrs| new(attrs) }
|
16
|
+
persistance.all(args).map! { |attrs| new(attrs) }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def find id, &block
|
21
21
|
if block_given?
|
22
|
-
persistance.find(id) { |attrs| yield new(attrs) if attrs }
|
22
|
+
persistance.find(id) { |attrs| Fiber.new { yield new(attrs) }.resume if attrs }
|
23
23
|
else
|
24
24
|
new persistance.find(id)
|
25
25
|
end
|
@@ -27,7 +27,7 @@ module Uorm
|
|
27
27
|
|
28
28
|
def create attrs, &block
|
29
29
|
obj = new(attrs)
|
30
|
-
|
30
|
+
block_given? ? obj.save(&block) : obj.save
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -58,7 +58,7 @@ module Uorm
|
|
58
58
|
update_attributes attrs
|
59
59
|
if block_given?
|
60
60
|
cb = ::Uorm::CRUD::Callbacks::Update.new
|
61
|
-
cb.callback(&block)
|
61
|
+
cb.callback(&block)
|
62
62
|
persistance.update self, cb
|
63
63
|
else
|
64
64
|
persistance.update self
|
data/lib/uorm/crud/callbacks.rb
CHANGED
data/lib/uorm/hash.rb
CHANGED
@@ -34,7 +34,9 @@ module Uorm
|
|
34
34
|
def update object, cb = nil
|
35
35
|
if cb
|
36
36
|
safe_update = client.safe_update({ _id: object.id }, attributes_without_id(object))
|
37
|
-
safe_update.callback
|
37
|
+
safe_update.callback do
|
38
|
+
cb.succeed object
|
39
|
+
end
|
38
40
|
else
|
39
41
|
::EM::Synchrony.sync client.safe_update({ _id: object.id }, attributes_without_id(object))
|
40
42
|
end
|
@@ -2,10 +2,13 @@ module Uorm
|
|
2
2
|
module Redis
|
3
3
|
class Persistance < Struct.new :model, :client
|
4
4
|
|
5
|
-
def all
|
6
|
-
|
7
|
-
return
|
8
|
-
|
5
|
+
def all q = {}
|
6
|
+
arr = client.keys.map { |id| self.find id }
|
7
|
+
return arr if q.empty? or arr.empty?
|
8
|
+
|
9
|
+
if have_query?(q, arr)
|
10
|
+
arr.select! { |attrs| q.all? { |key, value| attrs[key] == value } }
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
def find id
|
@@ -27,6 +30,10 @@ module Uorm
|
|
27
30
|
|
28
31
|
private
|
29
32
|
|
33
|
+
def have_query? q, coll
|
34
|
+
q and coll.all? { |attrs| attrs.respond_to?(:[]) }
|
35
|
+
end
|
36
|
+
|
30
37
|
def write object
|
31
38
|
client.mapped_hmset object.id, object.attributes
|
32
39
|
end
|
data/spec/redis_spec.rb
CHANGED
@@ -26,8 +26,8 @@ describe ARedisModel do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
let(:client) { Redis.new(db: 15, driver: :synchrony).tap(&:flushdb) }
|
29
|
-
let(:persistance) {
|
30
|
-
let(:test_persistance) {
|
29
|
+
let(:persistance) { ARedisModel.persistance = Uorm::Redis::Persistance.new ARedisModel, client }
|
30
|
+
let(:test_persistance) { ARedisModel.persistance = Uorm::Mongo::TestPerstistance.new }
|
31
31
|
|
32
32
|
before { test_persistance }
|
33
33
|
|
@@ -66,7 +66,26 @@ describe ARedisModel do
|
|
66
66
|
|
67
67
|
it 'returns an empty array if the client is empty' do
|
68
68
|
EM.synchrony do
|
69
|
-
ARedisModel.all.should
|
69
|
+
ARedisModel.all.should be_empty
|
70
|
+
|
71
|
+
EM.stop
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'retuns all objects for the given query' do
|
76
|
+
EM.synchrony do
|
77
|
+
persistance.create ARedisModel.new name: 'findme'
|
78
|
+
persistance.create ARedisModel.new dollars: 3.2
|
79
|
+
ARedisModel.all(name: 'findme').should be_collection_of ARedisModel
|
80
|
+
|
81
|
+
EM.stop
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'resturns an empty array if the given query gives no match' do
|
86
|
+
EM.synchrony do
|
87
|
+
persistance.create ARedisModel.new name: 'dont'
|
88
|
+
ARedisModel.all(name: 'find').should be_empty
|
70
89
|
|
71
90
|
EM.stop
|
72
91
|
end
|
data/uorm.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = 'uorm'
|
7
|
-
gem.version = '0.0.
|
7
|
+
gem.version = '0.0.14'
|
8
8
|
gem.authors = ['Dennis Rogenius']
|
9
9
|
gem.email = ['denro03@gmail.com']
|
10
10
|
gem.description = %q{A modular, flexible and lightweight ORM}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uorm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: em-synchrony
|
@@ -167,7 +167,6 @@ files:
|
|
167
167
|
- lib/uorm/mongo/object_id.rb
|
168
168
|
- lib/uorm/mongo/persistance.rb
|
169
169
|
- lib/uorm/redis.rb
|
170
|
-
- lib/uorm/redis/adapter.rb
|
171
170
|
- lib/uorm/redis/persistance.rb
|
172
171
|
- spec/mongo_spec.rb
|
173
172
|
- spec/redis_spec.rb
|
@@ -189,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
188
|
version: '0'
|
190
189
|
segments:
|
191
190
|
- 0
|
192
|
-
hash:
|
191
|
+
hash: -591575284162330363
|
193
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
193
|
none: false
|
195
194
|
requirements:
|
@@ -198,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
197
|
version: '0'
|
199
198
|
segments:
|
200
199
|
- 0
|
201
|
-
hash:
|
200
|
+
hash: -591575284162330363
|
202
201
|
requirements: []
|
203
202
|
rubyforge_project:
|
204
203
|
rubygems_version: 1.8.24
|