Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rubocop fixes #240

Merged
merged 19 commits into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/puppet/parser/functions/ensure_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ module Puppet::Parser::Functions
Will return:
['p.a', 'p.b', 'p.c']
EOS
) do |arguments|

raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' +
) do |arguments|
raise(Puppet::ParseError, 'ensure_prefix(): Wrong number of arguments ' \
"given (#{arguments.size} for 2)") if arguments.size < 2

enumerable = arguments[0]

unless enumerable.is_a?(Array) or enumerable.is_a?(Hash)
unless enumerable.is_a?(Array) || enumerable.is_a?(Hash)
raise Puppet::ParseError, "ensure_prefix(): expected first argument to be an Array or a Hash, got #{enumerable.inspect}"
end

Expand All @@ -38,18 +37,18 @@ module Puppet::Parser::Functions
end
end

if enumerable.is_a?(Array)
# Turn everything into string same as join would do ...
result = enumerable.collect do |i|
i = i.to_s
prefix && !i.start_with?(prefix) ? prefix + i : i
end
else
result = Hash[enumerable.map do |k,v|
k = k.to_s
[ prefix && !k.start_with?(prefix) ? prefix + k : k, v ]
end]
end
result = if enumerable.is_a?(Array)
# Turn everything into string same as join would do ...
enumerable.map do |i|
i = i.to_s
prefix && !i.start_with?(prefix) ? prefix + i : i
end
else
Hash[enumerable.map do |k, v|
k = k.to_s
[prefix && !k.start_with?(prefix) ? prefix + k : k, v]
end]
end

return result
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/to_hash_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ module Puppet::Parser::Functions
'foo: b' => {'key' => 'b', 'value' => 2}
}
EOS
) do |arguments|

) do |arguments|
hash, id = arguments
id = (id.nil? ? '' : "#{id}: ")

Expand Down
93 changes: 40 additions & 53 deletions lib/puppet/provider/package/pear.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def self.pearlist(hash)

begin
list = execute(command).split("\n")
list = list.collect do |set|
if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set)
list = list.map do |set|
if match = %r{INSTALLED PACKAGES, CHANNEL (.*):}i.match(set) # rubocop:disable Lint/AssignmentInCondition
channel = match[1].downcase
end

Expand All @@ -31,76 +31,69 @@ def self.pearlist(hash)
pearhash = pearsplit(set, channel)
pearhash[:provider] = :pear
pearhash
else
nil
end
else
if pearhash = pearsplit(set, channel)
if pearhash = pearsplit(set, channel) # rubocop:disable Lint/AssignmentInCondition
pearhash[:provider] = :pear
pearhash
else
nil
end
end
end.reject { |p| p.nil? }

rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, 'Could not list pears: %s' % detail
raise Puppet::Error, format('Could not list pears: %s', detail)
end

if hash[:justme]
return list.shift
else
return list
end
return list.shift if hash[:justme]
list
end

def self.pearsplit(desc, channel)
desc.strip!

case desc
when %r{^$} then return nil
when %r{^INSTALLED}i then return nil
when %r{no packages installed}i then return nil
when %r{^=} then return nil
when %r{^PACKAGE}i then return nil
when %r{^(\S+)\s+(\S+)\s+(\S+)\s*$} then
name = $1
version = $2
state = $3
return {
name: "#{channel}/#{name}",
ensure: state == 'stable' ? version : state
}
when %r{^$} then return nil
when %r{^INSTALLED}i then return nil
when %r{no packages installed}i then return nil
when %r{^=} then return nil
when %r{^PACKAGE}i then return nil
when %r{^(\S+)\s+(\S+)\s+(\S+)\s*$} then
name = Regexp.last_match(1)
version = Regexp.last_match(2)
state = Regexp.last_match(3)
return {
name: "#{channel}/#{name}",
ensure: state == 'stable' ? version : state
}
else
Puppet.debug "Could not match '%s'" % desc
Puppet.debug format("Could not match '%s'", desc)
nil
end
end

def self.instances
pearlist(local: true).collect do |hash|
pearlist(local: true).map do |hash|
new(hash)
end
end

def install(useversion = true)
command = ['-D', 'auto_discover=1', 'upgrade']
if @resource[:install_options]
command << @resource[:install_options]
else
command << '--alldeps'
end

if source = @resource[:source]
command << source
else
if ([email protected](:ensure).is_a? Symbol) and useversion
command << "#{@resource[:name]}-#{@resource.should(:ensure)}"
else
command << @resource[:name]
end
end
command << if @resource[:install_options]
@resource[:install_options]
else
'--alldeps'
end

