Using rotation measure grids to detect cosmological magnetic fields: A Bayesian approach