Skip to content

Commit 7f5f58d

Browse files
committed
Namespace function type_of()
1 parent 4393f5a commit 7f5f58d

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# Returns the type of the passed value.
5+
#
6+
# @example how to compare values' types
7+
# # compare the types of two values
8+
# if stdlib::type_of($first_value) != stdlib::type_of($second_value) { fail("first_value and second_value are different types") }
9+
# @example how to compare against an abstract type
10+
# unless stdlib::type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
11+
# unless stdlib::type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
12+
#
13+
# See the documentation for "The Puppet Type System" for more information about types.
14+
# See the `assert_type()` function for flexible ways to assert the type of a value.
15+
#
16+
# The built-in type() function in puppet is generally preferred over this function
17+
# this function is provided for backwards compatibility.
18+
Puppet::Functions.create_function(:'stdlib::type_of') do
19+
# @return [String]
20+
# the type of the passed value
21+
#
22+
# @param value
23+
def type_of(value)
24+
Puppet::Pops::Types::TypeCalculator.infer_set(value)
25+
end
26+
end

lib/puppet/functions/type_of.rb

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

3-
# @summary
4-
# Returns the type of the passed value.
5-
#
6-
# @example how to compare values' types
7-
# # compare the types of two values
8-
# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
9-
# @example how to compare against an abstract type
10-
# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
11-
# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
12-
#
13-
# See the documentation for "The Puppet Type System" for more information about types.
14-
# See the `assert_type()` function for flexible ways to assert the type of a value.
15-
#
16-
# The built-in type() function in puppet is generally preferred over this function
17-
# this function is provided for backwards compatibility.
3+
# THIS FILE WAS GENERATED BY `rake regenerate_unamespaced_shims`
4+
5+
# @summary DEPRECATED. Use the namespaced function [`stdlib::type_of`](#stdlibtype_of) instead.
186
Puppet::Functions.create_function(:type_of) do
19-
# @return [String]
20-
# the type of the passed value
21-
#
22-
# @param value
23-
def type_of(value)
24-
Puppet::Pops::Types::TypeCalculator.infer_set(value)
7+
dispatch :deprecation_gen do
8+
repeated_param 'Any', :args
9+
end
10+
def deprecation_gen(*args)
11+
call_function('deprecation', 'type_of', 'This function is deprecated, please use stdlib::type_of instead.')
12+
call_function('stdlib::type_of', *args)
2513
end
2614
end

spec/functions/type_of_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
require 'spec_helper'
44

55
if ENV['FUTURE_PARSER'] == 'yes'
6-
describe 'type_of' do
6+
describe 'stdlib::type_of' do
77
pending 'teach rspec-puppet to load future-only functions under 3.7.5' do
88
it { is_expected.not_to be_nil }
99
end
1010
end
1111
end
1212

1313
if Puppet.version.to_f >= 4.0
14-
describe 'type_of' do
14+
describe 'stdlib::type_of' do
1515
it { is_expected.not_to be_nil }
1616
it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
1717
it { is_expected.to run.with_params('', '').and_raise_error(ArgumentError) }

0 commit comments

Comments
 (0)