frebby 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/LICENSE +201 -0
  4. data/README.md +232 -0
  5. data/Rakefile +11 -0
  6. data/frebby.gemspec +29 -0
  7. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9887b888bece3f3120b9640d910f4baae8ed2de3
4
- data.tar.gz: e244028a95008565e9a5b02fb8309f2825cb1561
3
+ metadata.gz: 97043fa483d88a805f61f08f9e514d424833a515
4
+ data.tar.gz: ecfad287eea03a9a05a2ef3ff55f47c497a37592
5
5
  SHA512:
6
- metadata.gz: 9647df78942991006f7d8763b9a18c1d1acd4320d5aada28c5e51fe7b778a35ddf5d7ae825614cdac0dbea55b6602ee19fe9ae1f072578f5a212bd68eac48985
7
- data.tar.gz: d11c7a9b550d31769392409c88846f3cfd25f4dc2e6b313c50367ffc6e9972b6a4f065d2547a8eafc5cbb63f881548cca3513d8012a200334c2cb0f2ae74bef8
6
+ metadata.gz: 3bc7fb6746daa275c3d0034520220c90b075474071deafa9184a235cca030d6e5ddd56d7f272a1b4b051a6a7d3c42985de2bc13f76b740f5788532f993e55f51
7
+ data.tar.gz: 89fa4c9184fe09b6824c380734f71edeffba2d9d6c62113e905392455df03ae9e02070e14f9ec5dc09fcb96c95653d37b578ff454dcd29f5712733e77b26ab99
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,232 @@
1
+ # frebby
2
+
3
+ [![Gem](https://img.shields.io/gem/v/frebby.svg?style=plastic)][gem]
4
+ [![Travis](https://img.shields.io/travis/oclaussen/frebby.svg?style=plastic)][travis]
5
+
6
+ [gem]: https://rubygems.org/gems/frebby
7
+ [travis]: http://travis-ci.org/oclaussen/frebby
8
+
9
+
10
+ ## What is this?
11
+
12
+ `frebby` is a very, very simple Ruby script that generates JSON out of a Ruby
13
+ based configuration language. It is intended as an alternative to the numerous
14
+ attempts to write a more human-readable language for tool configuration (YAML,
15
+ TOML, HCL, to name a few).
16
+
17
+ In contrast to these other languages, `frebby` is not a full blown parser.
18
+ Instead it takes a bunch of Ruby code, `eval`s it and turns it into JSON. The
19
+ result can then be fed to basically anything that can read JSON.
20
+
21
+ ## Why should I use this?
22
+
23
+ Everyone has a different opinion on how powerful a configuration language should
24
+ be. Some people prefer a very strict and foolproof language while others prefer
25
+ full blown programming languages. For most, the answer is somewhere in the
26
+ middle. This tool is aimed at those who sit quite far in the programming
27
+ language camp and who feel YAML and HCL are lacking in possibilities.
28
+
29
+ ### The Good
30
+
31
+ * Use all the power of a full programming language for tools that usually
32
+ wouldn't support this (Ansible, Terraform, Packer, ...)
33
+
34
+ * Keep all your infrastructure defined in one consistent language
35
+
36
+ * Works with anything that expects configuration files in JSON format
37
+ (or YAML, or HCL, since these are just supersets of JSON)
38
+
39
+ * No dependencies (except Ruby, of course)
40
+
41
+ ### The Bad
42
+
43
+ * You need Ruby installed, and some level of Ruby knowledge will help also
44
+
45
+ * It is another tool in you build chain and adds some level of complexity
46
+
47
+ * There are some very good arguments for keeping the configuration for your
48
+ infrastructure as simple and obvious as possible. Using a turing complete
49
+ configuration language to set up the most critical parts of your
50
+ infrastructure just asks for trouble. With great power and so on.
51
+
52
+ ### The Ugly
53
+
54
+ * Due to the way frebby uses (abuses?) the Ruby programming language, there
55
+ are some quirks where it will not immediately work the way you would expect.
56
+ See the relevant [examples](examples/04_quirks) details.
57
+
58
+ ## How do I use this?
59
+
60
+ ### Installation & Usage
61
+
62
+ At its core, frebby is just a very simple ruby script without dependencies. In
63
+ theory, it is enough to just download the [main file](bin/frebby) and put it
64
+ anywhere in your `$PATH`. However, this won't get you the additional customization
65
+ options. Instead there are more convenient options available:
66
+
67
+ Usually you will want to install frebby directly from rubygems:
68
+
69
+ ```bash
70
+ gem install frebby
71
+ ```
72
+
73
+ Once installed, usage is pretty simple: The `frebby` command simply takes any
74
+ number of configuration files as input, either as arguments or from stdin,
75
+ and output JSON on stdout. There are no other arguments or configurations
76
+ to worry about.
77
+
78
+ ```bash
79
+ frebby /path/to/config/file.rb /path/to/other/config.rb > /new/json/config.json
80
+
81
+ # alternatively:
82
+ frebby < /path/to/config/file.rb > /new/json/config.json
83
+ ```
84
+
85
+ Aternatively, if you don't want to install Ruby locally, you can use frebby
86
+ out of Docker:
87
+
88
+ ```bash
89
+ docker pull oclaussen/frebby
90
+ docker run --rm -i oclaussen/frebby < /path/to/config/file.rb
91
+ ```
92
+
93
+ Remember that you need to either pass your config files to the docker container
94
+ via stdin or mount your working directory, so that frebby can find them.
95
+
96
+ ### Configuration syntax
97
+
98
+ Configuration for frebby is written in Ruby. The basic syntax looks like the
99
+ love child of HCL and Chef's recipe DSL and should be immediately familiar
100
+ to anyhone who has worked with either of them.
101
+
102
+ ```ruby
103
+ # Basic types (strings, numbers, lists, hashes) can be used just like
104
+ # in Ruby:
105
+
106
+ some_number 5
107
+
108
+ some_string <<EOF
109
+ This is
110
+ a very long
111
+ text
112
+ EOF
113
+
114
+ # Nested objects are created like this:
115
+
116
+ some_object 'some_nested_object' do
117
+ some_key 'some value'
118
+ some_other_key 'some other value'
119
+ end
120
+
121
+ # Lists of objects are created by repeated blocks:
122
+
123
+ some_list do
124
+ some_key 'some value'
125
+ end
126
+
127
+ some_list do
128
+ some_other_key 'some_other_value'
129
+ end
130
+ ```
131
+
132
+ This example will produce the following JSON output (minus formatting):
133
+
134
+ ```json
135
+ {
136
+ "some_number": 5,
137
+ "some_string": "This is\na very long\ntext\n",
138
+ "some_object": {
139
+ "some_nested_object": {
140
+ "some_key": "some value",
141
+ "some_other_key": "some other value"
142
+ }
143
+ },
144
+ "some_list": [
145
+ {
146
+ "some_key": "some value"
147
+ },
148
+ {
149
+ "some_other_key": "some other value"
150
+ }
151
+ ]
152
+ }
153
+ ```
154
+
155
+ For some more detailed examples, see the [examples](examples).
156
+
157
+ ### Customization
158
+
159
+ It is also possible to exert a little more control over how frebby translates
160
+ to JSON.
161
+
162
+ ```ruby
163
+ # There are a bunch of customization functions available, that will act whenever
164
+ # frebby tries to transform a key, value or the whole end result
165
+
166
+ # Every translation goes through all registered customization functions, and
167
+ # will apply the first one that returns a non-null result.
168
+
169
+ require 'frebby/hooks'
170
+
171
+ ::Frebby.customize_key do |key, **_data|
172
+ 'new_key' if %w[some_key some_other_key].include?(key)
173
+ end
174
+
175
+ ::Frebby.customize_value do |value, **_data|
176
+ value.sub('value', 'thing') if value.is_a? String
177
+ end
178
+
179
+ ::Frebby.customize_result do |result, **_data|
180
+ result['copied_field'] = result['copy_this']
181
+ result
182
+ end
183
+
184
+ some_object do
185
+ some_key 'some value'
186
+ some_completely_other_key 'some completely other value'
187
+
188
+ some_nested_object do
189
+ some_other_key 'some other value'
190
+ end
191
+ end
192
+
193
+ copy_this 'this value should be copied'
194
+ ```
195
+
196
+ This example will produce the following JSON output:
197
+
198
+ ```json
199
+ {
200
+ "some_object": {
201
+ "new_key": "some thing",
202
+ "some_completely_other_key": "some completely other thing",
203
+ "some_nested_object": {
204
+ "new_key": "some other thing"
205
+ }
206
+ },
207
+ "copy_this": "this thing should be copied",
208
+ "copied_field": "this thing should be copied"
209
+ }
210
+ ```
211
+
212
+ frebby also offers some more convenience functions that take care of common use
213
+ cases. There are also some useful presets for existing tools. Again, take a look
214
+ at the [examples](examples) for some inspiration.
215
+
216
+ ## License & Authors
217
+
218
+ ```text
219
+ Copyright 2018 Ole Claussen
220
+
221
+ Licensed under the Apache License, Version 2.0 (the "License");
222
+ you may not use this file except in compliance with the License.
223
+ You may obtain a copy of the License at
224
+
225
+ http://www.apache.org/licenses/LICENSE-2.0
226
+
227
+ Unless required by applicable law or agreed to in writing, software
228
+ distributed under the License is distributed on an "AS IS" BASIS,
229
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230
+ See the License for the specific language governing permissions and
231
+ limitations under the License.
232
+ ```
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new(:rubocop)
8
+ RSpec::Core::RakeTask.new(:rspec)
9
+
10
+ task default: %i[clean rubocop rspec]
11
+ task all: %i[clean rubocop rspec build]
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'frebby'
5
+ spec.version = '1.0.1'
6
+ spec.author = 'Ole Claussen'
7
+ spec.email = 'claussen.ole@gmail.com'
8
+ spec.license = 'Apache-2.0'
9
+ spec.summary = 'vs. JSON'
10
+ spec.description = <<~DESCRIPTION
11
+ `frebby` is a very, very simple Ruby script that generates JSON out of a Ruby
12
+ based configuration language. It is intended as an alternative to the numerous
13
+ attempts to write a more human-readable language for tool configuration (YAML,
14
+ TOML, HCL, to name a few).
15
+ DESCRIPTION
16
+ spec.homepage = 'https://github.com/oclaussen/frebby'
17
+
18
+ spec.require_paths = ['lib']
19
+ spec.bindir = 'bin'
20
+ spec.executables = ['frebby']
21
+ spec.files = Dir['lib/**/*.rb'] +
22
+ Dir['bin/*'] +
23
+ Dir['*.gemspec'] +
24
+ %w[LICENSE README.md Gemfile Rakefile]
25
+
26
+ spec.add_development_dependency 'rake', '~> 12.3'
27
+ spec.add_development_dependency 'rspec', '~> 3.7'
28
+ spec.add_development_dependency 'rubocop', '~> 0.52'
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frebby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ole Claussen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-10 00:00:00.000000000 Z
11
+ date: 2018-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -63,7 +63,12 @@ executables:
63
63
  extensions: []
64
64
  extra_rdoc_files: []
65
65
  files:
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - Rakefile
66
70
  - bin/frebby
71
+ - frebby.gemspec
67
72
  - lib/frebby/hooks.rb
68
73
  - lib/frebby/presets/ansible.rb
69
74
  - lib/frebby/presets/packer.rb