Validating YAML Files in Ruby
YAML stands for “YAML Ain’t Markup Language”. YAML is a data serialization language that is often used for writing configuration files.
In simple terms YAML is like XML or JSON, but for human beings rather than computers. I feel this is getting overlooked a lot, programmers need to understand that. Another human like configuration language I like is TOML (Tom’s Obvious Minimal Language).
In a static language (like crystal) you need to define the structure of a YAML or JSON file. Defining the structure also act as validation of its schema. Validating the schema is a good idea because it ensure’s that all the required data is present. Its better to know data is missing when your program starts rather than while it is running.
For dynamic language like ruby you can load a yaml file, and ruby will dynamically initialize it. It does make your life easier as a programmer. You don’t need to define the schema, and remember to update the schema when you add a new variable to your file.
But defining the schema has its benefits -
- For the User: It reminds then to have the configuration filled before running their program
- For the Developer: It helps us to eliminate the configuration file as a possible reason for the program not running.