Class: WithUid::UidGenerator Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/with_uid/uid_generator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, **options, &generator) ⇒ UidGenerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of UidGenerator.



10
11
12
13
14
15
# File 'lib/with_uid/uid_generator.rb', line 10

def initialize(context, ** options, &generator)
  @context = context
  @generator = generator
  @suffix = options[:suffix]
  @prefix = options[:prefix]
end

Instance Attribute Details

#contextObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/with_uid/uid_generator.rb', line 8

def context
  @context
end

#generatorObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/with_uid/uid_generator.rb', line 8

def generator
  @generator
end

Instance Method Details

#each {|uid(prefix)| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yields:



17
18
19
20
21
22
23
24
25
# File 'lib/with_uid/uid_generator.rb', line 17

def each
  return enum_for(:each) unless block_given?

  yield uid(prefix)
  loop do
    next_uid = uid(prefix, suffix)
    yield next_uid
  end
end

#prefixObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
# File 'lib/with_uid/uid_generator.rb', line 33

def prefix
  with_default(@prefix) do
    ''
  end
end

#suffixObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
30
31
# File 'lib/with_uid/uid_generator.rb', line 27

def suffix
  with_default(@suffix) do
    "_#{SecureRandom.hex(3)}"
  end
end