Class: KSUID::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ksuid/configuration.rb

Overview

Encapsulates the configuration for the KSUID gem as a whole.

You can override the generation of the random payload data by setting the #random_generator value to a valid random payload generator. This should be done via the module-level configure method.

The gem-level configuration lives at the module-level config.

Constant Summary collapse

ConfigurationError =

Raised when the gem is misconfigured.

Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeKSUID::Configuration

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.

Instantiates a new KSUID configuration



33
34
35
# File 'lib/ksuid/configuration.rb', line 33

def initialize
  self.random_generator = self.class.default_generator
end

Instance Attribute Details

#random_generator#call

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.

The method for generating random payloads in the gem

Returns:

  • (#call)

    a callable that returns 16 bytes



42
43
44
# File 'lib/ksuid/configuration.rb', line 42

def random_generator
  @random_generator
end

Class Method Details

.default_generatorProc

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.

The default generator for generating random payloads

Returns:

  • (Proc)


24
25
26
# File 'lib/ksuid/configuration.rb', line 24

def self.default_generator
  -> { SecureRandom.random_bytes(BYTES[:payload]) }
end