uorm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/uorm.rb CHANGED
@@ -3,7 +3,6 @@ require 'uorm/version'
3
3
  require 'active_support/callbacks'
4
4
  require 'active_support/core_ext/hash'
5
5
 
6
-
7
6
  module Uorm
8
7
  autoload :Type, 'uorm/type'
9
8
  autoload :Field, 'uorm/field'
data/lib/uorm/dsl.rb CHANGED
@@ -6,8 +6,8 @@ module Uorm
6
6
  persistance.all(args).map { |attrs| new attrs }
7
7
  end
8
8
 
9
- def find args
10
- new persistance.find args
9
+ def find id
10
+ new persistance.find id
11
11
  end
12
12
 
13
13
  def create attrs
@@ -2,18 +2,24 @@ module Uorm
2
2
  module EM::Mongo
3
3
  class DB
4
4
  class << self
5
- attr_accessor :name
5
+ attr_accessor :name, :pool_size
6
6
 
7
7
  def collection coll
8
8
  db.collection coll
9
9
  end
10
10
 
11
11
  def db
12
- @db ||= connection.db name
12
+ connection.db name
13
+ end
14
+
15
+ def pool_size
16
+ @pool_size ||= 2
13
17
  end
14
18
 
15
19
  def connection
16
- @connection ||= ::EM::Mongo::Connection.new
20
+ @connection ||= ::EM::Synchrony::ConnectionPool.new(size: pool_size) do
21
+ ::EM::Mongo::Connection.new
22
+ end
17
23
  end
18
24
  end
19
25
  end
data/lib/uorm/redis.rb CHANGED
@@ -14,7 +14,7 @@ module Uorm
14
14
  end
15
15
 
16
16
  def initialize values = {}
17
- values[:id] ||= nil
17
+ values[:id] ||= values['id'] || nil
18
18
  super values
19
19
  end
20
20
 
data/lib/uorm/redis/db.rb CHANGED
@@ -2,10 +2,16 @@ module Uorm
2
2
  module Redis
3
3
  class DB
4
4
  class << self
5
- attr_accessor :nr
5
+ attr_accessor :nr, :pool_size
6
+
7
+ def pool_size
8
+ @pool_size ||= 2
9
+ end
6
10
 
7
11
  def client
8
- @client ||= ::Redis.new driver: :synchrony, db: nr
12
+ @client ||= ::EM::Synchrony::ConnectionPool.new(size: pool_size) do
13
+ ::Redis.new driver: :synchrony, db: nr
14
+ end
9
15
  end
10
16
  end
11
17
  end
@@ -14,13 +14,16 @@ module Uorm
14
14
 
15
15
  def all options = {}
16
16
  keys = collection.keys
17
+ return [] if keys.empty?
18
+
17
19
  collection.mget(keys).map do |val|
18
20
  MultiJson.load val if val
19
21
  end
20
22
  end
21
23
 
22
24
  def find id
23
- MultiJson.load collection.get id
25
+ data = collection.get id
26
+ MultiJson.load data if data
24
27
  end
25
28
 
26
29
  def create object
data/lib/uorm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uorm
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -55,12 +55,15 @@ describe ARedisModel do
55
55
  end
56
56
  end
57
57
 
58
-
59
58
  describe '.all' do
60
59
  it 'returns a collection of all objects' do
61
60
  ARedisModel.create attributes
62
61
  ARedisModel.all.should be_collection_of ARedisModel
63
62
  end
63
+
64
+ it 'returns an empty array if the collection is empty' do
65
+ ARedisModel.all.should =~ []
66
+ end
64
67
  end
65
68
 
66
69
  describe '.find' do
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.3
4
+ version: 0.0.4
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: 2012-12-27 00:00:00.000000000 Z
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport