puppet-strings 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -6
  3. data/lib/puppet-strings.rb +2 -0
  4. data/lib/puppet-strings/describe.rb +2 -0
  5. data/lib/puppet-strings/json.rb +2 -0
  6. data/lib/puppet-strings/markdown.rb +11 -9
  7. data/lib/puppet-strings/markdown/base.rb +11 -3
  8. data/lib/puppet-strings/markdown/data_type.rb +2 -0
  9. data/lib/puppet-strings/markdown/data_types.rb +3 -1
  10. data/lib/puppet-strings/markdown/defined_type.rb +2 -0
  11. data/lib/puppet-strings/markdown/defined_types.rb +3 -1
  12. data/lib/puppet-strings/markdown/function.rb +9 -7
  13. data/lib/puppet-strings/markdown/functions.rb +3 -1
  14. data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
  15. data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
  16. data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
  17. data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
  18. data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
  19. data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
  20. data/lib/puppet-strings/markdown/resource_type.rb +2 -0
  21. data/lib/puppet-strings/markdown/resource_types.rb +3 -1
  22. data/lib/puppet-strings/markdown/table_of_contents.rb +3 -1
  23. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +7 -3
  24. data/lib/puppet-strings/markdown/templates/data_type.erb +12 -4
  25. data/lib/puppet-strings/markdown/templates/data_type_function.erb +1 -1
  26. data/lib/puppet-strings/markdown/templates/function.erb +1 -1
  27. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  28. data/lib/puppet-strings/markdown/templates/resource_type.erb +8 -2
  29. data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
  30. data/lib/puppet-strings/tasks.rb +2 -0
  31. data/lib/puppet-strings/tasks/generate.rb +2 -0
  32. data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
  33. data/lib/puppet-strings/version.rb +3 -1
  34. data/lib/puppet-strings/yard.rb +3 -0
  35. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  36. data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
  37. data/lib/puppet-strings/yard/code_objects/class.rb +4 -2
  38. data/lib/puppet-strings/yard/code_objects/data_type.rb +4 -2
  39. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +2 -0
  40. data/lib/puppet-strings/yard/code_objects/defined_type.rb +4 -2
  41. data/lib/puppet-strings/yard/code_objects/function.rb +6 -3
  42. data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
  43. data/lib/puppet-strings/yard/code_objects/plan.rb +4 -2
  44. data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
  45. data/lib/puppet-strings/yard/code_objects/task.rb +2 -0
  46. data/lib/puppet-strings/yard/code_objects/type.rb +3 -0
  47. data/lib/puppet-strings/yard/handlers.rb +2 -0
  48. data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
  49. data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
  50. data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
  51. data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
  52. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
  53. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +2 -0
  54. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
  55. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
  56. data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
  57. data/lib/puppet-strings/yard/handlers/ruby/base.rb +5 -0
  58. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +33 -17
  59. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -7
  60. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
  61. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +4 -1
  62. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +14 -6
  63. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +5 -2
  64. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +12 -1
  65. data/lib/puppet-strings/yard/parsers.rb +2 -0
  66. data/lib/puppet-strings/yard/parsers/json/parser.rb +2 -0
  67. data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
  68. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +12 -10
  69. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +4 -0
  70. data/lib/puppet-strings/yard/tags.rb +2 -0
  71. data/lib/puppet-strings/yard/tags/enum_tag.rb +2 -0
  72. data/lib/puppet-strings/yard/tags/factory.rb +2 -0
  73. data/lib/puppet-strings/yard/tags/overload_tag.rb +4 -1
  74. data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
  75. data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
  76. data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
  77. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +1 -1
  78. data/lib/puppet-strings/yard/util.rb +4 -1
  79. data/lib/puppet/application/strings.rb +2 -0
  80. data/lib/puppet/face/strings.rb +4 -1
  81. data/lib/puppet/feature/rgen.rb +2 -0
  82. data/lib/puppet/feature/yard.rb +2 -0
  83. metadata +5 -5
