mem_model 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +8 -0
- data/lib/mem_model.rb +19 -1
- data/lib/mem_model/base.rb +32 -16
- data/lib/mem_model/guid.rb +12 -8
- data/lib/mem_model/rooted_base.rb +4 -23
- data/lib/mem_model/version.rb +1 -1
- data/mem_model.gemspec +2 -2
- data/test/mem_model/test_rooted_base.rb +4 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjdiMTBhMWRhMGZmMWRkMDlkOGEwODJmNDUzYmJmOWFkODU0ZWJkZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjM2OTc3OWQ1ODlmOTJjZGQ4NDY3MDliNDlkMWQ3MTdlOTc5ZDlhNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTUzOTMwN2ViZjM1Y2Q4N2VhZDU4OWRkZDAyYjJkZjZiNjhlNGFjY2U2Y2Y2
|
10
|
+
YzY4YmEyYjY2MGYyZmJmNTM2MGVhN2NkZGU0MTFkNTUyNmI0NjBlNTM3MjMx
|
11
|
+
OWU5YTg2ZTgxMDI4MmUyOTk4MjM1YjJkNzVjZjk0ZDBmNzUxZGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWYyMjgzODkwNTQxZGU5ZTc4ZWQ4MzFlZmRiZGEwN2MxYjYwNWEzNmEyNjgx
|
14
|
+
MDk1NzllNmMyZGMzZmRkMjY2ZjMzOGM3Njk5OTYwMTAxZDYxYTkzMGM4ZmQz
|
15
|
+
ZGY2ZTEzZjA1NDE5YjFkMmM3NTlhMzdkY2E3NWI2NzBlZGQxYTY=
|
data/CHANGELOG.md
CHANGED
data/lib/mem_model.rb
CHANGED
@@ -7,7 +7,25 @@ module MemModel
|
|
7
7
|
def maglev?
|
8
8
|
!defined?(Maglev).nil?
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
|
+
def commit
|
12
|
+
maglev? ? Maglev.commit_transaction : true
|
13
|
+
end
|
14
|
+
|
15
|
+
def abort
|
16
|
+
maglev? ? Maglev.abort_transaction : true
|
17
|
+
end
|
18
|
+
|
19
|
+
def persistent(&block)
|
20
|
+
if maglev?
|
21
|
+
Maglev.persistent{ block.call }
|
22
|
+
commit
|
23
|
+
else
|
24
|
+
block.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function :maglev?, :commit, :abort, :persistent
|
11
29
|
end
|
12
30
|
|
13
31
|
%w[ concern base errors guid model_name rooted_base validations version ].each do |file|
|
data/lib/mem_model/base.rb
CHANGED
@@ -4,6 +4,7 @@ module MemModel
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
include MemModel::Validations
|
7
|
+
include MemModel::Guid
|
7
8
|
attr_accessor :id
|
8
9
|
end
|
9
10
|
|
@@ -70,13 +71,11 @@ module MemModel
|
|
70
71
|
end
|
71
72
|
|
72
73
|
def abort
|
73
|
-
|
74
|
-
true
|
74
|
+
MemModel.abort
|
75
75
|
end
|
76
76
|
|
77
77
|
def commit
|
78
|
-
|
79
|
-
true
|
78
|
+
MemModel.commit
|
80
79
|
end
|
81
80
|
|
82
81
|
alias_method :to_str, :to_s
|
@@ -84,6 +83,16 @@ module MemModel
|
|
84
83
|
def delete(record)
|
85
84
|
store.delete(record)
|
86
85
|
end
|
86
|
+
|
87
|
+
if !MemModel.maglev?
|
88
|
+
def committed?; false; end
|
89
|
+
end
|
90
|
+
|
91
|
+
def persistent(&block)
|
92
|
+
committed? ?
|
93
|
+
MemModel.persistent(&block) :
|
94
|
+
block.call
|
95
|
+
end
|
87
96
|
end
|
88
97
|
|
89
98
|
def initialize(attributes = {})
|
@@ -98,11 +107,25 @@ module MemModel
|
|
98
107
|
|
99
108
|
def model_name; self.class.model_name; end
|
100
109
|
|
101
|
-
|
110
|
+
if !MemModel.maglev?
|
102
111
|
def committed?; @persisted == true; end
|
103
112
|
end
|
104
|
-
|
105
|
-
|
113
|
+
|
114
|
+
def class_committed?
|
115
|
+
self.class.committed?
|
116
|
+
end
|
117
|
+
|
118
|
+
def persisted?
|
119
|
+
class_committed? ?
|
120
|
+
committed? :
|
121
|
+
@persisted == true
|
122
|
+
end
|
123
|
+
alias_method :exists?, :persisted?
|
124
|
+
|
125
|
+
def new?
|
126
|
+
!persisted?
|
127
|
+
end
|
128
|
+
alias_method :new_record?, :new?
|
106
129
|
|
107
130
|
def to_key; end
|
108
131
|
def to_param; end
|
@@ -110,7 +133,6 @@ module MemModel
|
|
110
133
|
|
111
134
|
def errors; @errors ||= Errors.new(self); end
|
112
135
|
|
113
|
-
|
114
136
|
def maglev?
|
115
137
|
self.class.maglev?
|
116
138
|
end
|
@@ -124,15 +146,9 @@ module MemModel
|
|
124
146
|
end
|
125
147
|
|
126
148
|
def persistent(&block)
|
127
|
-
|
128
|
-
block.call
|
149
|
+
self.class.persistent(&block)
|
129
150
|
end
|
130
151
|
|
131
|
-
def new?
|
132
|
-
!persisted?
|
133
|
-
end
|
134
|
-
alias_method :new_record?, :new?
|
135
|
-
|
136
152
|
def save
|
137
153
|
new? ? create : update
|
138
154
|
end
|
@@ -141,7 +157,7 @@ module MemModel
|
|
141
157
|
self.id ||= generate_id
|
142
158
|
persistent do
|
143
159
|
self.class.store << self
|
144
|
-
@persisted = true unless
|
160
|
+
@persisted = true unless class_committed?
|
145
161
|
end
|
146
162
|
self.id
|
147
163
|
end
|
data/lib/mem_model/guid.rb
CHANGED
@@ -2,11 +2,23 @@ module MemModel
|
|
2
2
|
module Guid
|
3
3
|
extend MemModel::Concern
|
4
4
|
|
5
|
+
def generate_id
|
6
|
+
self.class.generate_id
|
7
|
+
end
|
8
|
+
|
5
9
|
module ClassMethods
|
6
10
|
def generate_id
|
7
11
|
[guid_prefix, '-', new_uuid].join.upcase
|
8
12
|
end
|
9
13
|
|
14
|
+
def guid_prefix
|
15
|
+
name[0...3]
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_all_matching(substring)
|
19
|
+
store.select{ |r| r.id.include?(substring.to_s.upcase) }
|
20
|
+
end
|
21
|
+
|
10
22
|
def random_bytes(n=16)
|
11
23
|
flags = File::RDONLY
|
12
24
|
flags |= File::NONBLOCK if defined? File::NONBLOCK
|
@@ -34,14 +46,6 @@ module MemModel
|
|
34
46
|
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
35
47
|
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
36
48
|
end
|
37
|
-
|
38
|
-
def guid_prefix
|
39
|
-
name[0...3]
|
40
|
-
end
|
41
|
-
|
42
|
-
def find_all_matching(substring)
|
43
|
-
store.select{ |r| r.id.include?(substring.to_s.upcase) }
|
44
|
-
end
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
@@ -3,7 +3,10 @@ module MemModel
|
|
3
3
|
|
4
4
|
module RootedBase
|
5
5
|
extend MemModel::Concern
|
6
|
-
|
6
|
+
|
7
|
+
included do
|
8
|
+
include MemModel::Base
|
9
|
+
end
|
7
10
|
|
8
11
|
module ClassMethods
|
9
12
|
def root_container
|
@@ -22,28 +25,6 @@ module MemModel
|
|
22
25
|
def root
|
23
26
|
@root ||= root_container::PERSISTENT_ROOT
|
24
27
|
end
|
25
|
-
|
26
|
-
def abort
|
27
|
-
Maglev.abort_transaction if maglev?
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def commit
|
32
|
-
Maglev.commit_transaction if maglev?
|
33
|
-
true
|
34
|
-
end
|
35
|
-
|
36
|
-
def persistent(&block)
|
37
|
-
abort
|
38
|
-
maglev? ?
|
39
|
-
Maglev.persistent { block.call } :
|
40
|
-
block.call
|
41
|
-
commit
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def persistent(&block)
|
46
|
-
self.class.persistent(&block)
|
47
28
|
end
|
48
29
|
end
|
49
30
|
end
|
data/lib/mem_model/version.rb
CHANGED
data/mem_model.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mem_model 0.
|
2
|
+
# stub: mem_model 0.7.0.20140103165733 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mem_model"
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.7.0.20140103165733"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["JohnnyT"]
|
@@ -18,23 +18,10 @@ class TestRootedBase < Minitest::Test
|
|
18
18
|
refute Account.exists? 314159
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@account.save
|
26
|
-
end
|
27
|
-
@account.abort
|
28
|
-
end
|
29
|
-
|
30
|
-
else
|
31
|
-
|
32
|
-
def test_mri_exists
|
33
|
-
refute Account.exists? @account.id
|
34
|
-
@account.save
|
35
|
-
assert Account.exists? @account.id
|
36
|
-
end
|
37
|
-
|
21
|
+
def test_exists
|
22
|
+
refute Account.exists? @account.id
|
23
|
+
@account.save
|
24
|
+
assert Account.exists? @account.id
|
38
25
|
end
|
39
26
|
|
40
27
|
def test_root_container
|