From be6d8dd56266e3a0236a216c6ee80a728fcc0214 Mon Sep 17 00:00:00 2001 From: Dave Armstrong Date: Mon, 10 Jun 2019 11:20:51 +0100 Subject: [PATCH] (maint) Add to_hash function to resourceShim for compatibility --- lib/puppet/resource_api/glue.rb | 4 ++++ spec/puppet/resource_api/glue_spec.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/puppet/resource_api/glue.rb b/lib/puppet/resource_api/glue.rb index 85628c3e..8eee448d 100644 --- a/lib/puppet/resource_api/glue.rb +++ b/lib/puppet/resource_api/glue.rb @@ -41,6 +41,10 @@ def to_hierayaml YAML.dump('type' => { title => attributes }).split("\n").drop(2).join("\n") + "\n" end + def to_hash + values + end + # attribute names that are not title or namevars def filtered_keys values.keys.reject { |k| k == :title || !attr_def[k] || (attr_def[k][:behaviour] == :namevar && @namevars.size == 1) } diff --git a/spec/puppet/resource_api/glue_spec.rb b/spec/puppet/resource_api/glue_spec.rb index 2a1ee68d..c31b8c00 100644 --- a/spec/puppet/resource_api/glue_spec.rb +++ b/spec/puppet/resource_api/glue_spec.rb @@ -56,5 +56,9 @@ it { expect(instance.to_hierayaml).to eq " ? |-\n foo:\n bar\n : attr: value\n attr_ro: fixed\n" } end end + + describe '.to_hash' do + it { expect(instance.to_hash).to eq(namevarname: 'title', attr: 'value', attr_ro: 'fixed') } + end end end