@@ -1,4 +1,4 @@
1
- ### `<%= name %>`
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -1,4 +1,4 @@
1
- ### `<%= name %>`
1
+ ### <a name="<%= link %>"></a>`<%= name %>`
2
2
 
3
3
  <% if text -%>
4
4
  <%= text %>
@@ -98,7 +98,11 @@ Default value: `<%= prop[:default] %>`
98
98
  The following parameters are available in the `<%= name %>` <%= @type %>.
99
99
 
100
100
  <% parameters.each do |param| -%>
101
- ##### `<%= param[:name] %>`
101
+ * [`<%= param[:name] %>`](#<%= param[:name] %>)
102
+ <% end -%>
103
+
104
+ <% parameters.each do |param| -%>
105
+ ##### <a name="<%= param[:name] %>"></a>`<%= param[:name] %>`
102
106
 
103
107
  <% if param[:values] -%>
104
108
  Valid values: `<%= param[:values].map { |value| value_string(value) }.join('`, `') %>`
@@ -116,7 +120,9 @@ Aliases: `<%= param[:aliases].to_s.delete('{').delete('}') %>`
116
120
  Data type: `<%= param[:data_type] %>`<%= "\n_\*this data type contains a regex that may not be accurately reflected in generated documentation_" if regex_in_data_type?(param[:data_type]) %>
117
121
 
118
122
  <% end -%>
123
+ <% if param[:description] -%>
119
124
  <%= word_wrap(param[:description]) %>
125
+ <% end -%>
120
126
 
121
127
  <% if options_for_param(param[:name]) -%>
122
128
  Options:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Monkey patch URL decoding in object displays. Usually :: is interpreted as a
2
4
  # namespace, but this is disabled in our base object, and so instead gets
3
5
  # URL-encoded.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake'
2
4
  require 'rake/tasklib'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings'
2
4
 
3
5
  # Implements the strings:generate task.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/tasks'
2
4
 
3
5
  namespace :strings do
@@ -5,6 +7,7 @@ namespace :strings do
5
7
  task :checkout do
6
8
  if Dir.exist?('doc')
7
9
  fail "The 'doc' directory (#{File.expand_path('doc')}) is not a Git repository! Remove it and run the Rake task again." unless Dir.exist?('doc/.git')
10
+
8
11
  Dir.chdir('doc') do
9
12
  system 'git checkout gh-pages'
10
13
  system 'git pull --rebase origin gh-pages'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetStrings
2
- VERSION = '2.5.0'.freeze
4
+ VERSION = '2.6.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yard'
2
4
 
3
5
  # Module for YARD related functionality.
@@ -102,6 +104,7 @@ class YARD::CLI::Stats
102
104
 
103
105
  def stats_for_puppet_plans
104
106
  return unless PuppetStrings.puppet_5?
107
+
105
108
  output 'Puppet Plans', *type_statistics_all(:puppet_plan)
106
109
  end
107
110
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD code objects.
2
4
  module PuppetStrings::Yard::CodeObjects
3
5
  require 'puppet-strings/yard/code_objects/class'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Implements the base code object.
2
4
  class PuppetStrings::Yard::CodeObjects::Base < YARD::CodeObjects::NamespaceObject
3
5
  # Allocates a new code object.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet classes.
@@ -52,8 +54,8 @@ class PuppetStrings::Yard::CodeObjects::Class < PuppetStrings::Yard::CodeObjects
52
54
  hash[:inherits] = statement.parent_class if statement.parent_class
53
55
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
54
56
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
55
- hash[:defaults] = defaults unless defaults.empty?
56
- hash[:source] = source unless source && source.empty?
57
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
58
+ hash[:source] = source unless source.nil? || source.empty?
57
59
  hash
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -86,8 +88,8 @@ class PuppetStrings::Yard::CodeObjects::DataType < PuppetStrings::Yard::CodeObje
86
88
  hash[:file] = file
87
89
  hash[:line] = line
88
90
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring, %i[param option enum return example])
89
- hash[:defaults] = defaults unless defaults.empty?
90
- hash[:source] = source unless source && source.empty?
91
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
92
+ hash[:source] = source unless source.nil? || source.empty?
91
93
  hash[:functions] = functions.map do |func|
92
94
  {
93
95
  name: func.name,
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet defined types.
@@ -51,8 +53,8 @@ class PuppetStrings::Yard::CodeObjects::DefinedType < PuppetStrings::Yard::CodeO
51
53
  hash[:line] = line
52
54
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
53
55
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
54
- hash[:defaults] = defaults unless defaults.empty?
55
- hash[:source] = source unless source && source.empty?
56
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
57
+ hash[:source] = source unless source.nil? || source.empty?
56
58
  hash
57
59
  end
58
60
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet functions.
@@ -61,11 +63,12 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
61
63
  # @return [String] Returns the Puppet signature of the function.
62
64
  def signature
63
65
  return '' if self.has_tag? :overload
66
+
64
67
  tags = self.tags(:param)
65
68
  args = @parameters.map do |parameter|
66
69
  name, default = parameter
67
70
  tag = tags.find { |t| t.name == name } if tags
68
- type = tag && tag.types ? "#{tag.type} " : 'Any '
71
+ type = tag&.types ? "#{tag.type} " : 'Any '
69
72
  prefix = "#{name[0]}" if name.start_with?('*', '&')
70
73
  name = name[1..-1] if prefix
71
74
  default = " = #{default}" if default
@@ -96,8 +99,8 @@ class PuppetStrings::Yard::CodeObjects::Function < PuppetStrings::Yard::CodeObje
96
99
 
97
100
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
98
101
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
99
- hash[:defaults] = defaults unless defaults.empty?
100
- hash[:source] = source unless source && source.empty?
102
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
103
+ hash[:source] = source unless source.nil? || source.empty?
101
104
  hash
102
105
  end
103
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/base'
2
4
 
3
5
  # Implements the base class for "groups".
@@ -10,6 +12,7 @@ class PuppetStrings::Yard::CodeObjects::Group < PuppetStrings::Yard::CodeObjects
10
12
  def self.instance(key)
11
13
  instance = P(:root, key)
12
14
  return instance unless instance.is_a?(YARD::CodeObjects::Proxy)
15
+
13
16
  instance = self.new(:root, key)
14
17
  instance.visibility = :hidden
15
18
  P(:root).children << instance
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  class PuppetStrings::Yard::CodeObjects::Plans < PuppetStrings::Yard::CodeObjects::Group
@@ -49,8 +51,8 @@ class PuppetStrings::Yard::CodeObjects::Plan < PuppetStrings::Yard::CodeObjects:
49
51
  hash[:line] = line
50
52
  hash[:docstring] = PuppetStrings::Yard::Util.docstring_to_hash(docstring)
51
53
  defaults = Hash[*parameters.reject{ |p| p[1].nil? }.flatten]
52
- hash[:defaults] = defaults unless defaults.empty?
53
- hash[:source] = source unless source && source.empty?
54
+ hash[:defaults] = defaults unless defaults.nil? || defaults.empty?
55
+ hash[:source] = source unless source.nil? || source.empty?
54
56
  hash
55
57
  end
56
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet providers.
@@ -42,6 +44,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
42
44
  # @return [void]
43
45
  def add_confine(key, value)
44
46
  return unless key && value
47
+
45
48
  @confines ||= {}
46
49
  @confines[key] = value
47
50
  end
@@ -51,6 +54,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
51
54
  # @return [void]
52
55
  def add_feature(feature)
53
56
  return unless feature
57
+
54
58
  @features ||= []
55
59
  @features << feature
56
60
  end
@@ -60,6 +64,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
60
64
  # @return [void]
61
65
  def add_default(constraints)
62
66
  return unless constraints
67
+
63
68
  @defaults ||= []
64
69
  @defaults << constraints
65
70
  end
@@ -70,6 +75,7 @@ class PuppetStrings::Yard::CodeObjects::Provider < PuppetStrings::Yard::CodeObje
70
75
  # @return [void]
71
76
  def add_command(key, value)
72
77
  return unless key && value
78
+
73
79
  @commands ||= {}
74
80
  @commands[key] = value
75
81
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
 
3
5
  # Implements the group for Puppet tasks.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/code_objects/group'
2
4
  require 'puppet-strings/yard/util'
3
5
 
@@ -167,6 +169,7 @@ class PuppetStrings::Yard::CodeObjects::Type < PuppetStrings::Yard::CodeObjects:
167
169
  def providers
168
170
  providers = YARD::Registry.all("puppet_providers_#{name}".intern)
169
171
  return providers if providers.empty?
172
+
170
173
  providers.first.children
171
174
  end
172
175
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The module for custom YARD handlers.
2
4
  module PuppetStrings::Yard::Handlers
3
5
  # The module for custom Ruby YARD handlers.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PuppetStrings::Yard::Handlers::Helpers
2
4
  # Logs a warning if a summary tag has more than 140 characters
3
5
  def self.validate_summary_tag(object)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class PuppetStrings::Yard::Handlers::JSON::Base < YARD::Handlers::Base
2
4
  def self.handles?(statement)
3
5
  handlers.any? {|handler| statement.is_a?(handler)}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/json/base'
2
4
  require 'puppet-strings/yard/parsers'
3
5
  require 'puppet-strings/yard/parsers/json/parser'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Implements the base handler for Puppet language handlers.
2
4
  class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
3
5
  # Determine sif the handler handles the given statement.
@@ -17,6 +19,7 @@ class PuppetStrings::Yard::Handlers::Puppet::Base < YARD::Handlers::Base
17
19
  tags = object.tags(:param)
18
20
  tags.each do |tag|
19
21
  next if statement.parameters.find { |p| tag.name == p.name }
22
+
20
23
  log.warn "The @param tag for parameter '#{tag.name}' has no matching parameter at #{statement.file}:#{statement.line}." unless tag.name == 'name' || tag.name == 'title'
21
24
  end
22
25
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/puppet/base'
3
5
  require 'puppet-strings/yard/parsers'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/puppet/base'
3
5
  require 'puppet-strings/yard/parsers'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/puppet/base'
3
5
  require 'puppet-strings/yard/parsers'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/puppet/base'
3
5
  require 'puppet-strings/yard/parsers'
@@ -37,7 +39,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
37
39
  def add_return_tag(object, type=nil)
38
40
  tag = object.tag(:return)
39
41
  if tag
40
- if (type && tag.types.first) && (type != tag.types.first)
42
+ if (type && tag.types && tag.types.first) && (type != tag.types.first)
41
43
  log.warn "Documented return type does not match return type in function definition near #{statement.file}:#{statement.line}."
42
44
  end
43
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/puppet/base'
3
5
  require 'puppet-strings/yard/parsers'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ripper'
2
4
 
3
5
  # Implements the base handler for Ruby language handlers.
@@ -12,6 +14,7 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
12
14
  # @return [String] Returns a string representation of the node or nil if a string representation was not possible.
13
15
  def node_as_string(node)
14
16
  return nil unless node
17
+
15
18
  case node.type
16
19
  when :symbol, :symbol_literal
17
20
  node.source[1..-1]
@@ -42,8 +45,10 @@ class PuppetStrings::Yard::Handlers::Ruby::Base < YARD::Handlers::Ruby::Base
42
45
  def get_name(statementobject, statementtype)
43
46
  parameters = statementobject.parameters(false)
44
47
  raise YARD::Parser::UndocumentableError, "Expected at least one parameter to #{statementtype} at #{statementobject.file}:#{statementobject.line}." if parameters.empty?
48
+
45
49
  name = node_as_string(parameters.first)
46
50
  raise YARD::Parser::UndocumentableError, "Expected a symbol or string literal for first parameter but found '#{parameters.first.type}' at #{statement.file}:#{statement.line}." unless name
51
+
47
52
  name
48
53
  end
49
54
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'puppet-strings/yard/handlers/helpers'
2
4
  require 'puppet-strings/yard/handlers/ruby/base'
3
5
  require 'puppet-strings/yard/code_objects'
@@ -10,8 +12,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
10
12
 
11
13
  process do
12
14
  return unless statement.count > 1
15
+
13
16
  ruby_module_name = statement[0].source
14
17
  return unless ruby_module_name == 'Puppet::DataTypes' || ruby_module_name == 'DataTypes' # rubocop:disable Style/MultipleComparison This reads better
18
+
15
19
  object = get_datatype_yard_object(get_name(statement, 'Puppet::DataTypes.create_type'))
16
20
  # Extract the interface definition
17
21
  type_interface = extract_data_type_interface
@@ -65,8 +69,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
65
69
  next false unless node.is_a?(YARD::Parser::Ruby::MethodCallNode) &&
66
70
  node.method_name &&
67
71
  node.method_name.source == 'interface'
72
+
68
73
  parameters = node.parameters(false)
69
74
  next false unless parameters.count >= 1
75
+
70
76
  interface_string = node_as_string(parameters[0])
71
77
  next false unless interface_string
72
78
 
@@ -97,8 +103,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
97
103
  # @return [YARD::Parser::Ruby::AstNode, nil]
98
104
  def find_ruby_ast_node(ast_node, recurse = false, &block)
99
105
  raise ArgumentError, 'find_ruby_ast_node requires a block' unless block_given?
106
+
100
107
  is_found = yield ast_node
101
108
  return ast_node if is_found
109
+
102
110
  if ast_node.respond_to?(:children)
103
111
  ast_node.children.each do |child_node|
104
112
  child_found = find_ruby_ast_node(child_node, recurse, &block)
@@ -128,7 +136,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
128
136
  # Anything else is ignored
129
137
  class LazyLiteralEvaluator
130
138
  def initialize
131
- @literal_visitor ||= ::Puppet::Pops::Visitor.new(self, "literal", 0, 0)
139
+ @literal_visitor = ::Puppet::Pops::Visitor.new(self, "literal", 0, 0)
132
140
  end
133
141
 
134
142
  def literal(ast)
@@ -136,72 +144,72 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
136
144
  end
137
145
 
138
146
  # ----- The following methods are different/additions from the original Literal_evaluator
139
- def literal_Object(o) # rubocop:disable Naming/UncommunicativeMethodParamName
147
+ def literal_Object(o)
140
148
  # Ignore any other object types
141
149
  end
142
150
 
143
- def literal_AccessExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName
151
+ def literal_AccessExpression(o)
144
152
  # Extract the raw text of the Access Expression
145
153
  ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(o).extract_text
146
154
  end
147
155
 
148
- def literal_QualifiedReference(o) # rubocop:disable Naming/UncommunicativeMethodParamName
156
+ def literal_QualifiedReference(o)
149
157
  # Extract the raw text of the Qualified Reference
150
158
  ::Puppet::Pops::Adapters::SourcePosAdapter.adapt(o).extract_text
151
159
  end
152
160
 
153
161
  # ----- The following methods are the same as the original Literal_evaluator
154
- def literal_Factory(o) # rubocop:disable Naming/UncommunicativeMethodParamName
162
+ def literal_Factory(o)
155
163
  literal(o.model)
156
164
  end
157
165
 
158
- def literal_Program(o) # rubocop:disable Naming/UncommunicativeMethodParamName
166
+ def literal_Program(o)
159
167
  literal(o.body)
160
168
  end
161
169
 
162
- def literal_LiteralString(o) # rubocop:disable Naming/UncommunicativeMethodParamName
170
+ def literal_LiteralString(o)
163
171
  o.value
164
172
  end
165
173
 
166
- def literal_QualifiedName(o) # rubocop:disable Naming/UncommunicativeMethodParamName
174
+ def literal_QualifiedName(o)
167
175
  o.value
168
176
  end
169
177
 
170
- def literal_LiteralNumber(o) # rubocop:disable Naming/UncommunicativeMethodParamName
178
+ def literal_LiteralNumber(o)
171
179
  o.value
172
180
  end
173
181
 
174
- def literal_UnaryMinusExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName
182
+ def literal_UnaryMinusExpression(o)
175
183
  -1 * literal(o.expr)
176
184
  end
177
185
 
178
- def literal_LiteralBoolean(o) # rubocop:disable Naming/UncommunicativeMethodParamName
186
+ def literal_LiteralBoolean(o)
179
187
  o.value
180
188
  end
181
189
 
182
- def literal_LiteralUndef(o) # rubocop:disable Naming/UncommunicativeMethodParamName
190
+ def literal_LiteralUndef(o)
183
191
  nil
184
192
  end
185
193
 
186
- def literal_LiteralDefault(o) # rubocop:disable Naming/UncommunicativeMethodParamName
194
+ def literal_LiteralDefault(o)
187
195
  :default
188
196
  end
189
197
 
190
- def literal_LiteralRegularExpression(o) # rubocop:disable Naming/UncommunicativeMethodParamName
198
+ def literal_LiteralRegularExpression(o)
191
199
  o.value
192
200
  end
193
201
 
194
- def literal_ConcatenatedString(o) # rubocop:disable Naming/UncommunicativeMethodParamName
202
+ def literal_ConcatenatedString(o)
195
203
  # use double quoted string value if there is no interpolation
196
204
  throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString)
