Sha256: f1f66ec94d8aee30b6ec9b26cbe05fc56c96b038cc799ed5210224d3ab4f8936

Contents?: true

Size: 597 Bytes

Versions: 20

Compression:

Stored size: 597 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module DearInventory
  module Validators
    class Guid < DearInventory::Validator
      extend T::Sig

      REGEX = T.let(
        [
          /\A[\da-f]{32}\z/i,
          /\A(urn:uuid:)?[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i,
        ].freeze,
        T::Array[Regexp]
      )

      sig { override.void }
      def call
        value = instance_variable_get(:@value)
        return if value.nil?
        return if REGEX.any? { |regex| value =~ regex }

        raise_error("#{value.inspect} is not a valid GUID")
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
dear_inventory-1.4.0 lib/dear_inventory/validators/guid.rb
dear_inventory-1.3.0 lib/dear_inventory/validators/guid.rb
dear_inventory-1.2.0 lib/dear_inventory/validators/guid.rb
dear_inventory-1.1.1 lib/dear_inventory/validators/guid.rb
dear_inventory-1.1.0 lib/dear_inventory/validators/guid.rb
dear_inventory-1.0.0 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.5 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.4 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.3 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.2 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.1 lib/dear_inventory/validators/guid.rb
dear_inventory-0.7.0 lib/dear_inventory/validators/guid.rb
dear_inventory-0.6.3 lib/dear_inventory/validators/guid.rb
dear_inventory-0.6.2 lib/dear_inventory/validators/guid.rb
dear_inventory-0.6.1 lib/dear_inventory/validators/guid.rb
dear_inventory-0.6.0 lib/dear_inventory/validators/guid.rb
dear_inventory-0.5.0 lib/dear_inventory/validators/guid.rb
dear_inventory-0.4.1 lib/dear_inventory/validators/guid.rb
dear_inventory-0.4.0 lib/dear_inventory/validators/guid.rb
dear_inventory-0.3.0 lib/dear_inventory/validators/guid.rb