Module: DevSuite::Utils::Construct::Config::Attribute::Validator

Extended by:
Validator
Included in:
Validator
Defined in:
lib/dev_suite/utils/construct/config/attribute/validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_array!(value) ⇒ Object

Utility method to validate an Array.

Raises:

  • (ArgumentError)


42
43
44
# File 'lib/dev_suite/utils/construct/config/attribute/validator.rb', line 42

def validate_array!(value)
  raise ArgumentError, "Expected an Array, got #{value.class}" unless value.is_a?(Array)
end

#validate_config_attr_type!(attr:, value:, type:) ⇒ Object

Validates an attribute’s value based on its type.

Parameters:

  • attr (Symbol)

    The name of the attribute.

  • value (Object)

    The value to validate.

  • type (Symbol)

    The expected type of the attribute.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dev_suite/utils/construct/config/attribute/validator.rb', line 16

def validate_config_attr_type!(attr:, value:, type:)
  case type
  when :symbol
    validate_symbol!(value)
  when :hash
    validate_hash!(value)
  when :array
    validate_array!(value)
  when :class
    validate_instance_of!(value, Object)
  else
    raise ArgumentError, "Unknown type #{type} for attribute #{attr}"
  end
end

#validate_hash!(value) ⇒ Object

Utility method to validate a Hash.

Raises:

  • (ArgumentError)


37
38
39
# File 'lib/dev_suite/utils/construct/config/attribute/validator.rb', line 37

def validate_hash!(value)
  raise ArgumentError, "Expected a Hash, got #{value.class}" unless value.is_a?(Hash)
end

#validate_instance_of!(value, klass) ⇒ Object

Utility method to validate a class instance.

Raises:

  • (ArgumentError)


47
48
49
# File 'lib/dev_suite/utils/construct/config/attribute/validator.rb', line 47

def validate_instance_of!(value, klass)
  raise ArgumentError, "Expected an instance of #{klass}, got #{value.class}" unless value.is_a?(klass)
end

#validate_symbol!(value) ⇒ Object

Utility method to validate a Symbol.

Raises:

  • (ArgumentError)


32
33
34
# File 'lib/dev_suite/utils/construct/config/attribute/validator.rb', line 32

def validate_symbol!(value)
  raise ArgumentError, "Expected a Symbol, got #{value.class}" unless value.is_a?(Symbol)
end