Sha256: 041d5816a3b1eb3332f2f97ff01668b4595f5a52257a2c1a88eecb71c4e3c18b

Contents?: true

Size: 437 Bytes

Versions: 2

Compression:

Stored size: 437 Bytes

Contents

module Yema
  class Validator

    attr_reader :resource, :rules

    def initialize(resource, *rules)
      @resource, @rules = resource, rules
    end

    def valid?
      errors.empty?
    end

    def errors
      errors = []
      rules.each do |rule|
        value = resource.public_send(rule.attribute_name)
        errors << Error.new(rule, resource) unless rule.matches?(value)
      end
      errors.to_set
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yema-0.0.3 lib/yema/validator.rb
yema-0.0.2 lib/yema/validator.rb