Sha256: 78a7923fd59aa97fac5653dd930aa596727cd6e8b0d60492417aa65cdd43c2a0

Contents?: true

Size: 795 Bytes

Versions: 16

Compression:

Stored size: 795 Bytes

Contents

module MCollective
  module Validator
    class TypecheckValidator
      def self.validate(validator, validation_type)
        raise ValidatorError, "value should be a #{validation_type.to_s}" 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)
          when :number
            validator.is_a?(Numeric)
          when :string
            validator.is_a?(String)
          when :boolean
            [TrueClass, FalseClass].include?(validator.class)
          else
            false
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
mcollective-client-2.12.5 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.6 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.5 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.4 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.3 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.2 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-2.20.0 lib/mcollective/validator/typecheck_validator.rb
choria-mcorpc-support-0.0.1 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.12.4 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.12.3 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.12.1 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.12.0 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.11.4 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.11.3 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.11.2 lib/mcollective/validator/typecheck_validator.rb
mcollective-client-2.11.1 lib/mcollective/validator/typecheck_validator.rb