Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
use Enumerable.all?, s/chomp/strip/, handle nil case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Newland committed Dec 13, 2013
1 parent 93e18f8 commit 9cfc2cb
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/puppet/provider/mysql_grant/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ def exists?
if lines.length > 1
current_grants = grants_for_db(@resource[:database], lines)

if @resource[:grants].sort == current_grants.sort
return false if current_grants.nil?
return true if current_grants == ['ALL PRIVILEGES']

if Array(@resource[:grants]).all? { |g| current_grants.include?(g) }

This comment has been minimized.

Copy link
@wfarr

wfarr Dec 13, 2013

Contributor

Will this flatten as appropriate?

This comment has been minimized.

Copy link
@jnewland

jnewland Dec 13, 2013

Contributor
irb(main):001:0> Array(1)
=> [1]
irb(main):002:0> Array([1])
=> [1]

This comment has been minimized.

Copy link
@wfarr

wfarr Dec 13, 2013

Contributor

true
else
puts current_grants.inspect
puts Array(@resource[:grants]).inspect
false
end
else
Expand All @@ -29,7 +34,11 @@ def exists?

def grants_for_db(db, arr)
matching_grant = arr[1..-1].select { |line| line =~ / `#{db}`\.\* / }.first
matching_grant.match(/^GRANT (.*) ON /)[1].split(",").map { |w| w.chomp }
if matching_grant
matching_grant.match(/^GRANT (.*) ON /)[1].split(",").map { |w| w.strip }
else
nil
end
end

def grants
Expand Down

0 comments on commit 9cfc2cb

Please sign in to comment.