config.cr v0.1.0
config
An instance of Config
provides a Hash(String, String | Int | Bool)
that can be accessed via method calls. The method names are the keys of the hash. It also provides facilities to serialize a configuration out to a JSON or YAML file, and to read a JSON or YAML file as a configuration.
Full Documentation
https://wyhaines.github.io/config.cr/
Installation
-
Add the dependency to your
shard.yml
:dependencies: config: github: wyhaines/config.cr
-
Run
shards install
Usage
require "config"
config = Config.new
config.verbose = true
pp config.verbose # => true
if config.quiet? # => false
puts "be quiet"
else
puts "don't be quiet" # => "don't be quiet"
end
The #data
method will return the raw data hash.
pp config.data # => {"verbose" => true}
The Config
class can be initialized from an IO
, or a Path
/String
that points to a file. The file can be in either JSON or YAML format. The default format is JSON, but if the file cannot be read as JSON, but can be read as YAML, then the format will change to YAML.
config = Config.from("config.json") # {"verbose" : "true"}
pp config.verbose # => "true"
config = Config.from("config.yaml") # {verbose : true}
pp config.verbose # => true
config = Config.from("config.txt") # {also_verbose : true}
pp config.also_verbose # => true
## Contributing
1. Fork it (<https://github.com/wyhaines/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
- [Kirk Haines](https://github.com/wyhaines) - creator and maintainer
config.cr
- 0
- 0
- 2
- 1
- 1
- 7 months ago
- October 3, 2023
Apache License 2.0
Sat, 18 May 2024 12:56:00 GMT