Skip to content

Commit 2816281

Browse files
committed
Add support for ensurable in types_extras_handler
Puppet's `file` type uses the `ensurable` method in an extra file, so add support for that.
1 parent 0129234 commit 2816281

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
require 'puppet-strings/yard/code_objects'
66
require 'puppet-strings/yard/util'
77

8-
# Implements the handler for Puppet resource type newparam/newproperty calls written in Ruby.
8+
# Implements the handler for Puppet resource type newparam/newproperty/ensurable calls written in Ruby.
99
class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Yard::Handlers::Ruby::TypeBase
1010
# The default docstring when ensurable is used without given a docstring.
1111
DEFAULT_ENSURABLE_DOCSTRING = 'The basic property that the resource should be in.'
1212

1313
namespace_only
1414
handles method_call(:newparam)
1515
handles method_call(:newproperty)
16+
handles method_call(:ensurable)
1617

1718
process do
1819

@@ -38,9 +39,15 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
3839
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
3940
return unless ['Type', 'Puppet::Type'].include?(module_name) && method1_name == 'type'
4041

42+
# ensurable is syntatic sugar for newproperty
4143
typename = get_name(statement[0], 'Puppet::Type.type')
42-
method2_name = caller_method
43-
propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
44+
if caller_method == 'ensurable'
45+
method2_name = 'newproperty'
46+
propertyname = 'ensure'
47+
else
48+
method2_name = caller_method
49+
propertyname = get_name(statement, "Puppet::Type.type().#{method2_name}")
50+
end
4451

4552
typeobject = get_type_yard_object(typename)
4653

spec/unit/puppet-strings/yard/handlers/ruby/type_extras_handler_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,24 @@
4949
expect(object.parameters[0].isnamevar).to eq(true)
5050
end
5151
end
52+
53+
describe 'parsing source with ensurable' do
54+
let(:source) { <<~SOURCE
55+
Puppet::Type.newtype(:database) do
56+
desc 'database'
57+
end
58+
Puppet::Type.type(:database).ensurable do
59+
desc 'What state the database should be in.'
60+
end
61+
SOURCE
62+
}
63+
64+
it 'generates a doc string for an ensurable' do
65+
expect(subject.size).to eq(1)
66+
object = subject.first
67+
expect(object.properties.size).to eq(1)
68+
expect(object.properties[0].name).to eq('ensure')
69+
expect(object.properties[0].docstring).to eq('What state the database should be in.')
70+
end
71+
end
5272
end

0 commit comments

Comments
 (0)