{"id":15475153,"url":"https://github.com/vsajip/rb-cfg-lib","last_synced_at":"2026-06-04T02:31:43.984Z","repository":{"id":140255497,"uuid":"375596998","full_name":"vsajip/rb-cfg-lib","owner":"vsajip","description":"A Ruby library for working with the CFG configuration format. ","archived":false,"fork":false,"pushed_at":"2021-11-10T11:24:35.000Z","size":116,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T20:37:39.897Z","etag":null,"topics":["configuration","ruby","ruby-library"],"latest_commit_sha":null,"homepage":"https://docs.red-dove.com/cfg/index.html","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vsajip.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-10T06:41:21.000Z","updated_at":"2021-11-10T11:24:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"5186c95e-b417-4e7e-94cf-21f3eff2bdba","html_url":"https://github.com/vsajip/rb-cfg-lib","commit_stats":{"total_commits":48,"total_committers":1,"mean_commits":48.0,"dds":0.0,"last_synced_commit":"060331075b1b03790bf33d857979ee6328d2ff50"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Frb-cfg-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Frb-cfg-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Frb-cfg-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vsajip%2Frb-cfg-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vsajip","download_url":"https://codeload.github.com/vsajip/rb-cfg-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637634,"owners_count":19995011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","ruby","ruby-library"],"created_at":"2024-10-02T03:06:57.191Z","updated_at":"2026-06-04T02:31:43.976Z","avatar_url":"https://github.com/vsajip.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CFG::Config\n\nA Ruby library for working with the CFG configuration format.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cfg-config'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install cfg-config\n\n## Usage\n\nThe CFG configuration format is a text format for configuration files which is similar to, and a superset of, the JSON format. It dates from before its first announcement in [2008](https://wiki.python.org/moin/HierConfig) and has the following aims:\n\n* Allow a hierarchical configuration scheme with support for key-value mappings and lists.\n* Support cross-references between one part of the configuration and another.\n* Provide a string interpolation facility to easily build up configuration values from other configuration values.\n* Provide the ability to compose configurations (using include and merge facilities).\n* Provide the ability to access real application objects safely, where supported by the platform.\n* Be completely declarative.\n\nIt overcomes a number of drawbacks of JSON when used as a configuration format:\n\n* JSON is more verbose than necessary.\n* JSON doesn’t allow comments.\n* JSON doesn’t provide first-class support for dates and multi-line strings.\n* JSON doesn’t allow trailing commas in lists and mappings.\n* JSON doesn’t provide easy cross-referencing, interpolation, or composition.\n\nA simple example\n================\n\nWith the following configuration file, `test0.cfg`:\n```text\na: 'Hello, '\nb: 'world!'\nc: {\n  d: 'e'\n}\n'f.g': 'h'\nchristmas_morning: `2019-12-25 08:39:49`\nhome: `$HOME`\nfoo: `$FOO|bar`\n```\n\nYou can load and query the above configuration using, for example, [irb](https://ruby-doc.org/stdlib-2.4.0/libdoc/irb/rdoc/IRB.html):\n\nLoading a configuration\n-----------------------\n\nThe configuration above can be loaded as shown below. In the REPL shell:\n```text\n2.7.1 :001 \u003e require 'CFG/config'\n =\u003e true\n2.7.1 :002 \u003e include CFG\n =\u003e Object\n2.7.1 :003 \u003e cfg = CFG::Config::new(\"test0.cfg\")\n```\n\nThe successful `new()` call returns a `Config` instance which can be used to query the configuration.\n\nAccess elements with keys\n-------------------------\nAccessing elements of the configuration with a simple key is not much harder than using a `Hash`:\n```text\n2.7.1 :004 \u003e cfg['a']\n =\u003e \"Hello, \"\n2.7.1 :005 \u003e cfg['b']\n =\u003e \"world!\"\n```\n\nAccess elements with paths\n--------------------------\nAs well as simple keys, elements can also be accessed using path strings:\n```text\n2.7.1 :006 \u003e cfg['c.d']\n =\u003e \"e\"\n```\nHere, the desired value is obtained in a single step, by (under the hood) walking the path `c.d` – first getting the mapping at key `c`, and then the value at `d` in the resulting mapping.\n\nNote that you can have simple keys which look like paths:\n```text\n2.7.1 :007 \u003e cfg['f.g']\n =\u003e \"h\"\n```\nIf a key is given that exists in the configuration, it is used as such, and if it is not present in the configuration, an attempt is made to interpret it as a path. Thus, `f.g` is present and accessed via key, whereas `c.d` is not an existing key, so is interpreted as a path.\n\nAccess to date/time objects\n---------------------------\nYou can also get native Ruby date/time objects from a configuration, by using an ISO date/time pattern in a backtick-string:\n```text\n2.7.1 :008 \u003e cfg['christmas_morning']\n =\u003e #\u003cDateTime: 2019-12-25T08:39:49+00:00 ((2458843j,31189s,0n),+0s,2299161j)\u003e\n```\nAccess to other Ruby objects\n----------------------------\nAccess to other Ruby objects is also possible using the backtick-string syntax, provided that they are one of:\n* Environment variables\n* Public fields of public classes\n* Public static methods without parameters of public classes\n```text\n2.7.1 :009 \u003e require 'date'\n =\u003e false\n2.7.1 :010 \u003e DateTime::now - cfg['now']\n =\u003e (-148657/86400000000000)\n ```\n\nAccess to environment variables\n-------------------------------\nTo access an environment variable, use a backtick-string of the form `$VARNAME`:\n```text\n2.7.1 :011 \u003e cfg['home'] == ENV['HOME']\n =\u003e true\n```\nYou can specify a default value to be used if an environment variable isn’t present using the `$VARNAME|default-value` form. Whatever string follows the pipe character (including the empty string) is returned if the VARNAME is not a variable in the environment.\n```text\n2.7.1 :012 \u003e cfg['foo']\n =\u003e \"bar\"\n```\n\nFor more information, see [the CFG documentation](https://docs.red-dove.com/cfg/index.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Frb-cfg-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvsajip%2Frb-cfg-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvsajip%2Frb-cfg-lib/lists"}