Sha256: 4e4500fa851204c3131b06f021d18308c0e711ffb5cd7c122280cff374f7f7e0

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module HashValidator
  @@validators = []


  def self.append_validator(validator)
    unless validator.is_a?(HashValidator::Validator::Base)
      raise StandardError.new('validators need to inherit from HashValidator::Validator::Base')
    end

    if @@validators.detect { |v| v.name == validator.name }
      raise StandardError.new('validators need to have unique names')
    end

    @@validators << validator
  end

  def self.validator_for(rhs)
    @@validators.detect { |v| v.should_validate?(rhs) } || raise(StandardError.new("Could not find valid validator for: #{rhs}"))
  end

  module Validator
  end
end

# Load validators
require 'hash_validator/validators/base'
require 'hash_validator/validators/simple_validator'
require 'hash_validator/validators/hash_validator'
require 'hash_validator/validators/presence_validator'
require 'hash_validator/validators/simple_type_validators'
require 'hash_validator/validators/boolean_validator'
require 'hash_validator/validators/email_validator'
require 'hash_validator/validators/enumerable_validator'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hash_validator-0.2.4 lib/hash_validator/validators.rb