I’m beginning to work on a new Ruby on Rails application that is a CRUD interface for certain attributes contained in a config file. The process will look something like: CRUD RoR App > Database > Export to config file.
My question is what is the optimal way to design this (the back-end part that exports from the DB to the config file). Assuming the config file is on the same server as the RoR app, would I just write separate classes (in /lib) that have methods to read/write to the config file and include/call them in a before_create filter in my models?
Yes, you can simply treat ConfigFile as a model class that doesn’t use ActiveRecord. It can go with your other models (doesn’t have to go in /lib).
This class can be the interface to the file, used by your Rails app. I’m not sure about calling it from a before_create though. If you plan to regenerate the entire file each time, you wouldn’t want to do that when just one part of it is being updated, unless it is very small.
Do you have the option of determining the format of the config file? Just output model.to_yaml and you’re done!