json-schema 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -18,7 +18,7 @@ From the git repo:
18
18
 
19
19
  <pre>
20
20
  $ gem build json-schema.gemspec
21
- $ gem install json-schema-0.9.6.gem
21
+ $ gem install json-schema-0.9.7.gem
22
22
  </pre>
23
23
 
24
24
 
@@ -28,256 +28,258 @@ require 'digest/md5'
28
28
  require 'digest/sha1'
29
29
  require 'tmpdir'
30
30
 
31
- module SimpleUUID
31
+ module JSON
32
+ module Util
32
33
 
33
- # Pure ruby UUID generator, which is compatible with RFC4122
34
- UUID = Struct.new :raw_bytes
34
+ # Pure ruby UUID generator, which is compatible with RFC4122
35
+ UUID = Struct.new :raw_bytes
35
36
 
36
- class UUID
37
- private_class_method :new
37
+ class UUID
38
+ private_class_method :new
38
39
 
39
- class << self
40
- def mask19 v, str # :nodoc
41
- nstr = str.bytes.to_a
42
- version = [0, 16, 32, 48, 64, 80][v]
43
- nstr[6] &= 0b00001111
44
- nstr[6] |= version
45
- # nstr[7] &= 0b00001111
46
- # nstr[7] |= 0b01010000
47
- nstr[8] &= 0b00111111
48
- nstr[8] |= 0b10000000
49
- str = ''
50
- nstr.each { |s| str << s.chr }
51
- str
52
- end
40
+ class << self
41
+ def mask19 v, str # :nodoc
42
+ nstr = str.bytes.to_a
43
+ version = [0, 16, 32, 48, 64, 80][v]
44
+ nstr[6] &= 0b00001111
45
+ nstr[6] |= version
46
+ # nstr[7] &= 0b00001111
47
+ # nstr[7] |= 0b01010000
48
+ nstr[8] &= 0b00111111
49
+ nstr[8] |= 0b10000000
50
+ str = ''
51
+ nstr.each { |s| str << s.chr }
52
+ str
53
+ end
53
54
 
54
- def mask18 v, str # :nodoc
55
- version = [0, 16, 32, 48, 64, 80][v]
56
- str[6] &= 0b00001111
57
- str[6] |= version
58
- # str[7] &= 0b00001111
59
- # str[7] |= 0b01010000
60
- str[8] &= 0b00111111
61
- str[8] |= 0b10000000
62
- str
63
- end
55
+ def mask18 v, str # :nodoc
56
+ version = [0, 16, 32, 48, 64, 80][v]
57
+ str[6] &= 0b00001111
58
+ str[6] |= version
59
+ # str[7] &= 0b00001111
60
+ # str[7] |= 0b01010000
61
+ str[8] &= 0b00111111
62
+ str[8] |= 0b10000000
63
+ str
64
+ end
64
65
 
65
- def mask v, str
66
- if RUBY_VERSION >= "1.9.0"
67
- return mask19 v, str
68
- else
69
- return mask18 v, str
70
- end
71
- end
72
- private :mask, :mask18, :mask19
66
+ def mask v, str
67
+ if RUBY_VERSION >= "1.9.0"
68
+ return mask19 v, str
69
+ else
70
+ return mask18 v, str
71
+ end
72
+ end
73
+ private :mask, :mask18, :mask19
73
74
 
74
- # UUID generation using SHA1. Recommended over create_md5.
75
- # Namespace object is another UUID, some of them are pre-defined below.
76
- def create_sha1 str, namespace
77
- sha1 = Digest::SHA1.new
78
- sha1.update namespace.raw_bytes
79
- sha1.update str
80
- sum = sha1.digest
81
- raw = mask 5, sum[0..15]
82
- ret = new raw
83
- ret.freeze
84
- ret
85
- end
86
- alias :create_v5 :create_sha1
75
+ # UUID generation using SHA1. Recommended over create_md5.
76
+ # Namespace object is another UUID, some of them are pre-defined below.
77
+ def create_sha1 str, namespace
78
+ sha1 = Digest::SHA1.new
79
+ sha1.update namespace.raw_bytes
80
+ sha1.update str
81
+ sum = sha1.digest
82
+ raw = mask 5, sum[0..15]
83
+ ret = new raw
84
+ ret.freeze
85
+ ret
86
+ end
87
+ alias :create_v5 :create_sha1
87
88
 
