Forces the order of valid roles upon sanitized roles in mask_for and sets the bitmaks default value to 0.

This commit is contained in:
James McCarthy 2011-09-05 19:27:24 +01:00 committed by Martin Rehfeld
parent f3d56f1ccf
commit f9343c70c0

View file

@ -19,15 +19,15 @@ module RoleModel
end
def mask_for(*roles)
(roles.map { |role|
sanitized_roles = roles.map { |role|
role.respond_to?(:each) ? role.to_a : role
}.flatten.map { |role|
role.to_sym
} & valid_roles).map { |role|
2**valid_roles.index(role)
}.inject { |sum, bitvalue|
sum + bitvalue
} || 0
}
(valid_roles & sanitized_roles).inject(0) { |sum, role|
sum + 2**valid_roles.index(role)
}
end
protected