Skip to content

Commit e45c4d6

Browse files
committed
(MAINT) Rubocop - (lib) fixes for markdown
1 parent 28ace22 commit e45c4d6

16 files changed

+70
-75
lines changed

lib/puppet-strings/markdown/base.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
require 'puppet-strings/json'
55
require 'puppet-strings/yard'
66

7+
# Implements classes that make elements in a YARD::Registry hash easily accessible for template.
78
module PuppetStrings::Markdown
89
# This class makes elements in a YARD::Registry hash easily accessible for templates.
910
#
1011
# Here's an example hash:
11-
#{:name=>:klass,
12+
# {:name=>:klass,
1213
# :file=>"(stdin)",
1314
# :line=>16,
1415
# :inherits=>"foo::bar",
@@ -57,11 +58,11 @@ def initialize(registry, component_type)
5758

5859
# generate 1:1 tag methods
5960
# e.g. {:tag_name=>"author", :text=>"eputnam"}
60-
{ :return_val => 'return',
61-
:since => 'since',
62-
:summary => 'summary',
63-
:note => 'note',
64-
:todo => 'todo' }.each do |method_name, tag_name|
61+
{ return_val: 'return',
62+
since: 'since',
63+
summary: 'summary',
64+
note: 'note',
65+
todo: 'todo' }.each do |method_name, tag_name|
6566
# @return [String] unless the tag is nil or the string.empty?
6667
define_method method_name do
6768
@tags.find { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }[:text] if @tags.any? { |tag| tag[:tag_name] == tag_name && !tag[:text].empty? }
@@ -148,7 +149,7 @@ def toc_info
148149
{
149150
name: name.to_s,
150151
link: link,
151-
desc: summary || @registry[:docstring][:text][0..140].gsub("\n",' '),
152+
desc: summary || @registry[:docstring][:text][0..140].tr("\n", ' '),
152153
private: private?
153154
}
154155
end
@@ -165,9 +166,9 @@ def private?
165166
def word_wrap(text, line_width: 120, break_sequence: "\n")
166167
return unless text
167168

