Sha256: fd309862e00530d629ca9215afc88b0ae729aa5e8678fef6512efe5b3edb40e2

Contents?: true

Size: 732 Bytes

Versions: 21

Compression:

Stored size: 732 Bytes

Contents

# typed: true
# frozen_string_literal: true

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

      sig { override.void }
      def call
        value = instance_variable_get(:@value)
        return if value.nil?

        check_type(value)
        check_length(value)
      end

      private

      def check_type(value)
        return if value.is_a?(::String)

        raise_error("expected a String but received #{value.inspect}")
      end

      def check_length(value)
        length = instance_variable_get(:@length)
        return if length.nil?
        return if value.length <= length

        raise_error("maximum length is #{length}")
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

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