Sha256: 8559285655e836e5af1dd44c37058964456b545e20ee1d3be7c9ca59ad95e1aa

Contents?: true

Size: 588 Bytes

Versions: 2

Compression:

Stored size: 588 Bytes

Contents

module Yema
  class Rule
    include Equalizer.new(:attribute_name)

    attr_reader :attribute_name

    def initialize(attribute_name, options={})
      assert_required_options(options)
      @attribute_name = attribute_name
    end

    def self.required_options
      []
    end

    def errors(resource)
      Validator.new(resource, self).errors
    end

    private

    def assert_required_options(options)
      shortage = self.class.required_options - options.keys
      raise InvalidOptionError, "Missing options: #{shortage.inspect}" unless shortage.empty?
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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