A unified approach to exact embeddings of Muckenhoupt and Gehring classes