yaml_extensions 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3c70c36c6334a48be6abb0efdad9dd6a5f5927362d9dabb609b28a0e37d4bb1b
4
+ data.tar.gz: 50a61007d447a40d7189ee5733bfd3c14613aacd9b3397f4a5f83fc2951ee8d2
5
+ SHA512:
6
+ metadata.gz: e162f9c0f312262c79a270d1d7a5779340d302025c0ec6109b456241ca484a062ef4b50680be7fd4d1a25f6f805d40a7c8032aa9d628cacffc04b4a6f296e905
7
+ data.tar.gz: d31b63c17381277fb188fa7c30c8a432c7d73b54f2f155ca64d9512eef7a55f0b6b77df2603fa3f2edf47b0d2485530b25ffc03cd70593092cb67798b370133e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at info@200ok.ch. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yaml_extensions.gemspec
4
+ gemspec
5
+
6
+ gem 'rake', '~> 12.0'
7
+ gem 'minitest', '~> 5.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 200ok GmbH, Switzerland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.org ADDED
@@ -0,0 +1,165 @@
1
+ * YamlExtensions
2
+ :PROPERTIES:
3
+ :CUSTOM_ID: yamlextensions
4
+ :END:
5
+
6
+ Extensions to make YAML even more useful.
7
+
8
+ ** Installation
9
+ :PROPERTIES:
10
+ :CUSTOM_ID: installation
11
+ :END:
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ #+BEGIN_SRC ruby
16
+ gem 'yaml_extensions'
17
+ #+END_SRC
18
+
19
+ And then execute:
20
+
21
+ #+BEGIN_EXAMPLE
22
+ $ bundle install
23
+ #+END_EXAMPLE
24
+
25
+ Or install it yourself as:
26
+
27
+ #+BEGIN_EXAMPLE
28
+ $ gem install yaml_extensions
29
+ #+END_EXAMPLE
30
+
31
+ ** Usage
32
+ :PROPERTIES:
33
+ :CUSTOM_ID: usage
34
+ :END:
35
+
36
+ Just require =yaml_extensions=. For now this will [[https://twitter.com/dhh/status/813075241236762624][freedom patch]] the
37
+ YAML module to extend its functionality.
38
+
39
+ #+begin_src ruby
40
+ require 'yaml_extensions'
41
+ #+end_src
42
+
43
+ Deep Merge any key-value-list by replacing YAML's regular Merge Key
44
+ =<<= with =<<<=. Example:
45
+
46
+ #+begin_src yaml
47
+ defaults: &DEFAULTS
48
+ hello: world
49
+ this:
50
+ is:
51
+ even: deeper
52
+
53
+ main:
54
+ <<<: *DEFAULTS
55
+ this:
56
+ is:
57
+ somewhat: deep
58
+ #+end_src
59
+
60
+ will be interpreted as
61
+
62
+ #+begin_src yaml
63
+ defaults:
64
+ hello: world
65
+ this:
66
+ is:
67
+ even: deeper
68
+
69
+ main:
70
+ this:
71
+ is:
72
+ somewhat: deep
73
+ even: deeper
74
+ hello: world
75
+ #+end_src
76
+
77
+ This does not acutally patch the parser, but runs a transformation on
78
+ the already parse data structure. Multiple deep merges can be achieved
79
+ by appending digits to =<<<=. Exmaple:
80
+
81
+ #+begin_src yaml
82
+ defaults: &DEFAULTS
83
+ hello: world
84
+ this:
85
+ is:
86
+ even: deeper
87
+
88
+ overrides: &OVERRIDES
89
+ this:
90
+ is:
91
+ even: deeper, i tell you
92
+
93
+ main:
94
+ <<<1: *DEFAULTS
95
+ <<<2: *OVERRIDES
96
+ this:
97
+ is:
98
+ somewhat: deep
99
+ #+end_src
100
+
101
+ will be interpreted as
102
+
103
+ #+begin_src yaml
104
+ defaults:
105
+ hello: world
106
+ this:
107
+ is:
108
+ even: deeper
109
+
110
+ overrides:
111
+ this:
112
+ is:
113
+ even: deeper, i tell you
114
+
115
+ main:
116
+ this:
117
+ is:
118
+ somewhat: deep
119
+ even: deeper, i tell you
120
+ hello: world
121
+ #+end_src
122
+
123
+ ** Development
124
+ :PROPERTIES:
125
+ :CUSTOM_ID: development
126
+ :END:
127
+
128
+ After checking out the repo, run =bin/setup= to install dependencies.
129
+ Then, run =rake test= to run the tests. You can also run =bin/console=
130
+ for an interactive prompt that will allow you to experiment.
131
+
132
+ To install this gem onto your local machine, run
133
+ =bundle exec rake install=. To release a new version, update the version
134
+ number in =version.rb=, and then run =bundle exec rake release=, which
135
+ will create a git tag for the version, push git commits and tags, and
136
+ push the =.gem= file to [[https://rubygems.org][rubygems.org]].
137
+
138
+ ** Contributing
139
+ :PROPERTIES:
140
+ :CUSTOM_ID: contributing
141
+ :END:
142
+
143
+ Bug reports and pull requests are welcome on GitHub at
144
+ https://github.com/200ok-ch/yaml_extensions. This project is intended to
145
+ be a safe, welcoming space for collaboration, and contributors are
146
+ expected to adhere to the
147
+ [[https://github.com/branch14/yaml_extensions/blob/master/CODE_OF_CONDUCT.md][code of conduct]].
148
+
149
+ ** License
150
+ :PROPERTIES:
151
+ :CUSTOM_ID: license
152
+ :END:
153
+
154
+ The gem is available as open source under the terms of the
155
+ [[https://opensource.org/licenses/MIT][MIT License]].
156
+
157
+ ** Code of Conduct
158
+ :PROPERTIES:
159
+ :CUSTOM_ID: code-of-conduct
160
+ :END:
161
+
162
+ Everyone interacting in the YamlExtensions project's codebases, issue
163
+ trackers, chat rooms and mailing lists is expected to follow the
164
+ [[https://github.com/200ok-ch/yaml_extensions/blob/master/CODE_OF_CONDUCT.md][code
165
+ of conduct]].
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yaml_extensions"
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,3 @@
1
+ module YamlExtensions
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+
3
+ require 'yaml_extensions/version'
4
+
5
+ class Hash
6
+ def deep_merge!(other_hash, &block)
7
+ merge!(other_hash) do |key, this, that|
8
+ if this.is_a?(Hash) && that.is_a?(Hash)
9
+ this.deep_merge!(that, &block)
10
+ elsif block_given?
11
+ yield(key, this, that)
12
+ else
13
+ that
14
+ end
15
+ end
16
+ end
17
+
18
+ def walk(&block)
19
+ reduce({}) do |aggregator, entry|
20
+ key, val = entry
21
+ nval = val.class.method_defined?(:walk) ? val.walk(&block) : val
22
+ aggregator.merge(key => nval)
23
+ end.tap { |result| yield(result) if block_given? }
24
+ end
25
+ end
26
+
27
+ class Array
28
+ def walk(&block)
29
+ map { |e| e.class.method_defined?(:walk) ? e.walk(&block) : e }
30
+ end
31
+ end
32
+
33
+ module YamlExtensions
34
+ def load(*args)
35
+ super(*args).walk do |h|
36
+ h.keys.sort.reverse_each do |key|
37
+ if key =~ /^<<<\d*$/
38
+ h.deep_merge!(h.delete(key)) { |_, this, _| this }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ module YAML
46
+ class << self
47
+ prepend YamlExtensions
48
+ end
49
+ end
50
+
51
+ puts YAML.dump(YAML.load(ARGF.read)) if $PROGRAM_NAME == __FILE__
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/yaml_extensions/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'yaml_extensions'
5
+ spec.version = YamlExtensions::VERSION
6
+ spec.authors = ['Phil Hofmann']
7
+ spec.email = ['phil@200ok.ch']
8
+
9
+ spec.summary = %q{Extensions to make YAML even more useful}
10
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
11
+ spec.homepage = 'https://github.com/200ok-ch/yaml_extensions'
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'] = spec.homepage
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
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ # spec.bindir = 'exe'
27
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yaml_extensions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Phil Hofmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-07-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - phil@200ok.ch
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - CODE_OF_CONDUCT.md
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.org
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/yaml_extensions.rb
29
+ - lib/yaml_extensions/version.rb
30
+ - yaml_extensions.gemspec
31
+ homepage: https://github.com/200ok-ch/yaml_extensions
32
+ licenses:
33
+ - MIT
34
+ metadata:
35
+ homepage_uri: https://github.com/200ok-ch/yaml_extensions
36
+ source_code_uri: https://github.com/200ok-ch/yaml_extensions
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.0.3
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Extensions to make YAML even more useful
56
+ test_files: []