module L4dServer class ConfigGenerator def self.generate(server) new(server).generate end def initialize(server) @server = server @template = server.server_template end def generate config_path = config_file_path config_dir = File.dirname(config_path) FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir) File.write(config_path, render_config) config_path end def config_file_path "/opt/l4d2/servers/#{@server.id}/server.cfg" end private def render_config # config is now a text field, not an association @template.config.to_s end end end