197
205
  o.segments[0].value
198
206
  end
199
207
 
200
- def literal_LiteralList(o) # rubocop:disable Naming/UncommunicativeMethodParamName
208
+ def literal_LiteralList(o)
201
209
  o.values.map { |v| literal(v) }
202
210
  end
203
211
 
204
- def literal_LiteralHash(o) # rubocop:disable Naming/UncommunicativeMethodParamName
212
+ def literal_LiteralHash(o)
205
213
  o.entries.reduce({}) do |result, entry|
206
214
  result[literal(entry.key)] = literal(entry.value)
207
215
  result
@@ -275,8 +283,10 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
275
283
  # Find param tags with a type that is different from the actual definition
276
284
  object.tags(:param).reject { |tag| tag.types.nil? }.each do |tag|
277
285
  next if actual_params_hash[tag.name].nil?
286
+
278
287
  actual_data_type = actual_params_hash[tag.name][:types]
279
288
  next if actual_data_type.nil?
289
+
280
290
  log.warn "The @param tag for '#{tag.name}' has a different type definition than the actual attribute near #{object.file}:#{object.line}." if tag.types != actual_data_type
281
291
  end
282
292
 
@@ -290,6 +300,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
290
300
  # Set the type in the param tag
291
301
  object.tags(:param).each do |tag|
