mirror of
https://github.com/Fishwaldo/role_model.git
synced 2025-03-15 11:32:04 +00:00
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:
parent
f3d56f1ccf
commit
f9343c70c0
1 changed files with 6 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue