toml-rb README

The project's README from github.com/emancu/toml-rb. As one markdown file: README.md.

TOML Logo

toml-rb

Gem Version Build Status Code Climate RubyGem

A pure Ruby TOML parser and dumper with no runtime dependencies.

toml-rb implements TOML 1.1.0 and passes all toml-test v2.2.0 decoder tests for that version.

Installation

$ gem install toml-rb

Or add this line to your Gemfile:

gem "toml-rb", "~> 6.0"

Parser Usage

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}

Dumper Usage

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"

Conformance

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:

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.

Contributing

  1. Fork it
  2. Create your feature branch git checkout -b my-new-feature
  3. Add tests and commit your changes git commit -am 'Add some feature'
  4. Run tests $ rake
  5. Push the branch git push origin my-new-feature
  6. Create new Pull Request

License

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.

toml-rb (emancu/toml-rb)

Searching Database…

What is this?toml-rb is a Ruby library that parses and dumps TOML configuration files, built on top of the Citrus parsing library.
Is it a library or a standalone tool?It's a Ruby library you add to a project; there's no CLI or GUI, just a parser and dumper API.
How do I add it to a project?Install it with 'gem install toml-rb', or add 'gem "toml-rb", "~> 6.0"' to your Gemfile.
Do I need any other gems or runtime dependencies?No, it has no runtime dependencies beyond Ruby itself (it bundles the Citrus parsing engine internally).
Which TOML spec version does it support?It implements TOML 1.1.0 and passes all toml-test v2.2.0 decoder tests for that version, but it has no option to switch to TOML 1.0.0 behavior, so it accepts some syntax that 1.0.0 would reject.
How thoroughly is conformance tested?It runs against the official toml-test conformance suite for both TOML 1.0.0 and TOML 1.1.0, with CI matrices and documented skip-lists for each spec version.
Why does TOML 1.0.0 have skipped tests?The 1.0.0 skip-list has 9 tests covering documents that TOML 1.0.0 forbids but TOML 1.1.0 allows, and since toml-rb only implements 1.1.0 behavior, those specific tests fail.
What parsing engine does it rely on internally?It uses the Citrus parsing library to implement the TOML grammar in Ruby.
Which topics is it in?toml, config, parser, ruby, library, mit, open-source
Creator
emancu
Size
0.5 MB
Stars
124
Age
13y
Commits · 90 Days