The ridge pieces.
The pattern of water marks inside indicate that the water came from somewhere high. You see the loose ridge pieces and the rusty nail heads. The ridge pieces need to be inspected, in addition to the loose/torn ridge pieces being fixed. I believe at this location the ridge pieces were not installed correctly because typically ridge pieces are installed pretty securely, and each of them has a very small area subject to wind blows. There may be other locations on the ridge that although not leaking at this point, but could have been weakened. At this moment I do not recommend replacing the whole ridge. A pack of ridge pieces for textured shingle is about 50 dollars.