Skip to content

Commit e7eecac

Browse files
committed
Namespace function to_toml()
1 parent 96293bc commit e7eecac

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../../../puppet_x/stdlib/toml_dumper.rb'
4+
5+
# @summary Convert a data structure and output to TOML.
6+
Puppet::Functions.create_function(:'stdlib::to_toml') do
7+
# @param data Data structure which needs to be converted into TOML
8+
# @return [String] Converted data as TOML string
9+
# @example How to output TOML to a file
10+
# file { '/tmp/config.toml':
11+
# ensure => file,
12+
# content => stdlib::to_toml($myhash),
13+
# }
14+
dispatch :to_toml do
15+
required_param 'Hash', :data
16+
return_type 'String'
17+
end
18+
19+
def to_toml(data)
20+
PuppetX::Stdlib::TomlDumper.new(data).toml_str
21+
end
22+
end

lib/puppet/functions/to_toml.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
# frozen_string_literal: true
22

3-
require_relative '../../puppet_x/stdlib/toml_dumper'
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
44

5-
# @summary Convert a data structure and output to TOML.
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::to_toml`](#stdlibto_toml) instead.
66
Puppet::Functions.create_function(:to_toml) do
7-
# @param data Data structure which needs to be converted into TOML
8-
# @return [String] Converted data as TOML string
9-
# @example How to output TOML to a file
10-
# file { '/tmp/config.toml':
11-
# ensure => file,
12-
# content => to_toml($myhash),
13-
# }
14-
dispatch :to_toml do
15-
required_param 'Hash', :data
16-
return_type 'String'
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
179
end
18-
19-
def to_toml(data)
20-
PuppetX::Stdlib::TomlDumper.new(data).toml_str
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'to_toml', 'This function is deprecated, please use stdlib::to_toml instead.')
12+
call_function('stdlib::to_toml', *args)
2113
end
2214
end

spec/functions/to_toml_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'to_toml' do
5+
describe 'stdlib::to_toml' do
66
context 'fails on invalid params' do
77
it { is_expected.not_to be_nil }
88

0 commit comments

Comments
 (0)