diff --git a/lib/puppet/parser/functions/to_hash_settings.rb b/lib/puppet/parser/functions/to_hash_settings.rb index 576180c8..88083906 100644 --- a/lib/puppet/parser/functions/to_hash_settings.rb +++ b/lib/puppet/parser/functions/to_hash_settings.rb @@ -30,9 +30,8 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, 'to_hash_settings(): Requires hash to work with') unless hash.is_a?(Hash) - return hash.reduce({}) do |acc, kv| + return hash.each_with_object({}) do |kv, acc| acc[id + kv[0]] = { 'key' => kv[0], 'value' => kv[1] } - acc end end end diff --git a/lib/puppet/provider/package/pear.rb b/lib/puppet/provider/package/pear.rb index 8150db24..dbbf8e9c 100644 --- a/lib/puppet/provider/package/pear.rb +++ b/lib/puppet/provider/package/pear.rb @@ -22,23 +22,17 @@ def self.pearlist(hash) begin list = execute(command).split("\n") list = list.map do |set| - if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) # rubocop:disable Lint/AssignmentInCondition - channel = match[1].downcase + %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) { |m| channel = m[1].downcase } + + if hash[:justme] && set =~ %r{^#{hash[:justme]}} + pearhash = pearsplit(set, channel) + pearhash[:provider] = :pear + pearhash + elsif (pearhash = pearsplit(set, channel)) + pearhash[:provider] = :pear + pearhash end - - if hash[:justme] - if set =~ %r{^#{hash[:justme]}} - pearhash = pearsplit(set, channel) - pearhash[:provider] = :pear - pearhash - end - else - if pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition - pearhash[:provider] = :pear - pearhash - end - end - end.reject { |p| p.nil? } + end.compact rescue Puppet::ExecutionFailure => detail raise Puppet::Error, format('Could not list pears: %s', detail) @@ -87,12 +81,10 @@ def install(useversion = true) command << if @resource[:source] @resource[:source] + elsif (!@resource.should(:ensure).is_a? Symbol) && useversion + "#{@resource[:name]}-#{@resource.should(:ensure)}" else - if (!@resource.should(:ensure).is_a? Symbol) && useversion - "#{@resource[:name]}-#{@resource.should(:ensure)}" - else - @resource[:name] - end + @resource[:name] end pearcmd(*command) diff --git a/lib/puppet/provider/package/pecl.rb b/lib/puppet/provider/package/pecl.rb index bb4de994..716baac9 100644 --- a/lib/puppet/provider/package/pecl.rb +++ b/lib/puppet/provider/package/pecl.rb @@ -19,20 +19,14 @@ def self.pecllist(hash) begin list = execute(command).split("\n").map do |set| - if hash[:justme] - if %r{^#{hash[:justme]}$}i.match(set) - if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition - peclhash[:provider] = :peclcmd - peclhash - end - end - else - if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition - peclhash[:provider] = :peclcmd - peclhash - end + if hash[:justme] && %r{^#{hash[:justme]}$}i =~ set && (peclhash = peclsplit(set)) + peclhash[:provider] = :peclcmd + peclhash + elsif (peclhash = peclsplit(set)) + peclhash[:provider] = :peclcmd + peclhash end - end.reject { |p| p.nil? } + end.compact rescue Puppet::ExecutionFailure => detail raise Puppet::Error, format('Could not list pecls: %s', detail) end @@ -79,13 +73,11 @@ def install(useversion = true) if @resource[:source] command << @resource[:source] + elsif (!@resource.should(:ensure).is_a? Symbol) && useversion + command << '-f' + command << "#{peclname}-#{@resource.should(:ensure)}" else - if (!@resource.should(:ensure).is_a? Symbol) && useversion - command << '-f' - command << "#{peclname}-#{@resource.should(:ensure)}" - else - command << peclname - end + command << peclname end if pipe == @resource[:pipe]