read_yaml_config

A Crystal library to parse YAML config files; supports required, optional, and default typed values

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 Bytes type, 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 than Arrays in terms of their YAML representation
  • Numbers can only be parsed into the Int64 and Float64 types and not their 32 bit 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 nil maps, only nil scalars (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_default for each type of the YAML::Any::Type union type, removing the need for to_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 Arrays in the "root" of a YAML file, e.g.:
- name: ana
  age: 31
- name: victoria
  age: 27
  • When declaring Arrays as instance variables, allow for declaring types other than Array(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

  1. Add the dependency to your shard.yml:

    dependencies:
      read_yaml_config:
        github: analessthanthree/read_yaml_config
    
  2. Run shards install

Usage

See ./spec for detailed examples

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/your-github-user/read_yaml_config/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. 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