Class: Guid
- Inherits:
-
Object
- Object
- Guid
- 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.
Constant Summary collapse
- SEQ_FILE_NAME =
"/tmp/ActiveFactsRandom"
- @@sequence =
nil
Instance Method Summary collapse
-
#<=>(o) ⇒ Object
:nodoc:.
- #==(value) ⇒ Object
-
#eql?(o) ⇒ Boolean
:nodoc:.
-
#equal?(value) ⇒ Boolean
if the value is unassigned, it equal?(:new).
-
#hash ⇒ Object
:nodoc:.
-
#initialize(i = :new) ⇒ Guid
constructor
A new instance of Guid.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(i = :new) ⇒ Guid
Returns a new instance of Guid.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/activefacts/api/guid.rb', line 22 def initialize(i = :new) @@sequence = ENV['ACTIVEFACTS_RANDOM'] || false if @@sequence == nil if i == :new case @@sequence when 'fixed' @@counter ||= 0 @value = SecureRandom.format_uuid('%032x' % (@@counter += 1)) when 'record' @@sequence_file ||= File.open(SEQ_FILE_NAME, 'w') @value = SecureRandom.uuid.freeze @@sequence_file.puts(@value) when 'replay' @@sequence_file ||= File.open(SEQ_FILE_NAME, 'r') @value = @@sequence_file.gets.chomp else @value = SecureRandom.uuid.freeze end 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:
71 72 73 |
# File 'lib/activefacts/api/guid.rb', line 71 def <=>(o) #:nodoc: to_s.<=>(o.to_s) end |
#==(value) ⇒ Object
55 56 57 |
# File 'lib/activefacts/api/guid.rb', line 55 def == value @value == value.to_s end |
#eql?(o) ⇒ Boolean
:nodoc:
67 68 69 |
# File 'lib/activefacts/api/guid.rb', line 67 def eql?(o) #:nodoc: to_s.eql?(o.to_s) end |
#equal?(value) ⇒ Boolean
if the value is unassigned, it equal?(:new).
51 52 53 |
# File 'lib/activefacts/api/guid.rb', line 51 def equal? value @value == value end |
#hash ⇒ Object
:nodoc:
63 64 65 |
# File 'lib/activefacts/api/guid.rb', line 63 def hash #:nodoc: @value.hash end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/activefacts/api/guid.rb', line 59 def inspect "\#<Guid #{@value}>" end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/activefacts/api/guid.rb', line 46 def to_s @value end |