uorm 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/uorm.rb CHANGED
@@ -3,6 +3,8 @@ require 'uorm/version'
3
3
  require 'active_support/callbacks'
4
4
  require 'active_support/core_ext/hash'
5
5
 
6
+ require 'em-synchrony'
7
+
6
8
  module Uorm
7
9
  autoload :Type, 'uorm/type'
8
10
  autoload :Field, 'uorm/field'
@@ -15,17 +17,13 @@ module Uorm
15
17
  module Redis
16
18
  autoload :Persistance, 'uorm/redis/persistance'
17
19
  autoload :DB, 'uorm/redis/db'
18
- require 'multi_json'
19
20
  end
20
21
 
21
- module EM
22
- autoload :Mongo, 'uorm/em-mongo'
22
+ autoload :Mongo, 'uorm/mongo'
23
+ module Mongo
24
+ require 'uorm/mongo/object_id'
23
25
 
24
- module Mongo
25
- require 'uorm/em-mongo/object_id'
26
- autoload :DB, 'uorm/em-mongo/db'
27
- autoload :Persistance, 'uorm/em-mongo/persistance'
28
- end
26
+ autoload :DB, 'uorm/mongo/db'
27
+ autoload :Persistance, 'uorm/mongo/persistance'
29
28
  end
30
-
31
29
  end
data/lib/uorm/dsl.rb CHANGED
@@ -21,6 +21,14 @@ module Uorm
21
21
  def create attrs
22
22
  new(attrs).save
23
23
  end
24
+
25
+ def exists? id, &block
26
+ if block_given?
27
+ peristance.exists?(id) { |bool| yield bool }
28
+ else
29
+ persistance.exists? id
30
+ end
31
+ end
24
32
  end
25
33
  end
26
34
 
@@ -1,5 +1,7 @@
1
+ require 'em-synchrony/em-mongo'
2
+
1
3
  module Uorm
2
- module EM::Mongo
4
+ module Mongo
3
5
  def self.included base
4
6
  base.instance_eval do
5
7
  field :id, type: Type::ObjectId
@@ -1,5 +1,5 @@
1
1
  module Uorm
2
- module EM::Mongo
2
+ module Mongo
3
3
  class DB
4
4
  class << self
5
5
  attr_accessor :name, :pool_size
File without changes
@@ -1,5 +1,5 @@
1
1
  module Uorm
2
- module EM::Mongo
2
+ module Mongo
3
3
  class Persistance
4
4
  attr_reader :collection, :model
5
5
 
@@ -33,11 +33,13 @@ module Uorm
33
33
  end
34
34
 
35
35
  def create object
36
- object.id = collection.insert object.attributes.except(:id)
36
+ object.id = ::EM::Synchrony.sync collection.safe_insert(object.attributes.except(:id), safe: false)
37
+ rescue
38
+ false
37
39
  end
38
40
 
39
41
  def update object
40
- collection.update({_id: object.id}, object.attributes.except(:id))
42
+ ::EM::Synchrony.sync collection.safe_update({_id: object.id}, object.attributes.except(:id), safe: false)
41
43
  end
42
44
 
43
45
  def delete object
data/lib/uorm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Uorm
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  require 'em-mongo'
4
4
  require 'em-synchrony/em-mongo'
5
5
 
6
- Uorm::EM::Mongo::DB.name = 'uorm_test'
6
+ Uorm::Mongo::DB.name = 'uorm_test'
7
7
 
8
8
  class AMongoModel
9
9
  include Uorm::DSL
10
10
  include Uorm::Attributes
11
- include Uorm::EM::Mongo
11
+ include Uorm::Mongo
12
12
 
13
13
  field :reference, type: Uorm::Type::ObjectId
14
14
  field :name, type: Uorm::Type::String
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.6
4
+ version: 0.0.7
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-28 00:00:00.000000000 Z
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -172,12 +172,12 @@ files:
172
172
  - lib/uorm/attributes.rb
173
173
  - lib/uorm/callbacks.rb
174
174
  - lib/uorm/dsl.rb
175
- - lib/uorm/em-mongo.rb
176
- - lib/uorm/em-mongo/db.rb
177
- - lib/uorm/em-mongo/object_id.rb
178
- - lib/uorm/em-mongo/persistance.rb
179
175
  - lib/uorm/field.rb
180
176
  - lib/uorm/field_collection.rb
177
+ - lib/uorm/mongo.rb
178
+ - lib/uorm/mongo/db.rb
179
+ - lib/uorm/mongo/object_id.rb
180
+ - lib/uorm/mongo/persistance.rb
181
181
  - lib/uorm/redis.rb
182
182
  - lib/uorm/redis/db.rb
183
183
  - lib/uorm/redis/persistance.rb