move the code to a class and add Railtie support