cfg-config 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 42d965189975d3e21172981161817be59fd20ee4dd0641d119626eeff3f451a7
4
+ data.tar.gz: 2176e90e4c01cd3990ec48a62a59bb166a924d68148c074ab4f04b208a106990
5
+ SHA512:
6
+ metadata.gz: 35fd6448761324bbe04394ca8165d8c4613d4a8e82bcad27fb2cf0671c170f3c12be3417efc877464d3080d1c6e91ae049fefbc9f29901caa78fc57c2f3b636c
7
+ data.tar.gz: 9e47521770880b2522499b8c9237114dc19240d6db6b6201a5ae16f0e7593d50df0875f836e7baff99fb92b6a1d829dec8ca6526221887bf1f6fed3d40cfba58
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes for the new implementation should be documented in this file.
4
+
5
+ ## 0.1.0 - 2021-09-14
6
+ ### Added
7
+ - [`30f0482`](https://github.com/vsajip/rb-cfg-lib/commit/30f0482)
8
+ Release new implementation.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'minitest', '~> 5.0'
6
+ gem 'rake', '~> 12.0'
7
+
8
+ gem 'byebug', '~> 11.1', groups: %i[development test]
data/LICENSE.txt ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2018-2021, Vinay Sajip.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # CFG::Config
2
+
3
+ A Ruby library for working with the CFG configuration format.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cfg-config'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cfg-config
20
+
21
+ ## Usage
22
+
23
+ The 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:
24
+
25
+ * Allow a hierarchical configuration scheme with support for key-value mappings and lists.
26
+ * Support cross-references between one part of the configuration and another.
27
+ * Provide a string interpolation facility to easily build up configuration values from other configuration values.
28
+ * Provide the ability to compose configurations (using include and merge facilities).
29
+ * Provide the ability to access real application objects safely, where supported by the platform.
30
+ * Be completely declarative.
31
+
32
+ It overcomes a number of drawbacks of JSON when used as a configuration format:
33
+
34
+ * JSON is more verbose than necessary.
35
+ * JSON doesn’t allow comments.
36
+ * JSON doesn’t provide first-class support for dates and multi-line strings.
37
+ * JSON doesn’t allow trailing commas in lists and mappings.
38
+ * JSON doesn’t provide easy cross-referencing, interpolation, or composition.
39
+
40
+ A simple example
41
+ ================
42
+
43
+ With the following configuration file, `test0.cfg`:
44
+ ```text
45
+ a: 'Hello, '
46
+ b: 'world!'
47
+ c: {
48
+ d: 'e'
49
+ }
50
+ 'f.g': 'h'
51
+ christmas_morning: `2019-12-25 08:39:49`
52
+ home: `$HOME`
53
+ foo: `$FOO|bar`
54
+ ```
55
+
56
+ You can load and query the above configuration using, for example, [irb](https://ruby-doc.org/stdlib-2.4.0/libdoc/irb/rdoc/IRB.html):
57
+
58
+ Loading a configuration
59
+ -----------------------
60
+
61
+ The configuration above can be loaded as shown below. In the REPL shell:
62
+ ```text
63
+ 2.7.1 :001 > require 'CFG/config'
64
+ => true
65
+ 2.7.1 :002 > include CFG
66
+ => Object
67
+ 2.7.1 :003 > cfg = CFG::Config::new("test0.cfg")
68
+ ```
69
+
70
+ The successful `new()` call returns a `Config` instance which can be used to query the configuration.
71
+
72
+ Access elements with keys
73
+ -------------------------
74
+ Accessing elements of the configuration with a simple key is not much harder than using a `Hash`:
75
+ ```text
76
+ 2.7.1 :004 > cfg['a']
77
+ => "Hello, "
78
+ 2.7.1 :005 > cfg['b']
79
+ => "world!"
80
+ ```
81
+
82
+ Access elements with paths
83
+ --------------------------
84
+ As well as simple keys, elements can also be accessed using path strings:
85
+ ```text
86
+ 2.7.1 :006 > cfg['c.d']
87
+ => "e"
88
+ ```
89
+ Here, 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.
90
+
91
+ Note that you can have simple keys which look like paths:
92
+ ```text
93
+ 2.7.1 :007 > cfg['f.g']
94
+ => "h"
95
+ ```
96
+ If 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.
97
+
98
+ Access to date/time objects
99
+ ---------------------------
100
+ You can also get native Ruby date/time objects from a configuration, by using an ISO date/time pattern in a backtick-string:
101
+ ```text
102
+ 2.7.1 :008 > cfg['christmas_morning']
103
+ => #<DateTime: 2019-12-25T08:39:49+00:00 ((2458843j,31189s,0n),+0s,2299161j)>
104
+ ```
105
+ Access to other Ruby objects
106
+ ----------------------------
107
+ Access to other Ruby objects is also possible using the backtick-string syntax, provided that they are one of:
108
+ * Environment variables
109
+ * Public fields of public classes
110
+ * Public static methods without parameters of public classes
111
+ ```text
112
+ 2.7.1 :009 > require 'date'
113
+ => false
114
+ 2.7.1 :010 > DateTime::now - cfg['now']
115
+ => (-148657/86400000000000)
116
+ ```
117
+
118
+ Access to environment variables
119
+ -------------------------------
120
+ To access an environment variable, use a backtick-string of the form `$VARNAME`:
121
+ ```text
122
+ 2.7.1 :011 > cfg['home'] == ENV['HOME']
123
+ => true
124
+ ```
125
+ You 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.
126
+ ```text
127
+ 2.7.1 :012 > cfg['foo']
128
+ => "bar"
129
+ ```
130
+
131
+ For more information, see [the CFG documentation](https://docs.red-dove.com/cfg/index.html).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ # task :default => :test
11
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'CFG/config'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/CFG/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'cfg-config'
5
+ spec.version = CFG::VERSION
6
+ spec.authors = ['Vinay Sajip']
7
+ spec.email = ['vinay_sajip@yahoo.co.uk']
8
+
9
+ spec.summary = 'A Ruby library for working with the CFG configuration format.'
10
+ spec.description = 'A Ruby library for working with the CFG configuration format. See https://docs.red-dove.com/cfg/index.html for more information.'
11
+ spec.homepage = 'https://docs.red-dove.com/cfg/index.html'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ # spec.metadata['source_code_uri'] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ spec.files = Dir['README.md', 'LICENSE.txt',
23
+ 'CHANGELOG.md', 'lib/**/*.rb', 'bin/*',
24
+ 'cfg-config.gemspec', 'Gemfile', 'Rakefile']
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+ end