Sha256: 0edf5d1fb3f1ac3007e4e550f79443b0f7d6515b9a242af76890917dcdbc071c

Contents?: true

Size: 794 Bytes

Versions: 28

Compression:

Stored size: 794 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?(Fixnum)
          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

28 entries across 28 versions & 2 rubygems

Version Path
dtk-node-agent-0.7.4 mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb
mcollective-client-2.8.2 lib/mcollective/validator/typecheck_validator.rb
dtk-node-agent-0.7.3 mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb
dtk-node-agent-0.7.2 mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb
dtk-node-agent-0.7.1 mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb
mcollective-client-2.8.1 lib/mcollective/validator/typecheck_validator.rb
dtk-node-agent-0.7.0 mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb
mcollective-client-2.8.0 lib/mcollective/validator/typecheck_validator.rb