puppet 6.10.1-x64-mingw32 → 6.11.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +20 -12
- data/ext/project_data.yaml +3 -2
- data/ext/regexp_nodes/regexp_nodes.rb +4 -4
- data/ext/windows/service/daemon.rb +33 -8
- data/install.rb +6 -6
- data/lib/puppet.rb +8 -0
- data/lib/puppet/application.rb +1 -1
- data/lib/puppet/application/agent.rb +3 -0
- data/lib/puppet/application/apply.rb +2 -2
- data/lib/puppet/application/describe.rb +3 -9
- data/lib/puppet/application/device.rb +3 -0
- data/lib/puppet/application/doc.rb +1 -1
- data/lib/puppet/application/lookup.rb +1 -1
- data/lib/puppet/application/script.rb +2 -2
- data/lib/puppet/application/ssl.rb +25 -21
- data/lib/puppet/configurer.rb +42 -0
- data/lib/puppet/configurer/downloader.rb +2 -6
- data/lib/puppet/context/trusted_information.rb +42 -4
- data/lib/puppet/defaults.rb +19 -4
- data/lib/puppet/face/module/list.rb +5 -5
- data/lib/puppet/face/module/search.rb +1 -1
- data/lib/puppet/face/module/uninstall.rb +1 -1
- data/lib/puppet/face/module/upgrade.rb +1 -1
- data/lib/puppet/file_serving/http_metadata.rb +1 -1
- data/lib/puppet/file_system.rb +0 -8
- data/lib/puppet/file_system/memory_file.rb +1 -1
- data/lib/puppet/file_system/posix.rb +3 -2
- data/lib/puppet/forge.rb +3 -3
- data/lib/puppet/functions.rb +1 -2
- data/lib/puppet/gettext/module_translations.rb +1 -1
- data/lib/puppet/graph/rb_tree_map.rb +2 -2
- data/lib/puppet/graph/simple_graph.rb +4 -3
- data/lib/puppet/http.rb +29 -0
- data/lib/puppet/http/client.rb +156 -0
- data/lib/puppet/http/errors.rb +30 -0
- data/lib/puppet/http/redirector.rb +48 -0
- data/lib/puppet/http/resolver.rb +5 -0
- data/lib/puppet/http/resolver/settings.rb +5 -0
- data/lib/puppet/http/resolver/srv.rb +13 -0
- data/lib/puppet/http/response.rb +34 -0
- data/lib/puppet/http/retry_after_handler.rb +47 -0
- data/lib/puppet/http/service.rb +18 -0
- data/lib/puppet/http/service/ca.rb +49 -0
- data/lib/puppet/http/session.rb +55 -0
- data/lib/puppet/indirector/file_bucket_file/file.rb +1 -1
- data/lib/puppet/indirector/hiera.rb +2 -0
- data/lib/puppet/indirector/request.rb +1 -1
- data/lib/puppet/indirector/resource/ral.rb +1 -3
- data/lib/puppet/indirector/resource/validator.rb +1 -1
- data/lib/puppet/interface.rb +2 -1
- data/lib/puppet/interface/documentation.rb +1 -1
- data/lib/puppet/loaders.rb +0 -1
- data/lib/puppet/metatype/manager.rb +1 -1
- data/lib/puppet/module.rb +1 -1
- data/lib/puppet/module/task.rb +20 -4
- data/lib/puppet/module_tool/applications/installer.rb +1 -1
- data/lib/puppet/module_tool/applications/uninstaller.rb +3 -3
- data/lib/puppet/module_tool/metadata.rb +1 -1
- data/lib/puppet/module_tool/shared_behaviors.rb +4 -4
- data/lib/puppet/module_tool/tar/mini.rb +1 -1
- data/lib/puppet/network/http.rb +2 -6
- data/lib/puppet/network/http/api/indirected_routes.rb +12 -11
- data/lib/puppet/network/http/connection.rb +10 -12
- data/lib/puppet/network/http/pool.rb +2 -0
- data/lib/puppet/network/http/site.rb +5 -1
- data/lib/puppet/network/resolver.rb +4 -4
- data/lib/puppet/node/environment.rb +4 -2
- data/lib/puppet/pal/pal_impl.rb +2 -2
- data/lib/puppet/parser/ast.rb +1 -1
- data/lib/puppet/parser/ast/resourceparam.rb +1 -1
- data/lib/puppet/parser/functions.rb +1 -1
- data/lib/puppet/parser/scope.rb +8 -7
- data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +1 -1
- data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +1 -1
- data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -2
- data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -7
- data/lib/puppet/pops/loader/module_loaders.rb +1 -1
- data/lib/puppet/pops/loader/task_instantiator.rb +4 -0
- data/lib/puppet/pops/loaders.rb +1 -1
- data/lib/puppet/pops/lookup/hiera_config.rb +1 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
- data/lib/puppet/pops/merge_strategy.rb +22 -18
- data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
- data/lib/puppet/pops/parser/interpolation_support.rb +4 -4
- data/lib/puppet/pops/parser/locator.rb +1 -1
- data/lib/puppet/pops/parser/pn_parser.rb +17 -16
- data/lib/puppet/pops/puppet_stack.rb +52 -48
- data/lib/puppet/pops/types/p_sensitive_type.rb +1 -1
- data/lib/puppet/pops/types/p_uri_type.rb +1 -1
- data/lib/puppet/pops/types/string_converter.rb +10 -10
- data/lib/puppet/pops/types/types.rb +3 -3
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/property/ensure.rb +1 -1
- data/lib/puppet/provider/exec.rb +6 -2
- data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
- data/lib/puppet/provider/nameservice/pw.rb +2 -2
- data/lib/puppet/provider/package/apt.rb +5 -1
- data/lib/puppet/provider/package/dnfmodule.rb +87 -0
- data/lib/puppet/provider/package/dpkg.rb +31 -17
- data/lib/puppet/provider/package/openbsd.rb +1 -1
- data/lib/puppet/provider/package/pip.rb +34 -9
- data/lib/puppet/provider/package/portage.rb +1 -1
- data/lib/puppet/provider/package/rpm.rb +5 -5
- data/lib/puppet/provider/package/windows/package.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/parsedfile.rb +1 -1
- data/lib/puppet/provider/service/daemontools.rb +9 -9
- data/lib/puppet/provider/service/openbsd.rb +1 -1
- data/lib/puppet/provider/service/rcng.rb +2 -2
- data/lib/puppet/provider/service/runit.rb +2 -8
- data/lib/puppet/provider/service/systemd.rb +10 -10
- data/lib/puppet/provider/user/directoryservice.rb +1 -1
- data/lib/puppet/provider/user/user_role_add.rb +1 -1
- data/lib/puppet/provider/user/useradd.rb +22 -13
- data/lib/puppet/provider/user/windows_adsi.rb +4 -5
- data/lib/puppet/reference/indirection.rb +2 -2
- data/lib/puppet/reference/metaparameter.rb +1 -3
- data/lib/puppet/reference/providers.rb +1 -1
- data/lib/puppet/reference/type.rb +3 -9
- data/lib/puppet/reports.rb +1 -1
- data/lib/puppet/resource.rb +1 -1
- data/lib/puppet/resource/catalog.rb +1 -1
- data/lib/puppet/rest/errors.rb +1 -0
- data/lib/puppet/rest/response.rb +1 -0
- data/lib/puppet/rest/route.rb +1 -0
- data/lib/puppet/rest/routes.rb +3 -0
- data/lib/puppet/runtime.rb +25 -0
- data/lib/puppet/settings.rb +3 -3
- data/lib/puppet/settings/environment_conf.rb +1 -0
- data/lib/puppet/ssl/host.rb +1 -1
- data/lib/puppet/ssl/oids.rb +1 -1
- data/lib/puppet/ssl/state_machine.rb +23 -15
- data/lib/puppet/test/test_helper.rb +1 -1
- data/lib/puppet/transaction/report.rb +1 -1
- data/lib/puppet/trusted_external.rb +13 -0
- data/lib/puppet/type.rb +1 -3
- data/lib/puppet/type/exec.rb +7 -3
- data/lib/puppet/type/file.rb +1 -2
- data/lib/puppet/type/file/source.rb +2 -2
- data/lib/puppet/type/package.rb +10 -3
- data/lib/puppet/type/schedule.rb +1 -1
- data/lib/puppet/type/service.rb +1 -1
- data/lib/puppet/util.rb +2 -2
- data/lib/puppet/util/command_line/trollop.rb +1 -1
- data/lib/puppet/util/http_proxy.rb +2 -10
- data/lib/puppet/util/log.rb +2 -2
- data/lib/puppet/util/log/destinations.rb +2 -2
- data/lib/puppet/util/logging.rb +2 -2
- data/lib/puppet/util/metric.rb +2 -2
- data/lib/puppet/util/platform.rb +15 -4
- data/lib/puppet/util/provider_features.rb +2 -4
- data/lib/puppet/util/rdoc.rb +1 -1
- data/lib/puppet/util/reference.rb +1 -1
- data/lib/puppet/util/resource_template.rb +1 -1
- data/lib/puppet/util/selinux.rb +3 -1
- data/lib/puppet/util/windows/registry.rb +7 -5
- data/lib/puppet/vendor.rb +1 -1
- data/lib/puppet/vendor/require_vendored.rb +0 -1
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet/x509/cert_provider.rb +4 -1
- data/locales/puppet.pot +279 -203
- data/man/man5/puppet.conf.5 +30 -8
- data/man/man8/puppet-agent.8 +4 -1
- data/man/man8/puppet-apply.8 +1 -1
- data/man/man8/puppet-catalog.8 +1 -1
- data/man/man8/puppet-config.8 +1 -1
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +1 -1
- data/man/man8/puppet-epp.8 +1 -1
- data/man/man8/puppet-facts.8 +1 -1
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-generate.8 +1 -1
- data/man/man8/puppet-help.8 +1 -1
- data/man/man8/puppet-key.8 +1 -1
- data/man/man8/puppet-lookup.8 +1 -1
- data/man/man8/puppet-man.8 +1 -1
- data/man/man8/puppet-module.8 +1 -1
- data/man/man8/puppet-node.8 +1 -1
- data/man/man8/puppet-parser.8 +1 -1
- data/man/man8/puppet-plugin.8 +1 -1
- data/man/man8/puppet-report.8 +1 -1
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-script.8 +1 -1
- data/man/man8/puppet-ssl.8 +1 -1
- data/man/man8/puppet-status.8 +1 -1
- data/man/man8/puppet.8 +2 -2
- data/spec/fixtures/unit/provider/package/dnfmodule/dnf-module-list-installed.txt +11 -0
- data/spec/integration/configurer_spec.rb +52 -0
- data/spec/lib/puppet/certificate_factory.rb +2 -2
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/application/device_spec.rb +6 -0
- data/spec/unit/application/ssl_spec.rb +4 -7
- data/spec/unit/configurer_spec.rb +1 -0
- data/spec/unit/context/trusted_information_spec.rb +41 -2
- data/spec/unit/http/client_spec.rb +440 -0
- data/spec/unit/http/resolver_spec.rb +45 -0
- data/spec/unit/http/service/ca_spec.rb +106 -0
- data/spec/unit/http/service_spec.rb +32 -0
- data/spec/unit/http/session_spec.rb +102 -0
- data/spec/unit/indirector/resource/ral_spec.rb +4 -4
- data/spec/unit/network/http/connection_spec.rb +119 -145
- data/spec/unit/network/http/site_spec.rb +7 -0
- data/spec/unit/parser/scope_spec.rb +10 -0
- data/spec/unit/pops/loaders/loaders_spec.rb +13 -2
- data/spec/unit/pops/loaders/module_loaders_spec.rb +37 -0
- data/spec/unit/provider/exec_spec.rb +209 -0
- data/spec/unit/provider/package/dnfmodule_spec.rb +186 -0
- data/spec/unit/provider/package/dpkg_spec.rb +238 -78
- data/spec/unit/provider/package/pip_spec.rb +51 -6
- data/spec/unit/provider/service/daemontools_spec.rb +24 -0
- data/spec/unit/provider/service/runit_spec.rb +24 -0
- data/spec/unit/provider/service/systemd_spec.rb +25 -25
- data/spec/unit/provider/user/useradd_spec.rb +46 -0
- data/spec/unit/ssl/host_spec.rb +0 -5
- data/spec/unit/ssl/state_machine_spec.rb +16 -10
- data/spec/unit/type/exec_spec.rb +6 -12
- data/spec/unit/type/file_spec.rb +9 -4
- data/spec/unit/type/package_spec.rb +5 -0
- data/spec/unit/util/execution_spec.rb +16 -0
- data/spec/unit/util/http_proxy_spec.rb +79 -27
- data/spec/unit/util/log/destinations_spec.rb +7 -3
- metadata +54 -25
- data/lib/puppet/pops/loader/null_loader.rb +0 -60
- data/lib/puppet/vendor/deep_merge/CHANGELOG +0 -45
- data/lib/puppet/vendor/deep_merge/Gemfile +0 -3
- data/lib/puppet/vendor/deep_merge/LICENSE +0 -21
- data/lib/puppet/vendor/deep_merge/PUPPET_README.md +0 -6
- data/lib/puppet/vendor/deep_merge/README.md +0 -113
- data/lib/puppet/vendor/deep_merge/Rakefile +0 -19
- data/lib/puppet/vendor/deep_merge/deep_merge.gemspec +0 -35
- data/lib/puppet/vendor/deep_merge/lib/deep_merge.rb +0 -2
- data/lib/puppet/vendor/deep_merge/lib/deep_merge/core.rb +0 -210
- data/lib/puppet/vendor/deep_merge/lib/deep_merge/deep_merge_hash.rb +0 -28
- data/lib/puppet/vendor/deep_merge/lib/deep_merge/rails_compat.rb +0 -27
- data/lib/puppet/vendor/deep_merge/test/test_deep_merge.rb +0 -608
- data/lib/puppet/vendor/load_deep_merge.rb +0 -1
- data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +0 -24
- data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +0 -24
- data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +0 -24
@@ -1,45 +0,0 @@
|
|
1
|
-
2014-01-21 Dan DeLeo <dan@kallistec.com>
|
2
|
-
* Update knockout behavior to better handle nil (b7de40b5)
|
3
|
-
|
4
|
-
2011-08-15 Dan DeLeo <dan@kallistec.com>
|
5
|
-
* Document how to use w/ Rails 3 via Bundler
|
6
|
-
|
7
|
-
2011-07-28 Dan DeLeo <dan@kallistec.com>
|
8
|
-
* Use a plain ol' gemspec and Rakefile for gem creation
|
9
|
-
|
10
|
-
* Ship version 1.0.0
|
11
|
-
|
12
|
-
2011-05-23 Joe Van Dyk <joe@fixieconsulting.com>
|
13
|
-
|
14
|
-
* Added Changelog
|
15
|
-
|
16
|
-
2011-05-18 Joe Van Dyk <joe@fixieconsulting.com>
|
17
|
-
|
18
|
-
* Merging empty strings should work if String#blank? is defined.
|
19
|
-
|
20
|
-
* Use unix line endings
|
21
|
-
|
22
|
-
* Removing extra whitespace
|
23
|
-
|
24
|
-
2010-01-11 Dan DeLeo <dan@kallistec.com>
|
25
|
-
|
26
|
-
* fix boolean merging according to mdkent's patch explicitly test
|
27
|
-
for nils w/ #nil? instead of negating. Thanks mdkent!
|
28
|
-
|
29
|
-
2009-12-25 Dan DeLeo <dan@kallistec.com>
|
30
|
-
|
31
|
-
* miscellaneous cleanup
|
32
|
-
|
33
|
-
* make rails/active_support compat optional
|
34
|
-
|
35
|
-
* add jeweler rake task for gemability
|
36
|
-
|
37
|
-
2009-12-24 Dan DeLeo <dan@kallistec.com>
|
38
|
-
|
39
|
-
* VERSION: Version bump to 0.0.1
|
40
|
-
|
41
|
-
* VERSION: Version bump to 0.0.0
|
42
|
-
|
43
|
-
2009-11-06 Jonathan Weiss <jw@innerewut.de>
|
44
|
-
|
45
|
-
* import
|
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2008-2104 Steve Midgley, Daniel DeLeo
|
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.
|
@@ -1,113 +0,0 @@
|
|
1
|
-
DeepMerge Overview
|
2
|
-
==================
|
3
|
-
|
4
|
-
Deep Merge is a simple set of utility functions for Hash. It permits you to merge elements inside a hash together recursively. The manner by which it does this is somewhat arbitrary (since there is no defining standard for this) but it should end up being pretty intuitive and do what you expect.
|
5
|
-
|
6
|
-
You can learn a lot more about this by reading the test file. It's pretty well documented and has many examples of various merges from very simple to pretty complex.
|
7
|
-
|
8
|
-
The primary need that caused me to write this library is the merging of elements coming from HTTP parameters and related stored parameters in session. This lets a user build up a set of parameters over time, modifying individual items.
|
9
|
-
|
10
|
-
Deep Merge Core Documentation
|
11
|
-
=============================
|
12
|
-
|
13
|
-
`deep_merge!` method permits merging of arbitrary child elements. The two top level elements must be hashes. These hashes can contain unlimited (to stack limit) levels of child elements. These child elements to not have to be of the same types. Where child elements are of the same type, `deep_merge` will attempt to merge them together. Where child elements are not of the same type, `deep_merge` will skip or optionally overwrite the destination element with the contents of the source element at that level. So if you have two hashes like this:
|
14
|
-
|
15
|
-
source = {:x => [1,2,3], :y => 2}
|
16
|
-
dest = {:x => [4,5,'6'], :y => [7,8,9]}
|
17
|
-
dest.deep_merge!(source)
|
18
|
-
Results: {:x => [1,2,3,4,5,'6'], :y => 2}
|
19
|
-
|
20
|
-
By default, `deep_merge!` will overwrite any unmergeables and merge everything else. To avoid this, use `deep_merge` (no bang/exclamation mark)
|
21
|
-
|
22
|
-
Options
|
23
|
-
-------
|
24
|
-
|
25
|
-
Options are specified in the last parameter passed, which should be in hash format:
|
26
|
-
|
27
|
-
hash.deep_merge!({:x => [1,2]}, {:knockout_prefix => '--'})
|
28
|
-
:preserve_unmergeables DEFAULT: false
|
29
|
-
Set to true to skip any unmergeable elements from source
|
30
|
-
:knockout_prefix DEFAULT: nil
|
31
|
-
Set to string value to signify prefix which deletes elements from existing element
|
32
|
-
:sort_merged_arrays DEFAULT: false
|
33
|
-
Set to true to sort all arrays that are merged together
|
34
|
-
:unpack_arrays DEFAULT: nil
|
35
|
-
Set to string value to run "Array::join" then "String::split" against all arrays
|
36
|
-
:merge_hash_arrays DEFAULT: false
|
37
|
-
Set to true to merge hashes within arrays
|
38
|
-
:merge_debug DEFAULT: false
|
39
|
-
Set to true to get console output of merge process for debugging
|
40
|
-
|
41
|
-
Selected Options Details
|
42
|
-
------------------------
|
43
|
-
|
44
|
-
**:knockout_prefix**
|
45
|
-
|
46
|
-
The purpose of this is to provide a way to remove elements from existing Hash by specifying them in a special way in incoming hash
|
47
|
-
|
48
|
-
source = {:x => ['--1', '2']}
|
49
|
-
dest = {:x => ['1', '3']}
|
50
|
-
dest.ko_deep_merge!(source)
|
51
|
-
Results: {:x => ['2','3']}
|
52
|
-
|
53
|
-
Additionally, if the knockout_prefix is passed alone as a string, it will cause the entire element to be removed:
|
54
|
-
|
55
|
-
source = {:x => '--'}
|
56
|
-
dest = {:x => [1,2,3]}
|
57
|
-
dest.ko_deep_merge!(source)
|
58
|
-
Results: {:x => ""}
|
59
|
-
|
60
|
-
**:unpack_arrays**
|
61
|
-
|
62
|
-
The purpose of this is to permit compound elements to be passed in as strings and to be converted into discrete array elements
|
63
|
-
|
64
|
-
irsource = {:x => ['1,2,3', '4']}
|
65
|
-
dest = {:x => ['5','6','7,8']}
|
66
|
-
dest.deep_merge!(source, {:unpack_arrays => ','})
|
67
|
-
Results: {:x => ['1','2','3','4','5','6','7','8'}
|
68
|
-
|
69
|
-
Why: If receiving data from an HTML form, this makes it easy for a checkbox to pass multiple values from within a single HTML element
|
70
|
-
|
71
|
-
**:merge_hash_arrays**
|
72
|
-
|
73
|
-
merge hashes within arrays
|
74
|
-
|
75
|
-
source = {:x => [{:y => 1}]}
|
76
|
-
dest = {:x => [{:z => 2}]}
|
77
|
-
dest.deep_merge!(source, {:merge_hash_arrays => true})
|
78
|
-
Results: {:x => [{:y => 1, :z => 2}]}
|
79
|
-
|
80
|
-
There are many tests for this library - and you can learn more about the features and usages of deep_merge! by just browsing the test examples.
|
81
|
-
|
82
|
-
Using deep_merge in Rails
|
83
|
-
=========================
|
84
|
-
|
85
|
-
To avoid conflict with ActiveSupport, load deep_merge via:
|
86
|
-
|
87
|
-
require 'deep_merge/rails_compat'
|
88
|
-
|
89
|
-
In a Gemfile:
|
90
|
-
|
91
|
-
gem "deep_merge", :require => 'deep_merge/rails_compat'
|
92
|
-
|
93
|
-
The deep_merge methods will then be defined as
|
94
|
-
|
95
|
-
Hash#deeper_merge
|
96
|
-
Hash#deeper_merge!
|
97
|
-
Hash#ko_deeper_merge!
|
98
|
-
|
99
|
-
Simple Example Code
|
100
|
-
===================
|
101
|
-
|
102
|
-
require 'deep_merge'
|
103
|
-
x = {:x => [3,4,5]}
|
104
|
-
y = {:x => [1,2,3]}
|
105
|
-
y.deep_merge!(x)
|
106
|
-
# results: y = {:x => [1,2,3,4,5]}
|
107
|
-
|
108
|
-
Availability
|
109
|
-
============
|
110
|
-
|
111
|
-
`deep_merge` was written by Steve Midgley, and is now maintained by Daniel DeLeo. The official home of `deep_merge` on the internet is now https://github.com/danielsdeleo/deep_merge
|
112
|
-
|
113
|
-
Copyright (c) 2008 Steve Midgley, released under the MIT license
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
|
3
|
-
Rake::TestTask.new do |t|
|
4
|
-
t.libs << FileList['lib/**.rb']
|
5
|
-
t.test_files = FileList['test/test*.rb']
|
6
|
-
end
|
7
|
-
|
8
|
-
task :default => :test
|
9
|
-
|
10
|
-
begin
|
11
|
-
require 'rubygems'
|
12
|
-
require 'rubygems/package_task'
|
13
|
-
|
14
|
-
gemspec = eval(IO.read('deep_merge.gemspec'))
|
15
|
-
Gem::PackageTask.new(gemspec).define
|
16
|
-
rescue LoadError
|
17
|
-
#okay, then
|
18
|
-
end
|
19
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{deep_merge}
|
5
|
-
s.version = "1.0.1"
|
6
|
-
|
7
|
-
s.authors = ["Steve Midgley"]
|
8
|
-
s.date = %q{2011-07-28}
|
9
|
-
s.description = %q{Recursively merge hashes. Now works with Ruby 1.9 and ActiveSupport}
|
10
|
-
s.email = %q{dan@kallistec.com}
|
11
|
-
s.license = 'MIT'
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
"README.md"
|
14
|
-
]
|
15
|
-
s.files = [
|
16
|
-
"CHANGELOG",
|
17
|
-
"README.md",
|
18
|
-
"Rakefile",
|
19
|
-
"lib/deep_merge.rb",
|
20
|
-
"lib/deep_merge/core.rb",
|
21
|
-
"lib/deep_merge/deep_merge_hash.rb",
|
22
|
-
"lib/deep_merge/rails_compat.rb",
|
23
|
-
"test/test_deep_merge.rb"
|
24
|
-
]
|
25
|
-
s.homepage = %q{https://github.com/danielsdeleo/deep_merge}
|
26
|
-
s.require_paths = ["lib"]
|
27
|
-
s.summary = %q{Merge Deeply Nested Hashes}
|
28
|
-
s.test_files = [
|
29
|
-
"test/test_deep_merge.rb"
|
30
|
-
]
|
31
|
-
|
32
|
-
s.add_development_dependency "rake", "~> 10.1"
|
33
|
-
|
34
|
-
end
|
35
|
-
|
@@ -1,210 +0,0 @@
|
|
1
|
-
module DeepMerge
|
2
|
-
|
3
|
-
class InvalidParameter < StandardError; end
|
4
|
-
|
5
|
-
DEFAULT_FIELD_KNOCKOUT_PREFIX = '--'
|
6
|
-
|
7
|
-
# Deep Merge core documentation.
|
8
|
-
# deep_merge! method permits merging of arbitrary child elements. The two top level
|
9
|
-
# elements must be hashes. These hashes can contain unlimited (to stack limit) levels
|
10
|
-
# of child elements. These child elements to not have to be of the same types.
|
11
|
-
# Where child elements are of the same type, deep_merge will attempt to merge them together.
|
12
|
-
# Where child elements are not of the same type, deep_merge will skip or optionally overwrite
|
13
|
-
# the destination element with the contents of the source element at that level.
|
14
|
-
# So if you have two hashes like this:
|
15
|
-
# source = {:x => [1,2,3], :y => 2}
|
16
|
-
# dest = {:x => [4,5,'6'], :y => [7,8,9]}
|
17
|
-
# dest.deep_merge!(source)
|
18
|
-
# Results: {:x => [1,2,3,4,5,'6'], :y => 2}
|
19
|
-
# By default, "deep_merge!" will overwrite any unmergeables and merge everything else.
|
20
|
-
# To avoid this, use "deep_merge" (no bang/exclamation mark)
|
21
|
-
#
|
22
|
-
# Options:
|
23
|
-
# Options are specified in the last parameter passed, which should be in hash format:
|
24
|
-
# hash.deep_merge!({:x => [1,2]}, {:knockout_prefix => '--'})
|
25
|
-
# :preserve_unmergeables DEFAULT: false
|
26
|
-
# Set to true to skip any unmergeable elements from source
|
27
|
-
# :knockout_prefix DEFAULT: nil
|
28
|
-
# Set to string value to signify prefix which deletes elements from existing element
|
29
|
-
# :sort_merged_arrays DEFAULT: false
|
30
|
-
# Set to true to sort all arrays that are merged together
|
31
|
-
# :unpack_arrays DEFAULT: nil
|
32
|
-
# Set to string value to run "Array::join" then "String::split" against all arrays
|
33
|
-
# :merge_hash_arrays DEFAULT: false
|
34
|
-
# Set to true to merge hashes within arrays
|
35
|
-
# :merge_debug DEFAULT: false
|
36
|
-
# Set to true to get console output of merge process for debugging
|
37
|
-
#
|
38
|
-
# Selected Options Details:
|
39
|
-
# :knockout_prefix => The purpose of this is to provide a way to remove elements
|
40
|
-
# from existing Hash by specifying them in a special way in incoming hash
|
41
|
-
# source = {:x => ['--1', '2']}
|
42
|
-
# dest = {:x => ['1', '3']}
|
43
|
-
# dest.ko_deep_merge!(source)
|
44
|
-
# Results: {:x => ['2','3']}
|
45
|
-
# Additionally, if the knockout_prefix is passed alone as a string, it will cause
|
46
|
-
# the entire element to be removed:
|
47
|
-
# source = {:x => '--'}
|
48
|
-
# dest = {:x => [1,2,3]}
|
49
|
-
# dest.ko_deep_merge!(source)
|
50
|
-
# Results: {:x => ""}
|
51
|
-
# :unpack_arrays => The purpose of this is to permit compound elements to be passed
|
52
|
-
# in as strings and to be converted into discrete array elements
|
53
|
-
# irsource = {:x => ['1,2,3', '4']}
|
54
|
-
# dest = {:x => ['5','6','7,8']}
|
55
|
-
# dest.deep_merge!(source, {:unpack_arrays => ','})
|
56
|
-
# Results: {:x => ['1','2','3','4','5','6','7','8'}
|
57
|
-
# Why: If receiving data from an HTML form, this makes it easy for a checkbox
|
58
|
-
# to pass multiple values from within a single HTML element
|
59
|
-
#
|
60
|
-
# :merge_hash_arrays => merge hashes within arrays
|
61
|
-
# source = {:x => [{:y => 1}]}
|
62
|
-
# dest = {:x => [{:z => 2}]}
|
63
|
-
# dest.deep_merge!(source, {:merge_hash_arrays => true})
|
64
|
-
# Results: {:x => [{:y => 1, :z => 2}]}
|
65
|
-
#
|
66
|
-
# There are many tests for this library - and you can learn more about the features
|
67
|
-
# and usages of deep_merge! by just browsing the test examples
|
68
|
-
def self.deep_merge!(source, dest, options = {})
|
69
|
-
# turn on this line for stdout debugging text
|
70
|
-
merge_debug = options[:merge_debug] || false
|
71
|
-
overwrite_unmergeable = !options[:preserve_unmergeables]
|
72
|
-
knockout_prefix = options[:knockout_prefix] || nil
|
73
|
-
raise InvalidParameter, "knockout_prefix cannot be an empty string in deep_merge!" if knockout_prefix == ""
|
74
|
-
raise InvalidParameter, "overwrite_unmergeable must be true if knockout_prefix is specified in deep_merge!" if knockout_prefix && !overwrite_unmergeable
|
75
|
-
# if present: we will split and join arrays on this char before merging
|
76
|
-
array_split_char = options[:unpack_arrays] || false
|
77
|
-
# request that we sort together any arrays when they are merged
|
78
|
-
sort_merged_arrays = options[:sort_merged_arrays] || false
|
79
|
-
# request that arrays of hashes are merged together
|
80
|
-
merge_hash_arrays = options[:merge_hash_arrays] || false
|
81
|
-
di = options[:debug_indent] || ''
|
82
|
-
# do nothing if source is nil
|
83
|
-
return dest if source.nil?
|
84
|
-
# if dest doesn't exist, then simply copy source to it
|
85
|
-
if !(dest) && overwrite_unmergeable
|
86
|
-
dest = source; return dest
|
87
|
-
end
|
88
|
-
|
89
|
-
puts "#{di}Source class: #{source.class.inspect} :: Dest class: #{dest.class.inspect}" if merge_debug
|
90
|
-
if source.kind_of?(Hash)
|
91
|
-
puts "#{di}Hashes: #{source.inspect} :: #{dest.inspect}" if merge_debug
|
92
|
-
source.each do |src_key, src_value|
|
93
|
-
if dest.kind_of?(Hash)
|
94
|
-
puts "#{di} looping: #{src_key.inspect} => #{src_value.inspect} :: #{dest.inspect}" if merge_debug
|
95
|
-
if dest[src_key]
|
96
|
-
puts "#{di} ==>merging: #{src_key.inspect} => #{src_value.inspect} :: #{dest[src_key].inspect}" if merge_debug
|
97
|
-
dest[src_key] = deep_merge!(src_value, dest[src_key], options.merge(:debug_indent => di + ' '))
|
98
|
-
else # dest[src_key] doesn't exist so we want to create and overwrite it (but we do this via deep_merge!)
|
99
|
-
puts "#{di} ==>merging over: #{src_key.inspect} => #{src_value.inspect}" if merge_debug
|
100
|
-
# note: we rescue here b/c some classes respond to "dup" but don't implement it (Numeric, TrueClass, FalseClass, NilClass among maybe others)
|
101
|
-
begin
|
102
|
-
src_dup = src_value.dup # we dup src_value if possible because we're going to merge into it (since dest is empty)
|
103
|
-
rescue TypeError
|
104
|
-
src_dup = src_value
|
105
|
-
end
|
106
|
-
dest[src_key] = deep_merge!(src_value, src_dup, options.merge(:debug_indent => di + ' '))
|
107
|
-
end
|
108
|
-
else # dest isn't a hash, so we overwrite it completely (if permitted)
|
109
|
-
if overwrite_unmergeable
|
110
|
-
puts "#{di} overwriting dest: #{src_key.inspect} => #{src_value.inspect} -over-> #{dest.inspect}" if merge_debug
|
111
|
-
dest = overwrite_unmergeables(source, dest, options)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
elsif source.kind_of?(Array)
|
116
|
-
puts "#{di}Arrays: #{source.inspect} :: #{dest.inspect}" if merge_debug
|
117
|
-
# if we are instructed, join/split any source arrays before processing
|
118
|
-
if array_split_char
|
119
|
-
puts "#{di} split/join on source: #{source.inspect}" if merge_debug
|
120
|
-
source = source.join(array_split_char).split(array_split_char)
|
121
|
-
if dest.kind_of?(Array)
|
122
|
-
dest = dest.join(array_split_char).split(array_split_char)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
# if there's a naked knockout_prefix in source, that means we are to truncate dest
|
126
|
-
if knockout_prefix && source.index(knockout_prefix)
|
127
|
-
dest = clear_or_nil(dest); source.delete(knockout_prefix)
|
128
|
-
end
|
129
|
-
if dest.kind_of?(Array)
|
130
|
-
if knockout_prefix
|
131
|
-
print "#{di} knocking out: " if merge_debug
|
132
|
-
# remove knockout prefix items from both source and dest
|
133
|
-
source.delete_if do |ko_item|
|
134
|
-
retval = false
|
135
|
-
item = ko_item.respond_to?(:gsub) ? ko_item.gsub(%r{^#{knockout_prefix}}, "") : ko_item
|
136
|
-
if item != ko_item
|
137
|
-
print "#{ko_item} - " if merge_debug
|
138
|
-
dest.delete(item)
|
139
|
-
dest.delete(ko_item)
|
140
|
-
retval = true
|
141
|
-
end
|
142
|
-
retval
|
143
|
-
end
|
144
|
-
puts if merge_debug
|
145
|
-
end
|
146
|
-
puts "#{di} merging arrays: #{source.inspect} :: #{dest.inspect}" if merge_debug
|
147
|
-
source_all_hashes = source.all? { |i| i.kind_of?(Hash) }
|
148
|
-
dest_all_hashes = dest.all? { |i| i.kind_of?(Hash) }
|
149
|
-
if merge_hash_arrays && source_all_hashes && dest_all_hashes
|
150
|
-
# merge hashes in lists
|
151
|
-
list = []
|
152
|
-
dest.each_index do |i|
|
153
|
-
list[i] = deep_merge!(source[i] || {}, dest[i],
|
154
|
-
options.merge(:debug_indent => di + ' '))
|
155
|
-
end
|
156
|
-
list += source[dest.count..-1] if source.count > dest.count
|
157
|
-
dest = list
|
158
|
-
else
|
159
|
-
dest = dest | source
|
160
|
-
end
|
161
|
-
dest.sort! if sort_merged_arrays
|
162
|
-
elsif overwrite_unmergeable
|
163
|
-
puts "#{di} overwriting dest: #{source.inspect} -over-> #{dest.inspect}" if merge_debug
|
164
|
-
dest = overwrite_unmergeables(source, dest, options)
|
165
|
-
end
|
166
|
-
else # src_hash is not an array or hash, so we'll have to overwrite dest
|
167
|
-
puts "#{di}Others: #{source.inspect} :: #{dest.inspect}" if merge_debug
|
168
|
-
dest = overwrite_unmergeables(source, dest, options)
|
169
|
-
end
|
170
|
-
puts "#{di}Returning #{dest.inspect}" if merge_debug
|
171
|
-
dest
|
172
|
-
end # deep_merge!
|
173
|
-
|
174
|
-
# allows deep_merge! to uniformly handle overwriting of unmergeable entities
|
175
|
-
def self.overwrite_unmergeables(source, dest, options)
|
176
|
-
merge_debug = options[:merge_debug] || false
|
177
|
-
overwrite_unmergeable = !options[:preserve_unmergeables]
|
178
|
-
knockout_prefix = options[:knockout_prefix] || false
|
179
|
-
di = options[:debug_indent] || ''
|
180
|
-
if knockout_prefix && overwrite_unmergeable
|
181
|
-
if source.kind_of?(String) # remove knockout string from source before overwriting dest
|
182
|
-
src_tmp = source.gsub(%r{^#{knockout_prefix}},"")
|
183
|
-
elsif source.kind_of?(Array) # remove all knockout elements before overwriting dest
|
184
|
-
src_tmp = source.delete_if {|ko_item| ko_item.kind_of?(String) && ko_item.match(%r{^#{knockout_prefix}}) }
|
185
|
-
else
|
186
|
-
src_tmp = source
|
187
|
-
end
|
188
|
-
if src_tmp == source # if we didn't find a knockout_prefix then we just overwrite dest
|
189
|
-
puts "#{di}#{src_tmp.inspect} -over-> #{dest.inspect}" if merge_debug
|
190
|
-
dest = src_tmp
|
191
|
-
else # if we do find a knockout_prefix, then we just delete dest
|
192
|
-
puts "#{di}\"\" -over-> #{dest.inspect}" if merge_debug
|
193
|
-
dest = ""
|
194
|
-
end
|
195
|
-
elsif overwrite_unmergeable
|
196
|
-
dest = source
|
197
|
-
end
|
198
|
-
dest
|
199
|
-
end
|
200
|
-
|
201
|
-
def self.clear_or_nil(obj)
|
202
|
-
if obj.respond_to?(:clear)
|
203
|
-
obj.clear
|
204
|
-
else
|
205
|
-
obj = nil
|
206
|
-
end
|
207
|
-
obj
|
208
|
-
end
|
209
|
-
|
210
|
-
end # module DeepMerge
|