Module: RightSupport::Data::UUID

Defined in:
lib/right_support/data/uuid.rb

Defined Under Namespace

Classes: Implementation, SimpleUUID, UUIDGem, UUIDTools1, UUIDTools2, Unavailable

Class Method Summary collapse

Class Method Details

.generateObject

Raises:



124
125
126
127
128
# File 'lib/right_support/data/uuid.rb', line 124

def generate
  impl = implementation
  raise Unavailable, "No implementation is available" unless impl
  impl.generate
end

.implementationObject

Return the implementation that will be used to generate UUIDs.

Return

The implementation object.

Raise

Unavailable

if no suitable implementation is available



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/right_support/data/uuid.rb', line 138

def implementation
  return @implementation if @implementation

  if (defl = Implementation.default)
    self.implementation = defl
  else
    raise Unavailable, "No implementation is available"
  end

  @implementation
end

.implementation=(klass) ⇒ Object

Set the implementation that will be used to generate UUIDs.

Parameters

klass(inherits-from Implementation)

the implementation class

Return

The class that was passed as a parameter

Raise

Unavailable

if the specified implementation is not available

ArgumentError

if klass is not a subclass of Implementation, or is not available



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/right_support/data/uuid.rb', line 162

def implementation=(klass)
  if klass.is_a?(Implementation)
    @implementation = klass
  elsif klass.is_a?(Class) && klass.ancestors.include?(Implementation)
    @implementation = klass.new
  elsif klass.nil?
    @implementation = nil
  else
    raise ArgumentError, "Expected Implementation instance or subclass, got #{klass}"
  end
rescue Exception => e
  raise Unavailable, "#{klass} is not available due to a #{e.class}: #{e.message}"
end