read_yaml_config
read_yaml_config
A simple library that provides a class for reading configuration files in YAML format. The class and associated methods allow you set default values, so configuration files don't need to explicitly define every key/value pair.
Limitations
- No parsing of the
Bytestype, as I've never worked with the YAML binary tag - No parsing of the
Set(YAML:Any)type, as I have no idea if/how this is any different thanArraysin terms of their YAML representation - Numbers can only be parsed into the
Int64andFloat64types and not their32bit counterparts. Possibly related to this issue, although I haven't given a best effort attempt at making these 2 (4?) types live in harmony - No
nilmaps, onlynilscalars (see NOTE below) - Possibly others, idk
[!NOTE] This is because map values are accessed via getter methods, which aren't defined on
Nil.
TODO
- Define
parse_or_defaultfor each type of theYAML::Any::Typeunion type, removing the need forto_s,to_i,to_b, etc. conversions - Also define
parse_or_default?methods as above when values are expected to be nil-able. Ensure I also write specs for this type of method. Use sparingly, I've found that nil-able values gets me into trouble when writing in Crystal... - Appropriately handle
Arraysin the "root" of a YAML file, e.g.:
- name: ana
age: 31
- name: victoria
age: 27
- When declaring
Arraysas instance variables, allow for declaring types other thanArray(YAML::Any), e.g.:
Array(Int)
Array(Map)
Array(String)
- Write the usage example as a spec, and simply refer to that spec instead of needing to copy it in this README.
Far future work?
I may want to rewrite this library to have a more friendly interface. Something like:
my_config = ReadYAMLConfig.new
my_config.add_key "key_name", "default_value", "type"
my_config.add_key "map_name", Map.new, Map
...
my_config.parse(File.read path_to_yaml)
p my_config.key_name
Installation
-
Add the dependency to your
shard.yml:dependencies: read_yaml_config: github: analessthanthree/read_yaml_config -
Run
shards install
Usage
See ./spec for detailed examples
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/your-github-user/read_yaml_config/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- ana - creator and maintainer
Repository
read_yaml_config
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- about 8 hours ago
- August 20, 2026
License
MIT License
Links
Synced at
Thu, 20 Aug 2026 00:43:54 GMT
Languages