mem_model 0.5.0 → 0.6.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 +7 -0
- data/lib/mem_model.rb +0 -1
- data/lib/mem_model/base.rb +4 -5
- data/lib/mem_model/guid.rb +29 -1
- data/lib/mem_model/version.rb +1 -1
- data/mem_model.gemspec +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzRmZDhkYTI1YTQ4MjUwZDEzMDcxZmQ2YjM3YjRmYjUxM2UzNzQxZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWNjODQxZGM3MjRlMjg3OTY2ODBlMGFhYWQ3MzUzYmFjNDQ0MDhmYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTBjNDdhM2ZkYTc5NjkzMTQ1MTJjZGYwMDE5YWU3ZGYxMDMwY2RhMWI5ZjRh
|
10
|
+
MGY3MzY4ZGVlYmVhNmQwNTBiZDVlYjZmMzAzZmQ2MzVmZjRmNjZmNDhjZGQ5
|
11
|
+
OTA5YjZkMGM3MmJiNDdlNjA5ZjViMDhjMDkyZTg5ZTY3ZGNhYmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Njk1ZWUzNGVkYjdiODFhODY4NDZiMDFlMmY1MzU5M2RmZDJlMGRhZjRmNjNk
|
14
|
+
NWExM2Y1M2ZkY2EwNzk4NGQ1NWU1ODU5YzAwNjM5ZjY4NTNmZjgzMWU0ZDU4
|
15
|
+
MzY2YTJjMDI5NjFjMDFjZDVjZjU5M2IxMDQwZDY0NDIzZTBkMmQ=
|
data/CHANGELOG.md
CHANGED
data/lib/mem_model.rb
CHANGED
data/lib/mem_model/base.rb
CHANGED
@@ -38,10 +38,6 @@ module MemModel
|
|
38
38
|
all[-1]
|
39
39
|
end
|
40
40
|
|
41
|
-
def generate_id
|
42
|
-
object_id
|
43
|
-
end
|
44
|
-
|
45
41
|
# Find or nil
|
46
42
|
def find(id)
|
47
43
|
store.detect{ |r| r.id == id }
|
@@ -92,10 +88,13 @@ module MemModel
|
|
92
88
|
|
93
89
|
def initialize(attributes = {})
|
94
90
|
@persisted = false unless maglev?
|
95
|
-
self.id = self.class.generate_id
|
96
91
|
load_attributes(attributes)
|
92
|
+
self.id ||= self.generate_id
|
97
93
|
end
|
98
94
|
|
95
|
+
def generate_id
|
96
|
+
object_id
|
97
|
+
end
|
99
98
|
|
100
99
|
def model_name; self.class.model_name; end
|
101
100
|
|
data/lib/mem_model/guid.rb
CHANGED
@@ -4,7 +4,35 @@ module MemModel
|
|
4
4
|
|
5
5
|
module ClassMethods
|
6
6
|
def generate_id
|
7
|
-
[guid_prefix, '-',
|
7
|
+
[guid_prefix, '-', new_uuid].join.upcase
|
8
|
+
end
|
9
|
+
|
10
|
+
def random_bytes(n=16)
|
11
|
+
flags = File::RDONLY
|
12
|
+
flags |= File::NONBLOCK if defined? File::NONBLOCK
|
13
|
+
flags |= File::NOCTTY if defined? File::NOCTTY
|
14
|
+
flags |= File::NOFOLLOW if defined? File::NOFOLLOW
|
15
|
+
begin
|
16
|
+
File.open("/dev/urandom", flags) {|f|
|
17
|
+
unless f.stat.chardev?
|
18
|
+
raise Errno::ENOENT
|
19
|
+
end
|
20
|
+
ret = f.readpartial(n)
|
21
|
+
if ret.length != n
|
22
|
+
raise NotImplementedError, "Unexpected partial read from random device"
|
23
|
+
end
|
24
|
+
return ret
|
25
|
+
}
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
raise NotImplementedError, "No random device"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_uuid
|
32
|
+
ary = self.random_bytes(16).unpack("NnnnnN")
|
33
|
+
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
34
|
+
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
35
|
+
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
8
36
|
end
|
9
37
|
|
10
38
|
def guid_prefix
|
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.6.0.20140102221058 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.6.0.20140102221058"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["JohnnyT"]
|