Skip to content

Commit 07bb191

Browse files
committed
Namespace function parsehocon()
1 parent e284700 commit 07bb191

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

lib/puppet/functions/parsehocon.rb

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

3-
# @summary
4-
# This function accepts HOCON as a string and converts it into the correct
5-
# Puppet structure
6-
#
7-
# @example How to parse hocon
8-
# $data = parsehocon("{any valid hocon: string}")
9-
#
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::parsehocon`](#stdlibparsehocon) instead.
106
Puppet::Functions.create_function(:parsehocon) do
11-
# @param hocon_string A valid HOCON string
12-
# @param default An optional default to return if parsing hocon_string fails
13-
# @return [Data]
14-
dispatch :parsehocon do
15-
param 'String', :hocon_string
16-
optional_param 'Any', :default
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
179
end
18-
19-
def parsehocon(hocon_string, default = :no_default_provided)
20-
require 'hocon/config_factory'
21-
22-
begin
23-
data = Hocon::ConfigFactory.parse_string(hocon_string)
24-
data.resolve.root.unwrapped
25-
rescue Hocon::ConfigError::ConfigParseError => err
26-
Puppet.debug("Parsing hocon failed with error: #{err.message}")
27-
raise err if default == :no_default_provided
28-
default
29-
end
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'parsehocon', 'This function is deprecated, please use stdlib::parsehocon instead.')
12+
call_function('stdlib::parsehocon', *args)
3013
end
3114
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# This function accepts HOCON as a string and converts it into the correct
5+
# Puppet structure
6+
#
7+
# @example How to parse hocon
8+
# $data = stdlib::parsehocon("{any valid hocon: string}")
9+
#
10+
Puppet::Functions.create_function(:'stdlib::parsehocon') do
11+
# @param hocon_string A valid HOCON string
12+
# @param default An optional default to return if parsing hocon_string fails
13+
# @return [Data]
14+
dispatch :parsehocon do
15+
param 'String', :hocon_string
16+
optional_param 'Any', :default
17+
end
18+
19+
def parsehocon(hocon_string, default = :no_default_provided)
20+
require 'hocon/config_factory'
21+
22+
begin
23+
data = Hocon::ConfigFactory.parse_string(hocon_string)
24+
data.resolve.root.unwrapped
25+
rescue Hocon::ConfigError::ConfigParseError => err
26+
Puppet.debug("Parsing hocon failed with error: #{err.message}")
27+
raise err if default == :no_default_provided
28+
default
29+
end
30+
end
31+
end

spec/functions/parsehocon_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 'parsehocon' do
5+
describe 'stdlib::parsehocon' do
66
it { is_expected.to run.with_params('').and_return({}) }
77
it { is_expected.to run.with_params('valid hocon: string').and_return('valid hocon' => 'string') }
88
it { is_expected.to run.with_params('invalid').and_raise_error(Hocon::ConfigError::ConfigParseError) }

0 commit comments

Comments
 (0)