Class: Dogtag::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/dogtag/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(data_type, count = 1) ⇒ Generator

Returns a new instance of Generator.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dogtag/generator.rb', line 3

def initialize(data_type, count = 1)
  unless data_type.is_a? Integer
    raise ArgumentError, 'data_type must be an integer'
  end

  unless Dogtag::DATA_TYPE_ALLOWED_RANGE.include? data_type
    raise ArgumentError, "data_type is outside the allowed range of #{Dogtag::DATA_TYPE_ALLOWED_RANGE}"
  end

  raise ArgumentError, 'count must be an integer' unless count.is_a? Integer
  raise ArgumentError, 'count must be a positive number' if count < 1

  @data_type = data_type
  @count = count
end

Instance Method Details

#idsObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/dogtag/generator.rb', line 19

def ids
  response.sequence.map do |sequence|
    (
      shifted_timestamp |
      shifted_logical_shard_id |
      shifted_data_type |
      (sequence << Dogtag::SEQUENCE_SHIFT)
    )
  end
end