Sha256: 9ba6cdac3a431d7b63a36d9327c101e7417140430ca61a0fa4b50269eefba4d8

Contents?: true

Size: 1.02 KB

Versions: 85

Compression:

Stored size: 1.02 KB

Contents

module CFoundry
  module Validator
    class << self
      def value_matches?(val, type)
        return true if val.nil?

        case type
        when Class
          val.is_a?(type)
        when Regexp
          val.is_a?(String) && !!(val =~ type)
        when :url
          value_matches?(val, URI::regexp(%w(http https)))
        when :https_url
          value_matches?(val, URI::regexp("https"))
        when :boolean
          val.is_a?(TrueClass) || val.is_a?(FalseClass)
        when Array
          val.all? do |x|
            value_matches?(x, type.first)
          end
        when Hash
          val.is_a?(Hash) &&
            type.all? { |name, subtype|
              val.key?(name) && value_matches?(val[name], subtype)
            }
        when nil
          true
        else
          val.is_a?(Object.const_get(type.to_s.capitalize))
        end
      end

      def validate_type(val, type)
        unless value_matches?(val, type)
          raise CFoundry::Mismatch.new(type, val)
        end
      end
    end
  end
end

Version data entries

85 entries across 85 versions & 3 rubygems

Version Path
new_cfoundry-4.9.4 lib/cfoundry/validator.rb
new_cfoundry-4.9.3 lib/cfoundry/validator.rb
ncfoundry-4.9.4 lib/cfoundry/validator.rb
ncfoundry-4.9.3 lib/cfoundry/validator.rb
ncfoundry-4.9.2 lib/cfoundry/validator.rb
new_cfoundry-4.9.2 lib/cfoundry/validator.rb
new_cfoundry-4.9.1 lib/cfoundry/validator.rb
new_cfoundry-4.9.0 lib/cfoundry/validator.rb
new_cfoundry-4.8.3 lib/cfoundry/validator.rb
new_cfoundry-4.8.2 lib/cfoundry/validator.rb
cfoundry-4.7.2.rc1 lib/cfoundry/validator.rb
cfoundry-4.7.1 lib/cfoundry/validator.rb
cfoundry-4.7.1.rc1 lib/cfoundry/validator.rb
cfoundry-4.7.0 lib/cfoundry/validator.rb
cfoundry-4.6.3.rc3 lib/cfoundry/validator.rb
cfoundry-4.6.3.rc2 lib/cfoundry/validator.rb
cfoundry-4.6.3.rc1 lib/cfoundry/validator.rb
cfoundry-4.6.2 lib/cfoundry/validator.rb
cfoundry-4.6.1 lib/cfoundry/validator.rb
cfoundry-4.6.0 lib/cfoundry/validator.rb