168-
text.split("\n").collect! do |line|
169-
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1#{break_sequence}").strip : line
170-
end * break_sequence
169+
text.split("\n").map! { |line|
170+
line.length > line_width ? line.gsub(%r{(.{1,#{line_width}})(\s+|$)}, "\\1#{break_sequence}").strip : line
171+
} * break_sequence
171172
end
172173

173174
# @return [String] full markdown rendering of a component
@@ -176,7 +177,7 @@ def render(template)
176177
begin
177178
PuppetStrings::Markdown.erb(file).result(binding)
178179
rescue StandardError => e
179-
fail "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
180+
raise "Processing #{@registry[:file]}:#{@registry[:line]} with #{file} => #{e}"
180181
end
181182
end
182183

lib/puppet-strings/markdown/data_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def render
2020
end
2121
end
2222

23+
# Generates Markdown for a Puppet Function.
2324
class DataType::Function < Base
2425
def initialize(registry)
2526
super(registry, 'data_type_function')

lib/puppet-strings/markdown/data_types.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,32 @@
33
require_relative 'data_type'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Data Types.
67
module DataTypes
7-
88
# @return [Array] list of data types
99
def self.in_dtypes
1010
arr = YARD::Registry.all(:puppet_data_type).map!(&:to_hash)
1111
arr.concat(YARD::Registry.all(:puppet_data_type_alias).map!(&:to_hash))
1212

13-
arr.sort! { |a,b| a[:name] <=> b[:name] }
13+
arr.sort! { |a, b| a[:name] <=> b[:name] }
1414
arr.map! { |a| PuppetStrings::Markdown::DataType.new(a) }
1515
end
1616

1717
def self.contains_private?
18-
result = false
19-
unless in_dtypes.nil?
20-
in_dtypes.find { |type| type.private? }.nil? ? false : true
21-
end
18+
return if in_dtypes.nil?
19+
in_dtypes.find { |type| type.private? }.nil? ? false : true
2220
end
2321

2422
def self.render
25-
final = in_dtypes.length > 0 ? "## Data types\n\n" : ""
23+
final = !in_dtypes.empty? ? "## Data types\n\n" : ''
2624
in_dtypes.each do |type|
2725
final += type.render unless type.private?
2826
end
2927
final
3028
end
3129

32-
3330
def self.toc_info
34-
final = ["Data types"]
31+
final = ['Data types']
3532

3633
in_dtypes.each do |type|
3734
final.push(type.toc_info)

lib/puppet-strings/markdown/defined_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Defined Type.
67
class DefinedType < Base
78
def initialize(registry)
89
@template = 'classes_and_defines.erb'

lib/puppet-strings/markdown/defined_types.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
require_relative 'defined_type'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Defined Types.
67
module DefinedTypes
7-
88
# @return [Array] list of defined types
99
def self.in_dtypes
1010
arr = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash)
1111
arr.map! { |a| PuppetStrings::Markdown::DefinedType.new(a) }
1212
end
1313

1414
def self.contains_private?
15-
result = false
16-
unless in_dtypes.nil?
17-
in_dtypes.find { |type| type.private? }.nil? ? false : true
18-
end
15+
return if in_dtypes.nil?
16+
in_dtypes.find { |type| type.private? }.nil? ? false : true
1917
end
2018

2119
def self.render
22-
final = in_dtypes.length > 0 ? "## Defined types\n\n" : ""
20+
final = !in_dtypes.empty? ? "## Defined types\n\n" : ''
2321
in_dtypes.each do |type|
2422
final += type.render unless type.private?
2523
end
2624
final
2725
end
2826

2927
def self.toc_info
30-
final = ["Defined types"]
28+
final = ['Defined types']
3129

3230
in_dtypes.each do |type|
3331
final.push(type.toc_info)

lib/puppet-strings/markdown/function.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Function.
67
class Function < Base
78
attr_reader :signatures
89

@@ -21,14 +22,14 @@ def render
2122

2223
def type
2324
t = @registry[:type]
24-
if /ruby4x/.match?(t)
25-
"Ruby 4.x API"
26-
elsif /ruby3/.match?(t)
27-
"Ruby 3.x API"
28-
elsif /ruby/.match?(t)
29-
"Ruby"
25+
if %r{ruby4x}.match?(t)
26+
'Ruby 4.x API'
27+
elsif %r{ruby3}.match?(t)
28+
'Ruby 3.x API'
29+
elsif %r{ruby}.match?(t)
30+
'Ruby'
3031
else
31-
"Puppet Language"
32+
'Puppet Language'
3233
end
3334
end
3435

@@ -37,10 +38,11 @@ def error_type(type)
3738
end
3839

3940
def error_text(text)
40-
"#{text.split(' ').drop(1).join(' ')}"
41+
text.split(' ').drop(1).join(' ').to_s
4142
end
4243
end
4344

45+
# Implements methods to retrieve information about a function signature.
4446
class Function::Signature < Base
4547
def initialize(registry)
4648
@registry = registry

lib/puppet-strings/markdown/functions.rb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
require_relative 'function'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Functions.
67
module Functions
7-
88
# @return [Array] list of functions
99
def self.in_functions
1010
arr = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash)
1111
arr.map! { |a| PuppetStrings::Markdown::Function.new(a) }
1212
end
1313

1414
def self.contains_private?
15-
result = false
16-
unless in_functions.nil?
17-
in_functions.find { |func| func.private? }.nil? ? false : true
18-
end
15+
return if in_functions.nil?
16+
in_functions.find { |func| func.private? }.nil? ? false : true
1917
end
2018

2119
def self.render
22-
final = in_functions.length > 0 ? "## Functions\n\n" : ""
20+
final = !in_functions.empty? ? "## Functions\n\n" : ''
2321
in_functions.each do |func|
2422
final += func.render unless func.private?
2523
end
2624
final
2725
end
2826

2927
def self.toc_info
30-
final = ["Functions"]
28+
final = ['Functions']
3129

3230
in_functions.each do |func|
3331
final.push(func.toc_info)
@@ -37,4 +35,3 @@ def self.toc_info
3735
end
3836
end
3937
end
40-

lib/puppet-strings/markdown/puppet_class.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Class.
67
class PuppetClass < Base
78
def initialize(registry)
89
@template = 'classes_and_defines.erb'

lib/puppet-strings/markdown/puppet_classes.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
require_relative 'puppet_class'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Classes.
67
module PuppetClasses
7-
88
# @return [Array] list of classes
99
def self.in_classes
1010
arr = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)
1111
arr.map! { |a| PuppetStrings::Markdown::PuppetClass.new(a) }
1212
end
1313

1414
def self.contains_private?
15-
result = false
16-
unless in_classes.nil?
17-
in_classes.find { |klass| klass.private? }.nil? ? false : true
18-
end
15+
return if in_classes.nil?
16+
in_classes.find { |klass| klass.private? }.nil? ? false : true
1917
end
2018

2119
def self.render
22-
final = in_classes.length > 0 ? "## Classes\n\n" : ""
20+
final = !in_classes.empty? ? "## Classes\n\n" : ''
2321
in_classes.each do |klass|
2422
final += klass.render unless klass.private?
2523
end
2624
final
2725
end
2826

2927
def self.toc_info
30-
final = ["Classes"]
28+
final = ['Classes']
3129

3230
in_classes.each do |klass|
3331
final.push(klass.toc_info)

lib/puppet-strings/markdown/puppet_plan.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Plan.
67
class PuppetPlan < Base
78
def initialize(registry)
89
@template = 'classes_and_defines.erb'

lib/puppet-strings/markdown/puppet_plans.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
require_relative 'puppet_plan'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Plans.
67
module PuppetPlans
7-
88
# @return [Array] list of classes
99
def self.in_plans
1010
arr = YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash)
1111
arr.map! { |a| PuppetStrings::Markdown::PuppetPlan.new(a) }
1212
end
1313

