ruuid 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12955371c15837c3d5bd2ab62753e04852114933
4
- data.tar.gz: 154a406dce57289289633ca8107e24c372bde09f
3
+ metadata.gz: e771cd338893fc6ba98871678208daffbac1d5c4
4
+ data.tar.gz: 8383b56ae6a40be9be60fa9655177a53ca551b8b
5
5
  SHA512:
6
- metadata.gz: 520286586d5dc145c9f5872ec9f24c07e16920350175f8541bb93757ea262aab4a91a62f8f06edc3effccd06bc76da4cb6f38c44a714ef391293e628d0b731ad
7
- data.tar.gz: f3a64c3fc5840bb2b1bf89d8ebaa76a8f0432829d64ff4e2c713150233519336b84803842ca4b32f887605ebaaf2b7e12c83114204fddc6b01ed5506b0b27e76
6
+ metadata.gz: 67467a1ddabc1f10de041011c4cb9529776ea312f4eda91691e55d5a7f8463197ddaa798c181828ab653f919d5268455f6c0170ff1824a63af4fa24b4791f9e6
7
+ data.tar.gz: c711cb679f5e90c59c3d2ee3bcf414e00f06559e11358c6cdde09806d5a5478c32cc48a667a24ce5102e58538c9e39b7572a86150f4489f5559fa36fed183014
data/README.md CHANGED
@@ -30,7 +30,7 @@ Or install it yourself as:
30
30
  ```ruby
31
31
  require 'ruuid'
32
32
 
33
- uuid = RUUID.generate
33
+ uuid = RUUID::UUID.new
34
34
  # => <RUUID::UUID:0x70168845476220 data=7cc9f80c-c2e2-4d03-ad35-1e3112dc77de>
35
35
 
36
36
  uuid.version
@@ -31,7 +31,12 @@ module RUUID
31
31
  end
32
32
 
33
33
  def generate
34
- UUID.from_data(masked_bytes)
34
+ raw_bytes.tap { |bytes|
35
+ # Mask version
36
+ bytes[6] = (bytes[6] & 0x0f) | (version << 4)
37
+ # Mask variant
38
+ bytes[8] = (bytes[8] & 0x3f) | 0x80
39
+ }.collect(&:chr).join
35
40
  end
36
41
 
37
42
  private
@@ -42,14 +47,5 @@ module RUUID
42
47
  end
43
48
  source.call.bytes
44
49
  end
45
-
46
- def masked_bytes
47
- raw_bytes.tap { |bytes|
48
- # Mask version
49
- bytes[6] = (bytes[6] & 0x0f) | (version << 4)
50
- # Mask variant
51
- bytes[8] = (bytes[8] & 0x3f) | 0x80
52
- }.collect(&:chr).join
53
- end
54
50
  end # Generator
55
51
  end # RUUID
data/lib/ruuid/uuid.rb CHANGED
@@ -2,24 +2,15 @@ module RUUID
2
2
  class UUID
3
3
  include Comparable
4
4
 
5
- # @private
6
- def self.from_data(data)
7
- uuid = allocate
8
- uuid.instance_variable_set :@data, data.dup.freeze
9
- uuid.validate
10
- uuid
11
- end
12
-
13
5
  def self.parse(string)
14
- from_data(Parser.parse(string))
6
+ new(Parser.parse(string))
15
7
  end
16
8
 
17
- # @private
18
- def initialize
19
- raise RuntimeError, 'RUUID::UUID.new is not allowed. Use RUUID.generate instead.'
9
+ def initialize(data = RUUID.default_generator.generate)
10
+ @data = normalize(data)
11
+ validate
20
12
  end
21
13
 
22
- # @private
23
14
  attr_reader :data
24
15
 
25
16
  def to_s(format = RUUID.default_format)
@@ -70,7 +61,8 @@ module RUUID
70
61
  data.bytes[6] >> 4
71
62
  end
72
63
 
73
- # @private
64
+ private
65
+
74
66
  def validate
75
67
  unless data.length == 16
76
68
  raise InvalidUUIDError, 'Invalid UUID length'
@@ -80,5 +72,9 @@ module RUUID
80
72
  raise InvalidUUIDError, 'Invalid UUID variant'
81
73
  end
82
74
  end
75
+
76
+ def normalize(data)
77
+ data.dup.force_encoding(Encoding::BINARY).freeze
78
+ end
83
79
  end # UUID
84
80
  end # RUUID
data/lib/ruuid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RUUID
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/ruuid.rb CHANGED
@@ -16,8 +16,4 @@ module RUUID
16
16
 
17
17
  attr_accessor :default_format
18
18
  self.default_format = :canonical
19
-
20
- def generate
21
- default_generator.generate
22
- end
23
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler