diff options
author | Josh Cooper <josh@puppet.com> | 2018-07-09 19:50:03 -0700 |
---|---|---|
committer | Josh Cooper <josh@puppet.com> | 2018-07-09 19:50:03 -0700 |
commit | 59f4a9e49d397556a60f060faffdc14b734856da (patch) | |
tree | 8b630a7d02fc4e6e207fc3d84b9d78c1f6637191 /lib/puppet/provider/host | |
parent | 34e83e11a5fc344195217d9cd159d022b5d89ec1 (diff) | |
download | puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.gz puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.bz2 |
Automatic validation updates
Updated rubocop violations using `pdk validate -a`.
Diffstat (limited to 'lib/puppet/provider/host')
-rw-r--r-- | lib/puppet/provider/host/parsed.rb | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/lib/puppet/provider/host/parsed.rb b/lib/puppet/provider/host/parsed.rb index d3d0039..c3531e6 100644 --- a/lib/puppet/provider/host/parsed.rb +++ b/lib/puppet/provider/host/parsed.rb @@ -2,45 +2,44 @@ require 'puppet/provider/parsedfile' hosts = nil case Facter.value(:osfamily) -when "Solaris"; hosts = "/etc/inet/hosts" -when "windows" +when 'Solaris' then hosts = '/etc/inet/hosts' +when 'windows' require 'win32/resolv' hosts = Win32::Resolv.get_hosts_path else - hosts = "/etc/hosts" + hosts = '/etc/hosts' end +Puppet::Type.type(:host).provide(:parsed, parent: Puppet::Provider::ParsedFile, + default_target: hosts, filetype: :flat) do + confine exists: hosts -Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile, - :default_target => hosts,:filetype => :flat) do - confine :exists => hosts - - text_line :comment, :match => /^#/ - text_line :blank, :match => /^\s*$/ + text_line :comment, match: %r{^#} + text_line :blank, match: %r{^\s*$} hosts_pattern = '^([0-9a-f:]\S+)\s+([^#\s+]\S+)\s*(.*?)?(?:\s*#\s*(.*))?$' - record_line :parsed, :fields => %w{ip name host_aliases comment}, - :optional => %w{host_aliases comment}, - :match => /#{hosts_pattern}/, - :post_parse => proc { |hash| - # An absent comment should match "comment => ''" - hash[:comment] = '' if hash[:comment].nil? or hash[:comment] == :absent - unless hash[:host_aliases].nil? or hash[:host_aliases] == :absent - hash[:host_aliases].gsub!(/\s+/,' ') # Change delimiter - end - }, - :to_line => proc { |hash| - [:ip, :name].each do |n| - raise ArgumentError, _("%{attr} is a required attribute for hosts") % { attr: n } unless hash[n] and hash[n] != :absent - end - str = "#{hash[:ip]}\t#{hash[:name]}" - if hash.include? :host_aliases and !hash[:host_aliases].nil? and hash[:host_aliases] != :absent - str += "\t#{hash[:host_aliases]}" - end - if hash.include? :comment and !hash[:comment].empty? - str += "\t# #{hash[:comment]}" - end - str - } + record_line :parsed, fields: ['ip', 'name', 'host_aliases', 'comment'], + optional: ['host_aliases', 'comment'], + match: %r{#{hosts_pattern}}, + post_parse: proc { |hash| + # An absent comment should match "comment => ''" + hash[:comment] = '' if hash[:comment].nil? || hash[:comment] == :absent + unless hash[:host_aliases].nil? || hash[:host_aliases] == :absent + hash[:host_aliases].gsub!(%r{\s+}, ' ') # Change delimiter + end + }, + to_line: proc { |hash| + [:ip, :name].each do |n| + raise ArgumentError, _('%{attr} is a required attribute for hosts') % { attr: n } unless hash[n] && hash[n] != :absent + end + str = "#{hash[:ip]}\t#{hash[:name]}" + if hash.include?(:host_aliases) && !hash[:host_aliases].nil? && hash[:host_aliases] != :absent + str += "\t#{hash[:host_aliases]}" + end + if hash.include?(:comment) && !hash[:comment].empty? + str += "\t# #{hash[:comment]}" + end + str + } - text_line :incomplete, :match => /(?! (#{hosts_pattern}))/ + text_line :incomplete, match: %r{(?! (#{hosts_pattern}))} end |