Giter VIP home page Giter VIP logo

ruby-hocon's Introduction

Build Status

ruby-hocon

This is a port of the Typesafe Config library to Ruby.

The library provides Ruby support for the HOCON configuration file format.

At present, it supports parsing and modification of existing HOCON/JSON files via the ConfigFactory class and the ConfigValueFactory class, and rendering parsed config objects back to a String (see examples below). It also supports the parsing and modification of HOCON/JSON files via ConfigDocumentFactory.

Note: While the project is production ready, since not all features in the Typesafe library are supported, you may still run into some issues. If you find a problem, feel free to open a github issue.

The implementation is intended to be as close to a line-for-line port as the two languages allow, in hopes of making it fairly easy to port over new changesets from the Java code base over time.

Basic Usage

gem install hocon

To use the simple API, for reading config values:

require 'hocon'

conf = Hocon.load("myapp.conf")
puts "Here's a setting: #{conf["foo"]["bar"]["baz"]}"

By default, the simple API will determine the configuration file syntax/format based on the filename extension of the file; .conf will be interpreted as HOCON, .json will be interpreted as strict JSON, and any other extension will cause an error to be raised since the syntax is unknown. If you'd like to use a different file extension, you manually specify the syntax, like this:

require 'hocon'
require 'hocon/config_syntax'

conf = Hocon.load("myapp.blah", {:syntax => Hocon::ConfigSyntax::HOCON})

Supported values for :syntax are: JSON, CONF, and HOCON. (CONF and HOCON are aliases, and both map to the underlying HOCON syntax.)

To use the ConfigDocument API, if you need both read/write capability for modifying settings in a config file, or if you want to retain access to things like comments and line numbers:

require 'hocon/parser/config_document_factory'
require 'hocon/config_value_factory'

# The below 4 variables will all be ConfigDocument instances
doc = Hocon::Parser::ConfigDocumentFactory.parse_file("myapp.conf")
doc2 = doc.set_value("a.b", "[1, 2, 3, 4, 5]")
doc3 = doc.remove_value("a")
doc4 = doc.set_config_value("a.b", Hocon::ConfigValueFactory.from_any_ref([1, 2, 3, 4, 5]))

doc_has_value = doc.has_value?("a") # returns boolean
orig_doc_text = doc.render # returns string

Note that a ConfigDocument is used primarily for simple configuration manipulation while preserving whitespace and comments. As such, it is not powerful as the regular Config API, and will not resolve substitutions.

Testing

bundle install --path .bundle
bundle exec rspec spec

Unsupported Features

This supports many of the same things as the Java library, but there are some notable exceptions. Unsupported features include:

  • Non file includes
  • Loading resources from the class path or URLs
  • Properties files
  • Parsing anything other than files and strings
  • Duration and size settings
  • Java system properties

Maintainence

Maintainers: Joe Pinsonault [email protected], Chris Price [email protected], Kevin Corcoran [email protected]

Tickets: https://tickets.puppetlabs.com/browse/HC

ruby-hocon's People

Contributors

cprice404 avatar mslilah avatar jpinsonault avatar kevincorcoran avatar dakatsuka avatar jmccure avatar janelu2 avatar rlinehan avatar traylenator avatar waynr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.