A TOML parser using Citrus library.
toml-rb implements TOML 1.1.0 and passes all toml-test v2.2.0 decoder tests for that version.
$ gem install toml-rb
require 'toml-rb'
# From a file!
path = File.join(File.dirname(__FILE__), 'path', 'to', 'file')
TomlRB.load_file(path)
# From a stream!
stream = <<-EOS
title = "wow!"
[awesome]
you = true
others = false
EOS
TomlRB.parse(stream)
# => {"title"=>"wow!", "awesome"=>{"you"=>true, "others"=>false}}
# You want symbols as your keys? No problem!
TomlRB.load_file(path, symbolize_keys: true)
# Works the same for TomlRB.parse
# Local datetimes, dates and times are subclasses of Time. Offset datetimes are Time.
times = <<-EOS
odt = 1979-05-27T07:32:00Z
ldt = 1979-05-27T07:32:00
ld = 1979-05-27
lt = 07:32:00
EOS
TomlRB.parse(times).transform_values(&:class)
# => {"odt"=>Time, "ldt"=>TomlRB::LocalDateTime, "ld"=>TomlRB::LocalDate, "lt"=>TomlRB::LocalTime}require 'toml-rb'
# Simple example
TomlRB.dump( simple: true)
# => "simple = true\n"
# Complex example
hash = {
"title"=>"wow!",
"awesome"=> {
"you"=>true,
"others"=>false
}
}
TomlRB.dump(hash)
# => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"toml-rb is exercised against the official
toml-test conformance suite for both
TOML 1.0.0 and TOML 1.1.0. The harness lives in:
tool/toml-test-decoder— toml-test decoder shim..github/workflows/conformance.yml— CI workflow (per-version matrix)..github/toml-test-skip-1.0.txtand.github/toml-test-skip-1.1.txt— skip-lists of toml-test names for each spec version.
The TOML 1.1.0 skip-list is empty. The TOML 1.0.0 skip-list has 9 tests with
documents that TOML 1.0.0 forbids and TOML 1.1.0 allows. toml-rb accepts
TOML 1.1.0 syntax and has no option to select the spec version, so these tests
fail. CI runs toml-test with -skip-must-err, so the run fails when a skipped
test passes.
- Fork it
- Create your feature branch
git checkout -b my-new-feature - Add tests and commit your changes
git commit -am 'Add some feature' - Run tests
$ rake - Push the branch
git push origin my-new-feature - Create new Pull Request
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
