aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMelissa Stone <melissa@puppet.com>2018-04-13 15:10:47 -0700
committerMelissa Stone <melissa@puppet.com>2018-04-16 16:19:34 -0700
commit42416d957e7a96d156c532480018201e3c5ef487 (patch)
tree8d7248a2b59c7d5150c525cb82289fac977c3f97 /lib
parent88cd8802c5841b619baa3df2313f7b1fdf68308f (diff)
downloadpuppet-mailalias_core-42416d957e7a96d156c532480018201e3c5ef487.tar.gz
puppet-mailalias_core-42416d957e7a96d156c532480018201e3c5ef487.tar.bz2
Fix rubocop violations
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/mailalias/aliases.rb45
-rw-r--r--lib/puppet/type/mailalias.rb26
2 files changed, 38 insertions, 33 deletions
diff --git a/lib/puppet/provider/mailalias/aliases.rb b/lib/puppet/provider/mailalias/aliases.rb
index 038d450..9a9fa22 100644
--- a/lib/puppet/provider/mailalias/aliases.rb
+++ b/lib/puppet/provider/mailalias/aliases.rb
@@ -2,49 +2,48 @@ require 'puppet/provider/parsedfile'
Puppet::Type.type(:mailalias).provide(
:aliases,
- :parent => Puppet::Provider::ParsedFile,
- :default_target => "/etc/aliases",
- :filetype => :flat
+ parent: Puppet::Provider::ParsedFile,
+ default_target: '/etc/aliases',
+ filetype: :flat,
) do
- text_line :comment, :match => /^#/
- text_line :blank, :match => /^\s*$/
+ text_line :comment, match: %r{^#}
+ text_line :blank, match: %r{^\s*$}
- record_line :aliases, :fields => %w{name recipient}, :separator => /\s*:\s*/, :block_eval => :instance do
+ record_line :aliases, fields: %w[name recipient], separator: %r{\s*:\s*}, block_eval: :instance do
def post_parse(record)
if record[:recipient]
- record[:recipient] = record[:recipient].split(/\s*,\s*/).collect { |d| d.gsub(/^['"]|['"]$/, '') }
+ record[:recipient] = record[:recipient].split(%r{\s*,\s*}).map { |d| d.gsub(%r{^['"]|['"]$}, '') }
end
record
end
def process(line)
ret = {}
- records = line.split(':',4)
+ records = line.split(':', 4)
ret[:name] = records[0].strip
- if records.length == 4 and records[2].strip == 'include'
- ret[:file] = records[3].strip
+ if records.length == 4 && records[2].strip == 'include'
+ ret[:file] = records[3].strip
else
- records = line.split(':',2)
- ret[:recipient] = records[1].strip
+ records = line.split(':', 2)
+ ret[:recipient] = records[1].strip
end
ret
end
def to_line(record)
if record[:recipient]
- dest = record[:recipient].collect do |d|
- # Quote aliases that have non-alpha chars
- if d =~ /[^-+\w@.]/
- '"%s"' % d
- else
- d
- end
- end.join(",")
- "#{record[:name]}: #{dest}"
+ dest = record[:recipient].map { |d|
+ # Quote aliases that have non-alpha chars
+ if d =~ %r{[^-+\w@.]}
+ '"%s"' % d
+ else
+ d
+ end
+ }.join(',')
+ "#{record[:name]}: #{dest}"
elsif record[:file]
- "#{record[:name]}: :include: #{record[:file]}"
+ "#{record[:name]}: :include: #{record[:file]}"
end
end
end
end
-
diff --git a/lib/puppet/type/mailalias.rb b/lib/puppet/type/mailalias.rb
index b5df7b8..b26cd12 100644
--- a/lib/puppet/type/mailalias.rb
+++ b/lib/puppet/type/mailalias.rb
@@ -1,14 +1,15 @@
+# Creates an email alias in the local alias database.
module Puppet
Type.newtype(:mailalias) do
- @doc = "Creates an email alias in the local alias database."
+ @doc = 'Creates an email alias in the local alias database.'
ensurable
- newparam(:name, :namevar => true) do
- desc "The alias name."
+ newparam(:name, namevar: true) do
+ desc 'The alias name.'
end
- newproperty(:recipient, :array_matching => :all) do
+ newproperty(:recipient, array_matching: :all) do
desc "Where email should be sent. Multiple values
should be specified as an array. The file and the
recipient entries are mutually exclusive."
@@ -19,9 +20,9 @@ module Puppet
recipient entries are mutually exclusive."
validate do |value|
- unless Puppet::Util.absolute_path?(value)
- fail Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }
- end
+ unless Puppet::Util.absolute_path?(value)
+ raise Puppet::Error, _("File paths must be fully qualified, not '%{value}'") % { value: value }
+ end
end
end
@@ -29,17 +30,22 @@ module Puppet
desc "The file in which to store the aliases. Only used by
those providers that write to disk."
- defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
+ defaultto do
+ if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target
else
nil
end
- }
+ end
end
validate do
if self[:recipient] && self[:file]
- self.fail _("You cannot specify both a recipient and a file")
+ # rubocop:disable Style/SignalException
+ # We need to override this cop because puppet overrides `fail`. We need
+ # to use the puppet implementation of `fail` rather than the default
+ # ruby implementation
+ fail _('You cannot specify both a recipient and a file')
end
end
end