Sha256: 68f5d9fa582367727c190336d46ed12c773a68bbd5f538a091f2fcd06a675187

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

module WeakParameters
  class Validator
    attr_reader :block, :params

    def initialize(params, &block)
      @params = params
      instance_eval(&block)
    end

    def validate
      validators.each(&:validate)
    end

    def validators
      @validators ||= []
    end

    def type
      self.class.name.split("::").last.sub(/Validator$/, "").underscore.to_sym
    end

    private

    def string(key, options = {})
      validators << WeakParameters::BaseValidator.new(params, key, options)
    end

    def integer(key, options = {})
      validators << WeakParameters::IntegerValidator.new(params, key, options)
    end

    def boolean(key, options = {})
      validators << WeakParameters::BooleanValidator.new(params, key, options)
    end

    def hash(key, options = {})
      validators << WeakParameters::HashValidator.new(params, key, options)
    end

    def array(key, options = {})
      validators << WeakParameters::ArrayValidator.new(params, key, options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
weak_parameters-0.0.2 lib/weak_parameters/validator.rb