Sha256: bc05f02c9fa74907cb39c4a64bdd217e8ff1303287fc3aa5ae078919180083f6
Contents?: true
Size: 993 Bytes
Versions: 2
Compression:
Stored size: 993 Bytes
Contents
require 'delegate' require 'securerandom' unless defined? SecureRandom.uuid # I think this only applies to 1.8.6 (and JRuby/Rubinius in 1.8 mode) now: def SecureRandom.uuid hex(16).sub(/(........)(....)(....)(....)(............)/,'\1-\2-\3-\4-\5') end end # The Guid class is what it says on the packet, but you can assert a :new one. class Guid def initialize(i = :new) if i == :new @value = SecureRandom.uuid.freeze elsif (v = i.to_s).length == 36 and !(v !~ /[^0-9a-f]/i) @value = v.clone.freeze else raise "Illegal non-Guid value #{i.inspect} given for Guid" end end def to_s @value end # if the value is unassigned, it equal?(:new). def equal? value @value == value end def == value @value == value.to_s end def inspect "\#<Guid #{@value}>" end def hash #:nodoc: @value.hash end def eql?(o) #:nodoc: to_s.eql?(o.to_s) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activefacts-api-0.9.5 | lib/activefacts/api/guid.rb |
activefacts-api-0.9.4 | lib/activefacts/api/guid.rb |