mingo 0.4.2 → 0.4.3
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/lib/mingo/persistence.rb +36 -38
- metadata +29 -36
data/lib/mingo/persistence.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_support/concern'
|
|
3
3
|
class Mingo
|
4
4
|
module Persistence
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
6
|
+
|
7
7
|
module ClassMethods
|
8
8
|
def create(obj = nil)
|
9
9
|
new(obj).tap do |object|
|
@@ -12,52 +12,50 @@ class Mingo
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
module InstanceMethods
|
17
|
-
def initialize(*args)
|
18
|
-
@destroyed = false
|
19
|
-
super
|
20
|
-
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
def initialize(*args)
|
17
|
+
@destroyed = false
|
18
|
+
super
|
19
|
+
end
|
25
20
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
def persisted?
|
22
|
+
!!id
|
23
|
+
end
|
24
|
+
|
25
|
+
def save(options = {})
|
26
|
+
if persisted?
|
27
|
+
hash = values_for_update
|
28
|
+
unless %w[$set $unset] == hash.keys && hash.values.all? { |v| v.empty? }
|
29
|
+
update(hash, options)
|
34
30
|
end
|
31
|
+
else
|
32
|
+
self['_id'] = self.class.collection.insert(self.to_hash, options)
|
35
33
|
end
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def update(doc, options = {})
|
37
|
+
self.class.collection.update({'_id' => self.id}, doc, options)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
def reload
|
41
|
+
doc = self.class.first(id, :transformer => nil)
|
42
|
+
replace doc
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def destroy
|
46
|
+
self.class.collection.remove('_id' => self.id)
|
47
|
+
@destroyed = true
|
48
|
+
self.freeze
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
private
|
51
|
+
def destroyed?
|
52
|
+
@destroyed
|
53
|
+
end
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
private
|
56
|
+
|
57
|
+
def values_for_update
|
58
|
+
self.to_hash
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
metadata
CHANGED
@@ -1,37 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mingo
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.4.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Mislav Marohnić
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: mongo
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70278114958640 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
24
22
|
type: :runtime
|
25
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70278114958640
|
26
25
|
description: Mingo is a minimal document-object mapper for MongoDB.
|
27
26
|
email: mislav.marohnic@gmail.com
|
28
27
|
executables: []
|
29
|
-
|
30
28
|
extensions: []
|
31
|
-
|
32
29
|
extra_rdoc_files: []
|
33
|
-
|
34
|
-
files:
|
30
|
+
files:
|
35
31
|
- Rakefile
|
36
32
|
- lib/mingo/callbacks.rb
|
37
33
|
- lib/mingo/changes.rb
|
@@ -46,30 +42,27 @@ files:
|
|
46
42
|
- spec/mingo_spec.rb
|
47
43
|
homepage: http://github.com/mislav/mingo
|
48
44
|
licenses: []
|
49
|
-
|
50
45
|
post_install_message:
|
51
46
|
rdoc_options: []
|
52
|
-
|
53
|
-
require_paths:
|
47
|
+
require_paths:
|
54
48
|
- lib
|
55
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
50
|
none: false
|
57
|
-
requirements:
|
58
|
-
- -
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
56
|
none: false
|
63
|
-
requirements:
|
64
|
-
- -
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
67
61
|
requirements: []
|
68
|
-
|
69
62
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
63
|
+
rubygems_version: 1.8.12
|
71
64
|
signing_key:
|
72
65
|
specification_version: 3
|
73
66
|
summary: Minimal Mongo
|
74
67
|
test_files: []
|
75
|
-
|
68
|
+
has_rdoc:
|