Class: Guid

Inherits:
Object show all
Defined in:
lib/activefacts/api/guid.rb

Overview

The Guid class is what it says on the packet, but you can assert a :new one.

Instance Method Summary collapse

Constructor Details

#initialize(i = :new) ⇒ Guid

Returns a new instance of Guid.



17
18
19
20
21
22
23
24
25
# File 'lib/activefacts/api/guid.rb', line 17

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 ArgumentError.new("Illegal non-Guid value #{i.inspect} given for Guid")
  end
end

Instance Method Details

#<=>(o) ⇒ Object

:nodoc:



52
53
54
# File 'lib/activefacts/api/guid.rb', line 52

def <=>(o)				#:nodoc:
  to_s.<=>(o.to_s)
end

#==(value) ⇒ Object



36
37
38
# File 'lib/activefacts/api/guid.rb', line 36

def == value
  @value == value.to_s
end

#eql?(o) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


48
49
50
# File 'lib/activefacts/api/guid.rb', line 48

def eql?(o)                           #:nodoc:
  to_s.eql?(o.to_s)
end

#equal?(value) ⇒ Boolean

if the value is unassigned, it equal?(:new).

Returns:

  • (Boolean)


32
33
34
# File 'lib/activefacts/api/guid.rb', line 32

def equal? value
  @value == value
end

#hashObject

:nodoc:



44
45
46
# File 'lib/activefacts/api/guid.rb', line 44

def hash                              #:nodoc:
  @value.hash
end

#inspectObject



40
41
42
# File 'lib/activefacts/api/guid.rb', line 40

def inspect
  "\#<Guid #{@value}>"
end

#to_sObject



27
28
29
# File 'lib/activefacts/api/guid.rb', line 27

def to_s
  @value
end