Looking at chord tones and the chords themselves is probably a better approach in this circumstance. So, if you are playing in C major, and a Gm7 chord appears, you could simply play a phrase from a Gm7 arpeggio. Or, you could stay in C major and be more careful about the notes you choose...for example, a Gm7 chord contains the notes G-Bb-D-F, three of which (G,D,F) are in the C major scale - so you could play those notes from C major, and make sure to avoid the B note in C major (which might not sound the best in this context). Or, you could play the Bb note instead of the B note in C major while the Gm7 plays. C major scale notes over the Gm7 chord also imply different tensions, for example, if you played an A note from C major, that would imply a Gm9 chord. As long as you know what you are doing, feel free to be weird...that's jazz.