Sha256: 797f8b25aca58d645393cce65ff29ba92b261e3f8fe62942bf4c10112e737b21

Contents?: true

Size: 1009 Bytes

Versions: 65

Compression:

Stored size: 1009 Bytes

Contents

module CFoundry
  module Validator
    class << self
      def value_matches?(val, type)
        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

65 entries across 65 versions & 3 rubygems

Version Path
cfoundry-1.0.0 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc15 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc14 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc13 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc12 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc11 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc10 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc9 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc8 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc6 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc5 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc4 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc3 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc2 lib/cfoundry/validator.rb
cfoundry-0.7.0.rc1 lib/cfoundry/validator.rb
cfoundry-0.6.1.rc4 lib/cfoundry/validator.rb
cfoundry-0.5.3.rc7 lib/cfoundry/validator.rb
static-1.0.1 vendor/cfoundry-0.5.2/lib/cfoundry/validator.rb
cfoundry-0.6.1.rc3 lib/cfoundry/validator.rb
cfoundry-0.6.1.rc2 lib/cfoundry/validator.rb