88
- # UUID generation using MD5 (for backward compat.)
89
- def create_md5 str, namespace
90
- md5 = Digest::MD5.new
91
- md5.update namespace.raw_bytes
92
- md5.update str
93
- sum = md5.digest
94
- raw = mask 3, sum[0..16]
95
- ret = new raw
96
- ret.freeze
97
- ret
98
- end
99
- alias :create_v3 :create_md5
89
+ # UUID generation using MD5 (for backward compat.)
90
+ def create_md5 str, namespace
91
+ md5 = Digest::MD5.new
92
+ md5.update namespace.raw_bytes
93
+ md5.update str
94
+ sum = md5.digest
95
+ raw = mask 3, sum[0..16]
96
+ ret = new raw
97
+ ret.freeze
98
+ ret
99
+ end
100
+ alias :create_v3 :create_md5
100
101
 
101
- # UUID generation using random-number generator. From it's random
102
- # nature, there's no warranty that the created ID is really universaly
103
- # unique.
104
- def create_random
105
- rnd = [
106
- rand(0x100000000),
107
- rand(0x100000000),
108
- rand(0x100000000),
109
- rand(0x100000000),
110
- ].pack "N4"
111
- raw = mask 4, rnd
112
- ret = new raw
113
- ret.freeze
114
- ret
115
- end
116
- alias :create_v4 :create_random
102
+ # UUID generation using random-number generator. From it's random
103
+ # nature, there's no warranty that the created ID is really universaly
104
+ # unique.
105
+ def create_random
106
+ rnd = [
107
+ rand(0x100000000),
108
+ rand(0x100000000),
109
+ rand(0x100000000),
110
+ rand(0x100000000),
111
+ ].pack "N4"
112
+ raw = mask 4, rnd
113
+ ret = new raw
114
+ ret.freeze
115
+ ret
116
+ end
117
+ alias :create_v4 :create_random
117
118
 
118
- def read_state fp # :nodoc:
119
- fp.rewind
120
- Marshal.load fp.read
121
- end
119
+ def read_state fp # :nodoc:
120
+ fp.rewind
121
+ Marshal.load fp.read
122
+ end
122
123
 
123
- def write_state fp, c, m # :nodoc:
124
- fp.rewind
125
- str = Marshal.dump [c, m]
126
- fp.write str
127
- end
124
+ def write_state fp, c, m # :nodoc:
125
+ fp.rewind
126
+ str = Marshal.dump [c, m]
127
+ fp.write str
128
+ end
128
129
 
129
- private :read_state, :write_state
130
- STATE_FILE = 'ruby-uuid'
130
+ private :read_state, :write_state
131
+ STATE_FILE = 'ruby-uuid'
131
132
 
132
- # create the "version 1" UUID with current system clock, current UTC
133
- # timestamp, and the IEEE 802 address (so-called MAC address).
134
- #
135
- # Speed notice: it's slow. It writes some data into hard drive on every
136
- # invokation. If you want to speed this up, try remounting tmpdir with a
137
- # memory based filesystem (such as tmpfs). STILL slow? then no way but
138
- # rewrite it with c :)
139
- def create clock=nil, time=nil, mac_addr=nil
140
- c = t = m = nil
141
- Dir.chdir Dir.tmpdir do
142
- unless FileTest.exist? STATE_FILE then
143
- # Generate a pseudo MAC address because we have no pure-ruby way
144
- # to know the MAC address of the NIC this system uses. Note
145
- # that cheating with pseudo arresses here is completely legal:
146
- # see Section 4.5 of RFC4122 for details.
147
- sha1 = Digest::SHA1.new
148
- 256.times do
149
- r = [rand(0x100000000)].pack "N"
150
- sha1.update r
151
- end
152
- str = sha1.digest
153
- r = rand 14 # 20-6
154
- node = str[r, 6] || str
155
- if RUBY_VERSION >= "1.9.0"
156
- nnode = node.bytes.to_a
157
- nnode[0] |= 0x01
158
- node = ''
159
- nnode.each { |s| node << s.chr }
160
- else
161
- node[0] |= 0x01 # multicast bit
162
- end
163
- k = rand 0x40000
164
- open STATE_FILE, 'w' do |fp|
165
- fp.flock IO::LOCK_EX
166
- write_state fp, k, node
167
- fp.chmod 0o777 # must be world writable
168
- end
169
- end
170
- open STATE_FILE, 'r+' do |fp|
171
- fp.flock IO::LOCK_EX
172
- c, m = read_state fp
173
- c = clock % 0x4000 if clock
174
- m = mac_addr if mac_addr
175
- t = time
176
- if t.nil? then
177
- # UUID epoch is 1582/Oct/15
178
- tt = Time.now
179
- t = tt.to_i*10000000 + tt.tv_usec*10 + 0x01B21DD213814000
180
- end
181
- c = c.succ # important; increment here
182
- write_state fp, c, m
183
- end
184
- end
133
+ # create the "version 1" UUID with current system clock, current UTC
134
+ # timestamp, and the IEEE 802 address (so-called MAC address).
135
+ #
136
+ # Speed notice: it's slow. It writes some data into hard drive on every
137
+ # invokation. If you want to speed this up, try remounting tmpdir with a
138
+ # memory based filesystem (such as tmpfs). STILL slow? then no way but
139
+ # rewrite it with c :)
140
+ def create clock=nil, time=nil, mac_addr=nil
141
+ c = t = m = nil
142
+ Dir.chdir Dir.tmpdir do
143
+ unless FileTest.exist? STATE_FILE then
144
+ # Generate a pseudo MAC address because we have no pure-ruby way
145
+ # to know the MAC address of the NIC this system uses. Note
146
+ # that cheating with pseudo arresses here is completely legal:
147
+ # see Section 4.5 of RFC4122 for details.
148
+ sha1 = Digest::SHA1.new
149
+ 256.times do
150
+ r = [rand(0x100000000)].pack "N"
151
+ sha1.update r
152
+ end
153
+ str = sha1.digest
154
+ r = rand 14 # 20-6
155
+ node = str[r, 6] || str
156
+ if RUBY_VERSION >= "1.9.0"
157
+ nnode = node.bytes.to_a
158
+ nnode[0] |= 0x01
159
+ node = ''
160
+ nnode.each { |s| node << s.chr }
161
+ else
162
+ node[0] |= 0x01 # multicast bit
163
+ end
164
+ k = rand 0x40000
165
+ open STATE_FILE, 'w' do |fp|
166
+ fp.flock IO::LOCK_EX
167
+ write_state fp, k, node
168
+ fp.chmod 0o777 # must be world writable
169
+ end
170
+ end
171
+ open STATE_FILE, 'r+' do |fp|
172
+ fp.flock IO::LOCK_EX
173
+ c, m = read_state fp
174
+ c = clock % 0x4000 if clock
175
+ m = mac_addr if mac_addr
176
+ t = time
177
+ if t.nil? then
178
+ # UUID epoch is 1582/Oct/15
179
+ tt = Time.now
180
+ t = tt.to_i*10000000 + tt.tv_usec*10 + 0x01B21DD213814000
181
+ end
182
+ c = c.succ # important; increment here
183
+ write_state fp, c, m
184
+ end
185
+ end
185
186
 
186
- tl = t & 0xFFFF_FFFF
187
- tm = t >> 32
188
- tm = tm & 0xFFFF
189
- th = t >> 48
190
- th = th & 0x0FFF
191
- th = th | 0x1000
192
- cl = c & 0xFF
193
- ch = c & 0x3F00
194
- ch = ch >> 8
195
- ch = ch | 0x80
196
- pack tl, tm, th, cl, ch, m
197
- end
198
- alias :create_v1 :create
187
+ tl = t & 0xFFFF_FFFF
188
+ tm = t >> 32
189
+ tm = tm & 0xFFFF
190
+ th = t >> 48
191
+ th = th & 0x0FFF
192
+ th = th | 0x1000
193
+ cl = c & 0xFF
194
+ ch = c & 0x3F00
195
+ ch = ch >> 8
196
+ ch = ch | 0x80
197
+ pack tl, tm, th, cl, ch, m
198
+ end
199
+ alias :create_v1 :create
199
200
 
200
- # A simple GUID parser: just ignores unknown characters and convert
201
- # hexadecimal dump into 16-octet object.
202
- def parse obj
203
- str = obj.to_s.sub %r/\Aurn:uuid:/, ''
204
- str.gsub! %r/[^0-9A-Fa-f]/, ''
205
- raw = str[0..31].lines.to_a.pack 'H*'
206
- ret = new raw
207
- ret.freeze
208
- ret
209
- end
201
+ # A simple GUID parser: just ignores unknown characters and convert
202
+ # hexadecimal dump into 16-octet object.
203
+ def parse obj
204
+ str = obj.to_s.sub %r/\Aurn:uuid:/, ''
205
+ str.gsub! %r/[^0-9A-Fa-f]/, ''
206
+ raw = str[0..31].lines.to_a.pack 'H*'
207
+ ret = new raw
208
+ ret.freeze
209
+ ret
210
+ end
210
211
 
211
- # The 'primitive constructor' of this class
212
- # Note UUID.pack(uuid.unpack) == uuid
213
- def pack tl, tm, th, ch, cl, n
214
- raw = [tl, tm, th, ch, cl, n].pack "NnnCCa6"
215
- ret = new raw
216
- ret.freeze
217
- ret
218
- end
219
- end
212
+ # The 'primitive constructor' of this class
213
+ # Note UUID.pack(uuid.unpack) == uuid
214
+ def pack tl, tm, th, ch, cl, n
215
+ raw = [tl, tm, th, ch, cl, n].pack "NnnCCa6"
216
+ ret = new raw
217
+ ret.freeze
218
+ ret
219
+ end
220
+ end
220
221
 
221
- # The 'primitive deconstructor', or the dual to pack.
222
- # Note UUID.pack(uuid.unpack) == uuid
223
- def unpack
224
- raw_bytes.unpack "NnnCCa6"
225
- end
222
+ # The 'primitive deconstructor', or the dual to pack.
223
+ # Note UUID.pack(uuid.unpack) == uuid
224
+ def unpack
225
+ raw_bytes.unpack "NnnCCa6"
226
+ end
226
227
 
227
- # Generate the string representation (a.k.a GUID) of this UUID
228
- def to_s
229
- a = unpack
230
- tmp = a[-1].unpack 'C*'
231
- a[-1] = sprintf '%02x%02x%02x%02x%02x%02x', *tmp
232
- "%08x-%04x-%04x-%02x%02x-%s" % a
233
- end
234
- alias guid to_s
228
+ # Generate the string representation (a.k.a GUID) of this UUID
229
+ def to_s
230
+ a = unpack
231
+ tmp = a[-1].unpack 'C*'
232
+ a[-1] = sprintf '%02x%02x%02x%02x%02x%02x', *tmp
233
+ "%08x-%04x-%04x-%02x%02x-%s" % a
234
+ end
235
+ alias guid to_s
235
236
 
236
- # Convert into a RFC4122-comforming URN representation
237
- def to_uri
238
- "urn:uuid:" + self.to_s
239
- end
240
- alias urn to_uri
237
+ # Convert into a RFC4122-comforming URN representation
238
+ def to_uri
239
+ "urn:uuid:" + self.to_s
240
+ end
241
+ alias urn to_uri
241
242
 
242
- # Convert into 128-bit unsigned integer
243
- # Typically a Bignum instance, but can be a Fixnum.
244
- def to_int
245
- tmp = self.raw_bytes.unpack "C*"
246
- tmp.inject do |r, i|
247
- r * 256 | i
248
- end
249
- end
250
- alias to_i to_int
243
+ # Convert into 128-bit unsigned integer
244
+ # Typically a Bignum instance, but can be a Fixnum.
245
+ def to_int
246
+ tmp = self.raw_bytes.unpack "C*"
247
+ tmp.inject do |r, i|
248
+ r * 256 | i
249
+ end
250
+ end
251
+ alias to_i to_int
251
252
 
252
- # Gets the version of this UUID
253
- # returns nil if bad version
254
- def version
255
- a = unpack
256
- v = (a[2] & 0xF000).to_s(16)[0].chr.to_i
257
- return v if (1..5).include? v
258
- return nil
259
- end
253
+ # Gets the version of this UUID
254
+ # returns nil if bad version
255
+ def version
256
+ a = unpack
257
+ v = (a[2] & 0xF000).to_s(16)[0].chr.to_i
258
+ return v if (1..5).include? v
259
+ return nil
260
+ end
260
261
 
261
- # Two UUIDs are said to be equal if and only if their (byte-order
262
- # canonicalized) integer representations are equivallent. Refer RFC4122 for
263
- # details.
264
- def == other
265
- to_i == other.to_i
266
- end
262
+ # Two UUIDs are said to be equal if and only if their (byte-order
263
+ # canonicalized) integer representations are equivallent. Refer RFC4122 for
264
+ # details.
265
+ def == other
266
+ to_i == other.to_i
267
+ end
267
268
 
268
- include Comparable
269
- # UUIDs are comparable (don't know what benefits are there, though).
270
- def <=> other
271
- to_s <=> other.to_s
272
- end
269
+ include Comparable
270
+ # UUIDs are comparable (don't know what benefits are there, though).
271
+ def <=> other
272
+ to_s <=> other.to_s
273
+ end
273
274
 
274
- # Pre-defined UUID Namespaces described in RFC4122 Appendix C.
275
- NameSpace_DNS = parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
276
- NameSpace_URL = parse "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
277
- NameSpace_OID = parse "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
278
- NameSpace_X500 = parse "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
275
+ # Pre-defined UUID Namespaces described in RFC4122 Appendix C.
276
+ NameSpace_DNS = parse "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
277
+ NameSpace_URL = parse "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
278
+ NameSpace_OID = parse "6ba7b812-9dad-11d1-80b4-00c04fd430c8"
279
+ NameSpace_X500 = parse "6ba7b814-9dad-11d1-80b4-00c04fd430c8"
279
280
 
280
- # The Nil UUID in RFC4122 Section 4.1.7
281
- Nil = parse "00000000-0000-0000-0000-000000000000"
281
+ # The Nil UUID in RFC4122 Section 4.1.7
282
+ Nil = parse "00000000-0000-0000-0000-000000000000"
283
+ end
282
284
  end
283
285
  end
@@ -324,7 +324,7 @@ module JSON
324
324
  @@fake_uri_generator = lambda{|s| UUIDTools::UUID.sha1_create(UUIDTools::UUID_URL_NAMESPACE, s).to_s }
325
325
  else
326
326
  require 'uri/uuid'
327
- @@fake_uri_generator = lambda{|s| SimpleUUID::UUID.create_v5(s,SimpleUUID::UUID::Nil).to_s }
327
+ @@fake_uri_generator = lambda{|s| JSON::Util::UUID.create_v5(s,JSON::Util::UUID::Nil).to_s }
328
328
  end
329
329
 
330
330
  def fake_uri schema
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ version: 0.9.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kenny Hoxworth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-24 00:00:00 -04:00
18
+ date: 2011-06-29 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21