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…

这是什么?toml-rb 是一个 Ruby 库,用于解析和生成 TOML 配置文件,构建在 Citrus 解析库之上。
它是库还是独立工具?它是你添加到项目中的 Ruby 库;没有 CLI 或图形界面,只有解析和生成 API。
怎么把它加到项目里?用“gem install toml-rb”安装,或在 Gemfile 中添加 gem "toml-rb", "~> 6.0"。
需要其他 gem 或运行时依赖吗?不需要,除了 Ruby 本身之外它没有任何运行时依赖(Citrus 解析引擎打包在内部)。
它支持哪个 TOML 规范版本?它实现 TOML 1.1.0,并通过该版本的全部 toml-test v2.2.0 解码器测试,但它没有切换到 TOML 1.0.0 行为的选项,因此会接受一些 1.0.0 会拒绝的语法。
一致性测试有多彻底?它会针对 TOML 1.0.0 和 TOML 1.1.0 运行官方 toml-test 一致性测试套件,配有 CI 矩阵和针对每个规范版本的文档化跳过清单。
为什么 TOML 1.0.0 会有跳过的测试?1.0.0 的跳过清单有 9 个测试,涵盖 TOML 1.0.0 禁止但 TOML 1.1.0 允许的文档;由于 toml-rb 只实现 1.1.0 行为,这些特定测试会失败。
它内部依赖什么解析引擎?它使用 Citrus 解析库在 Ruby 中实现 TOML 文法。
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