Sha256: 8674cc35eecd9ee2c0c647182c1505a50b4883615a4cd5d9b339e1581fd04ad0

Contents?: true

Size: 894 Bytes

Versions: 7

Compression:

Stored size: 894 Bytes

Contents

module MCollective
  module Validator
    class TypecheckValidator
      def self.validate(validator, validation_type)
        raise ValidatorError, "value should be a #{validation_type}" unless check_type(validator, validation_type)
      end

      def self.check_type(validator, validation_type)
        case validation_type
        when Class
          validator.is_a?(validation_type)
        when :integer
          validator.is_a?(Integer)
        when :float
          validator.is_a?(Float) || validator.is_a?(Integer)
        when :number
          validator.is_a?(Numeric)
        when :string
          validator.is_a?(String)
        when :boolean
          [TrueClass, FalseClass].include?(validator.class)
        when :array
          validator.is_a?(Array)
        when :hash
          validator.is_a?(Hash)
        else
          false
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
choria-mcorpc-support-2.26.5 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.26.4 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.26.3 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.26.2 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.26.1 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.26.0 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.25.3 lib/mcollective/validator/typecheck_validator.rb