Sha256: fec4a843b8b98d36351f04c3298ba74e18d42f71dd2e80e9aa1061e01e6de1a8

Contents?: true

Size: 544 Bytes

Versions: 5

Compression:

Stored size: 544 Bytes

Contents

# frozen_string_literal: true

module InferModel
  class Parsers::UUID
    extend Callable
    extend Dry::Initializer

    UUID_REGEX = /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i

    param :value
    option :allow_blank, default: -> { true }

    def call
      raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
      return if value.nil? || value.empty?
      return value if UUID_REGEX.match?(value)

      raise Parsers::Error, "'#{value}' is not a UUID"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
infer_model-0.1.5 lib/infer_model/parsers/uuid.rb
infer_model-0.1.4 lib/infer_model/parsers/uuid.rb
infer_model-0.1.2 lib/infer_model/parsers/uuid.rb
infer_model-0.1.1 lib/infer_model/parsers/uuid.rb
infer_model-0.1.0 lib/infer_model/parsers/uuid.rb