Class: Pact::V2::Generators::UuidGenerator

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/pact/v2/generators/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(example: nil) ⇒ UuidGenerator

Returns a new instance of UuidGenerator.



87
88
89
90
91
92
93
94
95
96
# File 'lib/pact/v2/generators/base.rb', line 87

def initialize(example: nil)
  @example = example
  @regexStr = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}';
  if @example
    regex = Regexp.new("^#{@regexStr}$")
    unless @example.match?(regex)
      raise ArgumentError, "regex: Example value '#{@example}' does not match the UUID regular expression '#{@regexStr}'"
    end
  end
end

Instance Method Details

#as_basicObject



98
99
100
101
102
103
104
105
# File 'lib/pact/v2/generators/base.rb', line 98

def as_basic
  {
    "pact:matcher:type" => "regex",
    "pact:generator:type" => "Uuid",
    "regex" => @regexStr,
    "value" => @example || SecureRandom.uuid
  }
end