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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2RlY2YxMjZlNWIyNzA1MTliM2FlZDI5N2ZjNTZlNjYyOTI2MjM0Ng==
4
+ MzRmZDhkYTI1YTQ4MjUwZDEzMDcxZmQ2YjM3YjRmYjUxM2UzNzQxZg==
5
5
  data.tar.gz: !binary |-
6
- ZGYyNWYyMjY2MTI1ODkzZDg1ZGMxMGYwYmNkMjA1ZmI1MTY5OGYyNA==
6
+ ZWNjODQxZGM3MjRlMjg3OTY2ODBlMGFhYWQ3MzUzYmFjNDQ0MDhmYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Y2I1ZjJlNmZmMTI0ZDhkYjU5ZjQ3NzE2NWUwNDlmMzU2MmFlNGEwNjYwMzFj
10
- ODE4OGY3NzVlYzE3MTgwM2U3MGQxMjQ0ZmIyZWY3OTJmNmI1MjY1NzE4NDcw
11
- ZjkxYTE5MzcwY2VkYzRjMmZmYWJhYzU2MjI2YzFlNzA3M2Y5ZDM=
9
+ YTBjNDdhM2ZkYTc5NjkzMTQ1MTJjZGYwMDE5YWU3ZGYxMDMwY2RhMWI5ZjRh
10
+ MGY3MzY4ZGVlYmVhNmQwNTBiZDVlYjZmMzAzZmQ2MzVmZjRmNjZmNDhjZGQ5
11
+ OTA5YjZkMGM3MmJiNDdlNjA5ZjViMDhjMDkyZTg5ZTY3ZGNhYmE=
12
12
  data.tar.gz: !binary |-
13
- ZjY0YWZkMDY3ZDNmZjQwYTEyNWE1M2U2YjEzNmY4MDM3ZDMyOGY1ZjJmZWU0
14
- NGQ1NzY4NmJmNTg4ZjcyY2VlZmJmZmZmZTNhYzA0NDczM2IzODczMTA0OWY5
15
- NmZjZDgxNjU2ZThkZjgxMTIyYWE0ZTI4M2M1MzY3MTVjNjg3Zjg=
13
+ Njk1ZWUzNGVkYjdiODFhODY4NDZiMDFlMmY1MzU5M2RmZDJlMGRhZjRmNjNk
14
+ NWExM2Y1M2ZkY2EwNzk4NGQ1NWU1ODU5YzAwNjM5ZjY4NTNmZjgzMWU0ZDU4
15
+ MzY2YTJjMDI5NjFjMDFjZDVjZjU5M2IxMDQwZDY0NDIzZTBkMmQ=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.6.0 / 2014-01-02
2
+
3
+ * 1 unknown:
4
+
5
+ * Use internal random_bytes - SecureRandom is blowing up once committed
6
+
7
+
1
8
  ### 0.5.0 / 2014-01-02
2
9
 
3
10
  * 1 enhancement:
data/lib/mem_model.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  lib_dir = File.dirname(__FILE__)
2
2
  $LOAD_PATH << lib_dir unless $LOAD_PATH.include? lib_dir
3
3
 
4
- require 'securerandom'
5
4
  require 'set'
6
5
 
7
6
  module MemModel
@@ -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
 
@@ -4,7 +4,35 @@ module MemModel
4
4
 
5
5
  module ClassMethods
6
6
  def generate_id
7
- [guid_prefix, '-', SecureRandom.uuid].join.upcase
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
@@ -1,3 +1,3 @@
1
1
  module MemModel
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/mem_model.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mem_model 0.5.0.20140102213025 ruby lib
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.5.0.20140102213025"
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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mem_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnnyT