parlement 0.2 → 0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. data/CHANGES +14 -4
  2. data/README +25 -5
  3. data/Rakefile +21 -21
  4. data/app/controllers/account_controller.rb +5 -1
  5. data/app/controllers/elt_controller.rb +7 -10
  6. data/app/controllers/person_controller.rb +9 -0
  7. data/app/controllers/subscriber_controller.rb +21 -0
  8. data/app/helpers/elt_helper.rb +25 -13
  9. data/app/helpers/mailman.rb +9 -92
  10. data/app/helpers/subscriber_helper.rb +2 -0
  11. data/app/models/attachment.rb +2 -0
  12. data/app/models/elt.rb +64 -2
  13. data/app/models/mail.rb +198 -0
  14. data/app/models/mail_notify.rb +63 -0
  15. data/app/models/person.rb +8 -1
  16. data/app/views/account/_login.rhtml +31 -28
  17. data/app/views/account/_show.rhtml +4 -4
  18. data/app/views/elt/_elt.rhtml +23 -28
  19. data/app/views/elt/_list.rhtml +6 -2
  20. data/app/views/elt/new.rhtml +1 -1
  21. data/app/views/elt/show.rhtml +32 -10
  22. data/app/views/layouts/top.rhtml +16 -10
  23. data/app/views/mail_notify/publish.text.html.rhtml +46 -0
  24. data/app/views/mail_notify/publish.text.plain.rhtml +2 -0
  25. data/app/views/person/_listElts.rhtml +33 -0
  26. data/app/views/person/show.rhtml +21 -19
  27. data/config/boot.rb +2 -0
  28. data/config/environment.rb +19 -13
  29. data/config/environments/development.rb +3 -1
  30. data/config/environments/production.rb +2 -0
  31. data/config/environments/test.rb +2 -0
  32. data/config/routes.rb +5 -2
  33. data/db/ROOT/mail.txt +2 -0
  34. data/db/ROOT/parlement/news/release0.2.txt +8 -0
  35. data/db/ROOT/parlement/news/release0.3.txt +11 -0
  36. data/db/ROOT/parlement/test.txt +6 -1
  37. data/db/ROOT/parlement.txt +23 -30
  38. data/db/ROOT/perso.txt +17 -18
  39. data/db/development_structure.sql +133 -217
  40. data/db/schema.rb +83 -0
  41. data/db/schema.sql +11 -15
  42. data/lib/data_import.rb +3 -1
  43. data/public/attachment/file/architecture.png +0 -0
  44. data/public/attachment/file/architecture.svg +8972 -0
  45. data/public/attachment/file/security.svg +8960 -0
  46. data/public/images/Sleep-Deprivation-5.JPG +0 -0
  47. data/public/images/eltBackground.png +0 -0
  48. data/public/images/eltBackground.svg +89 -0
  49. data/public/images/orange_by_darren_Hester_350o.jpg +0 -0
  50. data/public/images/rails.png +0 -0
  51. data/public/images/smile.png +0 -0
  52. data/public/images/smile.svg +257 -0
  53. data/public/images/world.png +0 -0
  54. data/public/images/world.svg +170 -0
  55. data/public/javascripts/controls.js +30 -1
  56. data/public/javascripts/dragdrop.js +210 -145
  57. data/public/javascripts/effects.js +261 -399
  58. data/public/javascripts/ie7.js +6 -0
  59. data/public/javascripts/prototype.js +131 -72
  60. data/public/oldindex.html +270 -71
  61. data/public/stylesheets/default.css +189 -215
  62. data/script/about +1 -1
  63. data/script/breakpointer +1 -1
  64. data/script/console +1 -1
  65. data/script/destroy +1 -1
  66. data/script/generate +1 -1
  67. data/script/performance/benchmarker +1 -1
  68. data/script/performance/profiler +1 -1
  69. data/script/plugin +1 -1
  70. data/script/process/reaper +1 -1
  71. data/script/process/spawner +1 -1
  72. data/script/process/spinner +1 -1
  73. data/script/runner +1 -1
  74. data/script/server +1 -1
  75. data/test/fixtures/elts.yml +2 -0
  76. data/test/fixtures/mail/mail_ruby +27 -0
  77. data/test/fixtures/mail/mail_rubyChild +28 -0
  78. data/test/fixtures/mail/mail_rubyWithAttachment +7932 -0
  79. data/test/fixtures/mail/mail_rubyWithSubject +27 -0
  80. data/test/fixtures/mails.yml +7 -1
  81. data/test/fixtures/people.yml +5 -0
  82. data/test/fixtures/subscribers.yml +11 -0
  83. data/test/functional/account_controller_test.rb +38 -37
  84. data/test/functional/subscriber_controller_test.rb +128 -0
  85. data/test/test_helper.rb +44 -0
  86. data/test/unit/attachment_test.rb +1 -1
  87. data/test/unit/elt_test.rb +3 -2
  88. data/test/unit/mail_notify_test.rb +37 -0
  89. data/test/unit/mail_test.rb +124 -1
  90. data/test/unit/notifier_test.rb +0 -14
  91. data/test/unit/person_test.rb +2 -1
  92. data/test/unit/subscriber_test.rb +35 -0
  93. data/test/unit/user_test.rb +3 -3
  94. data/vendor/plugins/file_column/CHANGELOG +64 -0
  95. data/vendor/plugins/file_column/README +54 -0
  96. data/vendor/plugins/file_column/Rakefile +36 -0
  97. data/vendor/plugins/file_column/TODO +6 -0
  98. data/vendor/plugins/file_column/init.rb +12 -0
  99. data/vendor/plugins/file_column/lib/file_column.rb +719 -0
  100. data/vendor/plugins/file_column/lib/file_column_helper.rb +145 -0
  101. data/vendor/plugins/file_column/lib/file_compat.rb +28 -0
  102. data/vendor/plugins/file_column/lib/magick_file_column.rb +188 -0
  103. data/vendor/plugins/file_column/lib/validations.rb +112 -0
  104. data/vendor/plugins/file_column/test/abstract_unit.rb +90 -0
  105. data/vendor/plugins/file_column/test/connection.rb +17 -0
  106. data/vendor/plugins/file_column/test/file_column_helper_test.rb +97 -0
  107. data/vendor/plugins/file_column/test/file_column_test.rb +630 -0
  108. data/vendor/plugins/file_column/test/fixtures/entry.rb +32 -0
  109. data/vendor/plugins/file_column/test/fixtures/invalid-image.jpg +1 -0
  110. data/vendor/plugins/file_column/test/fixtures/kerb.jpg +0 -0
  111. data/vendor/plugins/file_column/test/fixtures/mysql.sql +25 -0
  112. data/vendor/plugins/file_column/test/fixtures/schema.rb +10 -0
  113. data/vendor/plugins/file_column/test/fixtures/skanthak.png +0 -0
  114. data/vendor/plugins/file_column/test/magick_test.rb +251 -0
  115. data/vendor/plugins/file_column/test/magick_view_only_test.rb +21 -0
  116. data/vendor/plugins/guid/README.TXT +19 -0
  117. data/vendor/plugins/guid/init.rb +23 -0
  118. data/vendor/plugins/guid/lib/usesguid.rb +37 -0
  119. data/vendor/plugins/guid/lib/uuid22.rb +43 -0
  120. data/vendor/plugins/guid/lib/uuidtools.rb +565 -0
  121. metadata +83 -15
  122. data/db/ROOT/CV.txt +0 -166
  123. data/lib/file_column.rb +0 -263
  124. data/lib/file_column_helper.rb +0 -45
  125. /data/{lib → vendor/plugins/file_column/lib}/rails_file_column.rb +0 -0
@@ -0,0 +1,565 @@
1
+ #--
2
+ # Copyright (c) 2005 Robert Aman
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ UUID_TOOLS_VERSION = "0.1.4"
25
+
26
+ $:.unshift(File.dirname(__FILE__))
27
+
28
+ require 'uri'
29
+ require 'time'
30
+ require 'thread'
31
+ require 'digest/sha1'
32
+ require 'digest/md5'
33
+
34
+ # Because it's impossible to hype a UUID generator on its genuine merits,
35
+ # I give you... Really bad ASCII art in the comments:
36
+ #
37
+ #
38
+ # \
39
+ # /
40
+ # +
41
+ # ]
42
+ # ]
43
+ # |
44
+ # /
45
+ # Mp___
46
+ # `~0NNp,
47
+ # __ggM'
48
+ # g0M~"`
49
+ # ]0M*-
50
+ #
51
+ # ___
52
+ # _g000M00g,
53
+ # j0M~ ~M&
54
+ # j0M" ~N,
55
+ # j0P M&
56
+ # jM 1
57
+ # j0 ]1
58
+ # .0P 0,
59
+ # 00' M&
60
+ # 0M ]0L
61
+ # ]0f ___ M0
62
+ # M0NN0M00MMM~"'M 0&
63
+ # `~ ~0 ]0,
64
+ # ]M ]0&
65
+ # M& M0,
66
+ # ____gp_ M& M0_
67
+ # __p0MPM8MM&_ M/ ^0&_
68
+ # gN"` M0N_j0, MM&__
69
+ # _gF `~M0P` __ M00g
70
+ # g0' gM0&, ~M0&
71
+ # _pM` 0, ]M1 "00&
72
+ # _00 /g1MMgj01 ]0MI
73
+ # _0F t"M,7MMM 00I
74
+ # g0' _ N&j& 40'
75
+ # g0' _p0Mq_ ' N0QQNM#g,
76
+ # 0' _g0000000g__ ~M@MMM000g
77
+ # f _jM00@` ~M0000Mgppg, "P00&
78
+ # | g000~ `~M000000&_ ~0&
79
+ # ]M _M00F "00MM` ~#&
80
+ # `0L m000F #E "0f
81
+ # 9r j000M` 40, 00
82
+ # ]0g_ j00M` ^M0MNggp#gqpg M0&
83
+ # ~MPM0f ~M000000000g_ ,_ygg&M00f
84
+ # `~~~M00000000000000
85
+ # `M0000000000f
86
+ # ~@@@MF~`
87
+ #
88
+ #
89
+
90
+ #= uuidtools.rb
91
+ #
92
+ # UUIDTools was designed to be a simple library for generating any
93
+ # of the various types of UUIDs. It conforms to RFC 4122 whenever
94
+ # possible.
95
+ #
96
+ #== Example
97
+ # UUID.md5_create(UUID_DNS_NAMESPACE, "www.widgets.com")
98
+ # => #<UUID:0x287576 UUID:3d813cbb-47fb-32ba-91df-831e1593ac29>
99
+ # UUID.sha1_create(UUID_DNS_NAMESPACE, "www.widgets.com")
100
+ # => #<UUID:0x2a0116 UUID:21f7f8de-8051-5b89-8680-0195ef798b6a>
101
+ # UUID.timestamp_create
102
+ # => #<UUID:0x2adfdc UUID:64a5189c-25b3-11da-a97b-00c04fd430c8>
103
+ # UUID.random_create
104
+ # => #<UUID:0x19013a UUID:984265dc-4200-4f02-ae70-fe4f48964159>
105
+ class UUID
106
+ @@mac_address = nil
107
+ @@last_timestamp = nil
108
+ @@last_node_id = nil
109
+ @@last_clock_sequence = nil
110
+ @@state_file = nil
111
+ @@mutex = Mutex.new
112
+
113
+ def initialize(time_low, time_mid, time_hi_and_version,
114
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
115
+ unless time_low >= 0 && time_low < 4294967296
116
+ raise ArgumentError,
117
+ "Expected unsigned 32-bit number for time_low, got #{time_low}."
118
+ end
119
+ unless time_mid >= 0 && time_mid < 65536
120
+ raise ArgumentError,
121
+ "Expected unsigned 16-bit number for time_mid, got #{time_mid}."
122
+ end
123
+ unless time_hi_and_version >= 0 && time_hi_and_version < 65536
124
+ raise ArgumentError,
125
+ "Expected unsigned 16-bit number for time_hi_and_version, " +
126
+ "got #{time_hi_and_version}."
127
+ end
128
+ unless clock_seq_hi_and_reserved >= 0 && clock_seq_hi_and_reserved < 256
129
+ raise ArgumentError,
130
+ "Expected unsigned 8-bit number for clock_seq_hi_and_reserved, " +
131
+ "got #{clock_seq_hi_and_reserved}."
132
+ end
133
+ unless clock_seq_low >= 0 && clock_seq_low < 256
134
+ raise ArgumentError,
135
+ "Expected unsigned 8-bit number for clock_seq_low, " +
136
+ "got #{clock_seq_low}."
137
+ end
138
+ unless nodes.respond_to? :size
139
+ raise ArgumentError,
140
+ "Expected nodes to respond to :size."
141
+ end
142
+ unless nodes.size == 6
143
+ raise ArgumentError,
144
+ "Expected nodes to have size of 6."
145
+ end
146
+ for node in nodes
147
+ unless node >= 0 && node < 256
148
+ raise ArgumentError,
149
+ "Expected unsigned 8-bit number for each node, " +
150
+ "got #{node}."
151
+ end
152
+ end
153
+ @time_low = time_low
154
+ @time_mid = time_mid
155
+ @time_hi_and_version = time_hi_and_version
156
+ @clock_seq_hi_and_reserved = clock_seq_hi_and_reserved
157
+ @clock_seq_low = clock_seq_low
158
+ @nodes = nodes
159
+ end
160
+
161
+ attr_accessor :time_low
162
+ attr_accessor :time_mid
163
+ attr_accessor :time_hi_and_version
164
+ attr_accessor :clock_seq_hi_and_reserved
165
+ attr_accessor :clock_seq_low
166
+ attr_accessor :nodes
167
+
168
+ # Parses a UUID from a string.
169
+ def UUID.parse(uuid_string)
170
+ unless uuid_string.kind_of? String
171
+ raise ArgumentError,
172
+ "Expected String, got #{uuid_string.class.name} instead."
173
+ end
174
+ uuid_components = uuid_string.downcase.scan(
175
+ Regexp.new("^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-" +
176
+ "([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{12})$")).first
177
+ raise ArgumentError, "Invalid UUID format." if uuid_components.nil?
178
+ time_low = uuid_components[0].to_i(16)
179
+ time_mid = uuid_components[1].to_i(16)
180
+ time_hi_and_version = uuid_components[2].to_i(16)
181
+ clock_seq_hi_and_reserved = uuid_components[3].to_i(16)
182
+ clock_seq_low = uuid_components[4].to_i(16)
183
+ nodes = []
184
+ for i in 0..5
185
+ nodes << uuid_components[5][(i * 2)..(i * 2) + 1].to_i(16)
186
+ end
187
+ return UUID.new(time_low, time_mid, time_hi_and_version,
188
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
189
+ end
190
+
191
+ # Parses a UUID from a raw byte string.
192
+ def UUID.parse_raw(raw_string)
193
+ unless raw_string.kind_of? String
194
+ raise ArgumentError,
195
+ "Expected String, got #{raw_string.class.name} instead."
196
+ end
197
+ integer = UUID.convert_byte_string_to_int(raw_string)
198
+
199
+ time_low = (integer >> 96) & 0xFFFFFFFF
200
+ time_mid = (integer >> 80) & 0xFFFF
201
+ time_hi_and_version = (integer >> 64) & 0xFFFF
202
+ clock_seq_hi_and_reserved = (integer >> 56) & 0xFF
203
+ clock_seq_low = (integer >> 48) & 0xFF
204
+ nodes = []
205
+ for i in 0..5
206
+ nodes << ((integer >> (40 - (i * 8))) & 0xFF)
207
+ end
208
+ return UUID.new(time_low, time_mid, time_hi_and_version,
209
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
210
+ end
211
+
212
+ # Creates a UUID from a random value.
213
+ def UUID.random_create()
214
+ new_uuid = UUID.parse_raw(UUID.true_random)
215
+ new_uuid.time_hi_and_version &= 0x0FFF
216
+ new_uuid.time_hi_and_version |= (4 << 12)
217
+ new_uuid.clock_seq_hi_and_reserved &= 0x3F
218
+ new_uuid.clock_seq_hi_and_reserved |= 0x80
219
+ return new_uuid
220
+ end
221
+
222
+ # Creates a UUID from a timestamp.
223
+ def UUID.timestamp_create(timestamp=nil)
224
+ # We need a lock here to prevent two threads from ever
225
+ # getting the same timestamp.
226
+ @@mutex.synchronize do
227
+ # Always use GMT to generate UUIDs.
228
+ if timestamp.nil?
229
+ gmt_timestamp = Time.now.gmtime
230
+ else
231
+ gmt_timestamp = timestamp.gmtime
232
+ end
233
+ # Convert to 100 nanosecond blocks
234
+ gmt_timestamp_100_nanoseconds = (gmt_timestamp.tv_sec * 10000000) +
235
+ (gmt_timestamp.tv_usec * 10) + 0x01B21DD213814000
236
+ nodes = UUID.get_mac_address.split(":").collect do |octet|
237
+ octet.to_i(16)
238
+ end
239
+ node_id = 0
240
+ for i in 0..5
241
+ node_id += (nodes[i] << (40 - (i * 8)))
242
+ end
243
+ clock_sequence = @@last_clock_sequence
244
+ if clock_sequence.nil?
245
+ clock_sequence = UUID.convert_byte_string_to_int(UUID.true_random)
246
+ end
247
+ if @@last_node_id != nil && @@last_node_id != node_id
248
+ # The node id has changed. Change the clock id.
249
+ clock_sequence = UUID.convert_byte_string_to_int(UUID.true_random)
250
+ elsif @@last_timestamp != nil &&
251
+ gmt_timestamp_100_nanoseconds <= @@last_timestamp
252
+ clock_sequence = clock_sequence + 1
253
+ end
254
+ @@last_timestamp = gmt_timestamp_100_nanoseconds
255
+ @@last_node_id = node_id
256
+ @@last_clock_sequence = clock_sequence
257
+
258
+ time_low = gmt_timestamp_100_nanoseconds & 0xFFFFFFFF
259
+ time_mid = ((gmt_timestamp_100_nanoseconds >> 32) & 0xFFFF)
260
+ time_hi_and_version = ((gmt_timestamp_100_nanoseconds >> 48) & 0x0FFF)
261
+ time_hi_and_version |= (1 << 12)
262
+ clock_seq_low = clock_sequence & 0xFF;
263
+ clock_seq_hi_and_reserved = (clock_sequence & 0x3F00) >> 8
264
+ clock_seq_hi_and_reserved |= 0x80
265
+
266
+ return UUID.new(time_low, time_mid, time_hi_and_version,
267
+ clock_seq_hi_and_reserved, clock_seq_low, nodes)
268
+ end
269
+ end
270
+
271
+ # Creates a UUID using the MD5 hash. (Version 3)
272
+ def UUID.md5_create(namespace, name)
273
+ return UUID.create_from_hash(Digest::MD5, namespace, name)
274
+ end
275
+
276
+ # Creates a UUID using the SHA1 hash. (Version 5)
277
+ def UUID.sha1_create(namespace, name)
278
+ return UUID.create_from_hash(Digest::SHA1, namespace, name)
279
+ end
280
+
281
+ # This method applies only to version 1 UUIDs.
282
+ # Checks if the node ID was generated from a random number
283
+ # or from an IEEE 802 address (MAC address).
284
+ # Always returns false for UUIDs that aren't version 1.
285
+ # This should not be confused with version 4 UUIDs where
286
+ # more than just the node id is random.
287
+ def random_node_id?
288
+ return false if self.version != 1
289
+ return ((self.nodes.first & 0x01) == 1)
290
+ end
291
+
292
+ # Returns true if this UUID is the
293
+ # nil UUID (00000000-0000-0000-0000-000000000000).
294
+ def nil_uuid?
295
+ return false if self.time_low != 0
296
+ return false if self.time_mid != 0
297
+ return false if self.time_hi_and_version != 0
298
+ return false if self.clock_seq_hi_and_reserved != 0
299
+ return false if self.clock_seq_low != 0
300
+ self.nodes.each do |node|
301
+ return false if node != 0
302
+ end
303
+ return true
304
+ end
305
+
306
+ # Returns the UUID version type.
307
+ # Possible values:
308
+ # 1 - Time-based with unique or random host identifier
309
+ # 2 - DCE Security version (with POSIX UIDs)
310
+ # 3 - Name-based (MD5 hash)
311
+ # 4 - Random
312
+ # 5 - Name-based (SHA-1 hash)
313
+ def version
314
+ return (time_hi_and_version >> 12)
315
+ end
316
+
317
+ # Returns the UUID variant.
318
+ # Possible values:
319
+ # 0b000 - Reserved, NCS backward compatibility.
320
+ # 0b100 - The variant specified in this document.
321
+ # 0b110 - Reserved, Microsoft Corporation backward compatibility.
322
+ # 0b111 - Reserved for future definition.
323
+ def variant
324
+ variant_raw = (clock_seq_hi_and_reserved >> 5)
325
+ result = nil
326
+ if (variant_raw >> 2) == 0
327
+ result = 0x000
328
+ elsif (variant_raw >> 1) == 2
329
+ result = 0x100
330
+ else
331
+ result = variant_raw
332
+ end
333
+ return (result >> 6)
334
+ end
335
+
336
+ # Returns true if this UUID is valid.
337
+ def valid?
338
+ if [0b000, 0b100, 0b110, 0b111].include?(self.variant) &&
339
+ (1..5).include?(self.version)
340
+ return true
341
+ else
342
+ return false
343
+ end
344
+ end
345
+
346
+ # Returns the IEEE 802 address used to generate this UUID or
347
+ # nil if a MAC address was not used.
348
+ def mac_address
349
+ return nil if self.version != 1
350
+ return nil if self.random_node_id?
351
+ return (self.nodes.collect do |node|
352
+ sprintf("%2.2x", node)
353
+ end).join(":")
354
+ end
355
+
356
+ # Returns the timestamp used to generate this UUID
357
+ def timestamp
358
+ return nil if self.version != 1
359
+ gmt_timestamp_100_nanoseconds = 0
360
+ gmt_timestamp_100_nanoseconds +=
361
+ ((self.time_hi_and_version & 0x0FFF) << 48)
362
+ gmt_timestamp_100_nanoseconds += (self.time_mid << 32)
363
+ gmt_timestamp_100_nanoseconds += self.time_low
364
+ return Time.at(
365
+ (gmt_timestamp_100_nanoseconds - 0x01B21DD213814000) / 10000000.0)
366
+ end
367
+
368
+ # Compares two UUIDs lexically
369
+ def <=>(other_uuid)
370
+ check = self.time_low <=> other_uuid.time_low
371
+ return check if check != 0
372
+ check = self.time_mid <=> other_uuid.time_mid
373
+ return check if check != 0
374
+ check = self.time_hi_and_version <=> other_uuid.time_hi_and_version
375
+ return check if check != 0
376
+ check = self.clock_seq_hi_and_reserved <=>
377
+ other_uuid.clock_seq_hi_and_reserved
378
+ return check if check != 0
379
+ check = self.clock_seq_low <=> other_uuid.clock_seq_low
380
+ return check if check != 0
381
+ for i in 0..5
382
+ if (self.nodes[i] < other_uuid.nodes[i])
383
+ return -1
384
+ end
385
+ if (self.nodes[i] > other_uuid.nodes[i])
386
+ return 1
387
+ end
388
+ end
389
+ return 0
390
+ end
391
+
392
+ # Returns a representation of the object's state
393
+ def inspect
394
+ return "#<UUID:0x#{self.object_id.to_s(16)} UUID:#{self.to_s}>"
395
+ end
396
+
397
+ # Returns the hex digest of the UUID object.
398
+ def hexdigest
399
+ return self.to_i.to_s(16)
400
+ end
401
+
402
+ # Returns the raw bytes that represent this UUID.
403
+ def raw
404
+ return UUID.convert_int_to_byte_string(self.to_i, 16)
405
+ end
406
+
407
+ # Returns a string representation for this UUID.
408
+ def to_s
409
+ result = sprintf("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", @time_low, @time_mid,
410
+ @time_hi_and_version, @clock_seq_hi_and_reserved, @clock_seq_low);
411
+ for i in 0..5
412
+ result << sprintf("%2.2x", @nodes[i])
413
+ end
414
+ return result
415
+ end
416
+
417
+ # Returns an integer representation for this UUID.
418
+ def to_i
419
+ bytes = (time_low << 96) + (time_mid << 80) +
420
+ (time_hi_and_version << 64) + (clock_seq_hi_and_reserved << 56) +
421
+ (clock_seq_low << 48)
422
+ for i in 0..5
423
+ bytes += (nodes[i] << (40 - (i * 8)))
424
+ end
425
+ return bytes
426
+ end
427
+
428
+ # Returns a URI for this UUID.
429
+ def to_uri
430
+ return URI.parse(self.to_uri_string)
431
+ end
432
+
433
+ # Returns a URI string for this UUID.
434
+ def to_uri_string
435
+ return "urn:uuid:#{self.to_s}"
436
+ end
437
+
438
+ def UUID.create_from_hash(hash_class, namespace, name) #:nodoc:
439
+ if hash_class == Digest::MD5
440
+ version = 3
441
+ elsif hash_class == Digest::SHA1
442
+ version = 5
443
+ else
444
+ raise ArgumentError,
445
+ "Expected Digest::SHA1 or Digest::MD5, got #{hash_class.name}."
446
+ end
447
+ hash = hash_class.new
448
+ hash.update(namespace.raw)
449
+ hash.update(name)
450
+ hash_string = hash.to_s[0..31]
451
+ new_uuid = UUID.parse("#{hash_string[0..7]}-#{hash_string[8..11]}-" +
452
+ "#{hash_string[12..15]}-#{hash_string[16..19]}-#{hash_string[20..31]}")
453
+
454
+ new_uuid.time_hi_and_version &= 0x0FFF
455
+ new_uuid.time_hi_and_version |= (version << 12)
456
+ new_uuid.clock_seq_hi_and_reserved &= 0x3F
457
+ new_uuid.clock_seq_hi_and_reserved |= 0x80
458
+ return new_uuid
459
+ end
460
+
461
+ # Returns the MAC address of the current computer's network card.
462
+ # Returns nil if a MAC address could not be found.
463
+ def UUID.get_mac_address #:nodoc:
464
+ if @@mac_address.nil?
465
+ if RUBY_PLATFORM =~ /win/ && !(RUBY_PLATFORM =~ /darwin/)
466
+ begin
467
+ ifconfig_output = `ipconfig /all`
468
+ mac_addresses = ifconfig_output.scan(
469
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})"))
470
+ if mac_addresses.size > 0
471
+ @@mac_address = mac_addresses.first.first.downcase.gsub(/-/, ":")
472
+ end
473
+ rescue
474
+ end
475
+ else
476
+ begin
477
+ ifconfig_output = `ifconfig`
478
+ mac_addresses = ifconfig_output.scan(
479
+ Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
480
+ if mac_addresses.size == 0
481
+ ifconfig_output = `ifconfig | grep HWaddr | cut -c39-`
482
+ mac_addresses = ifconfig_output.scan(
483
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
484
+ end
485
+ if mac_addresses.size == 0
486
+ ifconfig_output = `/sbin/ifconfig`
487
+ mac_addresses = ifconfig_output.scan(
488
+ Regexp.new("ether (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
489
+ end
490
+ if mac_addresses.size == 0
491
+ ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`
492
+ mac_addresses = ifconfig_output.scan(
493
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"))
494
+ end
495
+ if mac_addresses.size > 0
496
+ @@mac_address = mac_addresses.first.first
497
+ end
498
+ rescue
499
+ end
500
+ end
501
+ end
502
+ return @@mac_address
503
+ end
504
+
505
+ # Returns 128 bits of highly unpredictable data.
506
+ # The random number generator isn't perfect, but it's
507
+ # much, much better than the built-in pseudorandom number generators.
508
+ def UUID.true_random #:nodoc:
509
+ require 'benchmark'
510
+ hash = Digest::SHA1.new
511
+ performance = Benchmark.measure do
512
+ hash.update(rand.to_s)
513
+ hash.update(srand.to_s)
514
+ hash.update(rand.to_s)
515
+ hash.update(srand.to_s)
516
+ hash.update(Time.now.to_s)
517
+ hash.update(rand.to_s)
518
+ hash.update(self.object_id.to_s)
519
+ hash.update(rand.to_s)
520
+ hash.update(hash.object_id.to_s)
521
+ hash.update(self.methods.inspect)
522
+ begin
523
+ random_device = nil
524
+ if File.exists? "/dev/urandom"
525
+ random_device = File.open "/dev/urandom", "r"
526
+ elsif File.exists? "/dev/random"
527
+ random_device = File.open "/dev/random", "r"
528
+ end
529
+ hash.update(random_device.read(20)) if random_device != nil
530
+ rescue
531
+ end
532
+ begin
533
+ srand(hash.to_s.to_i(16) >> 128)
534
+ rescue
535
+ end
536
+ hash.update(rand.to_s)
537
+ hash.update(UUID.true_random) if (rand(2) == 0)
538
+ end
539
+ hash.update(performance.real.to_s)
540
+ hash.update(performance.inspect)
541
+ return UUID.convert_int_to_byte_string(hash.to_s[4..35].to_i(16), 16)
542
+ end
543
+
544
+ def UUID.convert_int_to_byte_string(integer, size) #:nodoc:
545
+ byte_string = ""
546
+ for i in 0..(size - 1)
547
+ byte_string << ((integer >> (((size - 1) - i) * 8)) & 0xFF)
548
+ end
549
+ return byte_string
550
+ end
551
+
552
+ def UUID.convert_byte_string_to_int(byte_string) #:nodoc:
553
+ integer = 0
554
+ size = byte_string.size
555
+ for i in 0..(size - 1)
556
+ integer += (byte_string[i] << (((size - 1) - i) * 8))
557
+ end
558
+ return integer
559
+ end
560
+ end
561
+
562
+ UUID_DNS_NAMESPACE = UUID.parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
563
+ UUID_URL_NAMESPACE = UUID.parse("6ba7b811-9dad-11d1-80b4-00c04fd430c8")
564
+ UUID_OID_NAMESPACE = UUID.parse("6ba7b812-9dad-11d1-80b4-00c04fd430c8")
565
+ UUID_X500_NAMESPACE = UUID.parse("6ba7b814-9dad-11d1-80b4-00c04fd430c8")