292
302
  next if actual_params_hash[tag.name].nil?
303
+
293
304
  tag.types = actual_params_hash[tag.name][:types]
294
305
  end
295
306
  end
@@ -311,10 +322,13 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
311
322
  # Functions with the wrong return type
312
323
  object.meths.each do |meth|
313
324
  next unless actual_func_names.include?(meth.name.to_s)
325
+
314
326
  return_tag = meth.docstring.tag(:return)
315
327
  next if return_tag.nil?
328
+
316
329
  actual_return_types = [actual_functions_hash[meth.name.to_s][:return_type]]
317
330
  next if return_tag.types == actual_return_types
331
+
318
332
  log.warn "The @return tag for '#{meth.name}' has a different type definition than the actual function near #{object.file}:#{object.line}. Expected #{actual_return_types}"
319
333
  return_tag.types = actual_return_types
320
334
  end
@@ -329,6 +343,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
329
343
  # Add the return type for the methods if missing
330
344
  object.meths.each do |meth|
331
345
  next unless meth.docstring.tag(:return).nil?
346
+
332
347
  meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type]))
333
348
  end
334
349
 
@@ -336,6 +351,7 @@ class PuppetStrings::Yard::Handlers::Ruby::DataTypeHandler < PuppetStrings::Yard
336
351
  object.meths.each do |meth|
337
352
  validate_function_method!(object, meth, actual_functions_hash[meth.name.to_s])
338
353
  next unless meth.docstring.tag(:return).nil?
354
+
339
355
  meth.docstring.add_tag(YARD::Tags::Tag.new(:return, '', actual_functions_hash[meth.name.to_s][:return_type]))
340
356
  end
341
357