Module: EasyType::Validators::Integer

Defined in:
lib/easy_type/validators.rb

Overview

This validator validates if it is an Integer

Examples:


newparam(:name) do
  include ::EasyType::Validators::Integer

Raises:

  • (Puppet::Error)

    when the name is invalid

Class Method Summary collapse

Class Method Details

.unsafe_validate(value) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/easy_type/validators.rb', line 62

def unsafe_validate(value)
  super if resource_api_available? && self.class.data_type
  return if value == 'absent'
  klass = value.class.to_s
  case klass
  when 'Integer', 'Fixnum', 'Bignum'
    return
  when 'String'
    fail Puppet::Error, "Invalid value for Integer: #{value}" unless value =~ STRING_OF_DIGITS
  else
    fail Puppet::Error, "Invalid value for Integer: #{value}"
  end
end