command << if @resource[:source]
@resource[:source]
else
if ([email protected](:ensure).is_a? Symbol) && useversion
"#{@resource[:name]}-#{@resource.should(:ensure)}"
else
@resource[:name]
end
end

pearcmd(*command)
end
Expand All @@ -109,12 +102,10 @@ def latest
# This always gets the latest version available.
version = ''
command = [command(:pearcmd), 'remote-info', @resource[:name]]
list = execute(command).split("\n")
list = list.collect do |set|
if set =~ %r{^Latest}
version = set.split[1]
end
execute(command).each_line do |set|
version = set.split[1] if set =~ %r{^Latest}
end

version
end

Expand All @@ -124,14 +115,10 @@ def query

def uninstall
output = pearcmd 'uninstall', @resource[:name]
if output =~ %r{^uninstall ok}
else
raise Puppet::Error, output
end
raise Puppet::Error, output unless output =~ %r{^uninstall ok}
end

def update
install(false)
end

end
62 changes: 24 additions & 38 deletions lib/puppet/provider/package/pecl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,37 @@
has_feature :upgradeable

case Facter.value(:operatingsystem)
when 'Solaris'
commands peclcmd: '/opt/coolstack/php5/bin/pecl'
else
commands peclcmd: 'pecl'
when 'Solaris'
commands peclcmd: '/opt/coolstack/php5/bin/pecl'
else
commands peclcmd: 'pecl'
end

def self.pecllist(hash)
command = [command(:peclcmd), 'list']

begin
list = execute(command).split("\n").collect do |set|
list = execute(command).split("\n").map do |set|
if hash[:justme]
if %r{^#{hash[:justme]}$}i.match(set)
if peclhash = peclsplit(set)
if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition
peclhash[:provider] = :peclcmd
peclhash
else
nil
end
else
nil
end
else
if peclhash = peclsplit(set)
if peclhash = peclsplit(set) # rubocop:disable Lint/AssignmentInCondition
peclhash[:provider] = :peclcmd
peclhash
else
nil
end
end
end.reject { |p| p.nil? }
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, 'Could not list pecls: %s' % detail
raise Puppet::Error, format('Could not list pecls: %s', detail)
end

if hash[:justme]
return list.shift
else
return list
end
return list.shift if hash[:justme]
list
end

def self.peclsplit(desc)
Expand All @@ -58,23 +49,23 @@ def self.peclsplit(desc)
when %r{No packages installed from channel}i then return nil
when %r{^=} then return nil
when %r{^PACKAGE} then return nil
when %r{\[1m} then return nil # Newer versions of PEAR use colorized output
when %r{\[1m} then return nil # Newer versions of PEAR use colorized output
when %r{^(\S+)\s+(\S+)\s+\S+} then
name = $1
version = $2
name = Regexp.last_match(1)
version = Regexp.last_match(2)

return {
name: "pecl-#{name.downcase}",
ensure: version
}
else
Puppet.warning 'Could not match %s' % desc
Puppet.warning format('Could not match %s', desc)
nil
end
end

def self.instances
pecllist(local: true).collect do |hash|
pecllist(local: true).map do |hash|
new(hash)
end
end
Expand All @@ -86,20 +77,20 @@ def peclname
def install(useversion = true)
command = ['upgrade']

if source = @resource[:source]
command << source
if @resource[:source]
command << @resource[:source]
else
if ([email protected](:ensure).is_a? Symbol) and useversion
if ([email protected](:ensure).is_a? Symbol) && useversion
command << '-f'
command << "#{peclname}-#{@resource.should(:ensure)}"
else
command << peclname
end
end

if pipe = @resource[:pipe]
command << '<<<'
command << @resource[:pipe]
if pipe == @resource[:pipe]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak Oops. This was clearly not right.

command << '<<<'
command << @resource[:pipe]
end

peclcmd(*command)
Expand All @@ -108,10 +99,8 @@ def install(useversion = true)
def latest
version = ''
command = [command(:peclcmd), 'remote-info', peclname]
list = execute(command).each_line do |set|
if set =~ %r{^Latest}
version = set.split[1]
end
execute(command).each_line do |set|
version = set.split[1] if set =~ %r{^Latest}
end

version
Expand All @@ -123,10 +112,7 @@ def query

def uninstall
output = peclcmd 'uninstall', peclname
if output =~ %r{^uninstall ok}
else
raise Puppet::Error, output
end
raise Puppet::Error, output unless output =~ %r{^uninstall ok}
end

def update
Expand Down