module StickyErrorsTrait
  as_trait do

    validate :validate_sticky_errors

    def add_sticky_error_on(attribute, error)
      @sticky_errors ||= {}
      @sticky_errors[attribute.to_sym] = error
    end

    private

    def validate_sticky_errors
      if @sticky_errors
        @sticky_errors.each do |attribute, error|
          errors.add(attribute, error)
        end
      end
    end

  end
end