1414
def self.contains_private?
15-
result = false
16-
unless in_plans.nil?
17-
in_plans.find { |plan| plan.private? }.nil? ? false : true
18-
end
15+
return if in_plans.nil?
16+
in_plans.find { |plan| plan.private? }.nil? ? false : true
1917
end
2018

2119
def self.render
22-
final = in_plans.length > 0 ? "## Plans\n\n" : ""
20+
final = !in_plans.empty? ? "## Plans\n\n" : ''
2321
in_plans.each do |plan|
2422
final += plan.render unless plan.private?
2523
end
2624
final
2725
end
2826

2927
def self.toc_info
30-
final = ["Plans"]
28+
final = ['Plans']
3129

3230
in_plans.each do |plan|
3331
final.push(plan.toc_info)

lib/puppet-strings/markdown/puppet_task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Task.
67
class PuppetTask < Base
78
def initialize(registry)
89
@template = 'puppet_task.erb'
@@ -21,6 +22,5 @@ def supports_noop
2122
def input_method
2223
@registry[:input_method]
2324
end
24-
2525
end
2626
end

lib/puppet-strings/markdown/puppet_tasks.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require_relative 'puppet_task'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for Puppet Tasks.
67
module PuppetTasks
7-
88
# @return [Array] list of classes
99
def self.in_tasks
1010
arr = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash)
@@ -16,15 +16,15 @@ def self.contains_private?
1616
end
1717

1818
def self.render
19-
final = in_tasks.length > 0 ? "## Tasks\n\n" : ""
19+
final = !in_tasks.empty? ? "## Tasks\n\n" : ''
2020
in_tasks.each do |task|
2121
final += task.render unless task.private?
2222
end
2323
final
2424
end
2525

2626
def self.toc_info
27-
final = ["Tasks"]
27+
final = ['Tasks']
2828

2929
in_tasks.each do |task|
3030
final.push(task.toc_info)

lib/puppet-strings/markdown/resource_type.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'puppet-strings/markdown/base'
44

55
module PuppetStrings::Markdown
6+
# Generates Markdown for a Puppet Resource Type.
67
class ResourceType < Base
78
def initialize(registry)
89
@template = 'resource_type.erb'
@@ -45,7 +46,7 @@ def parameters
4546
end
4647

4748
def regex_in_data_type?(data_type)
48-
m = data_type.match(/\w+\[\/.*\/\]/)
49+
m = data_type.match(%r{\w+\[/.*/\]})
4950
m unless m.nil? || m.length.zero?
5051
end
5152
end

0 commit comments

Comments
 (0)