mirror of
https://github.com/Fishwaldo/role_model.git
synced 2025-03-15 11:32:04 +00:00
Replaced use of map { |r| r.to_sym } with the more terse but idomatic map(&:to_sym).
This commit is contained in:
parent
f9343c70c0
commit
3cefbf35da
2 changed files with 5 additions and 9 deletions
|
@ -21,13 +21,9 @@ module RoleModel
|
|||
def mask_for(*roles)
|
||||
sanitized_roles = roles.map { |role|
|
||||
role.respond_to?(:each) ? role.to_a : role
|
||||
}.flatten.map { |role|
|
||||
role.to_sym
|
||||
}
|
||||
}.flatten.map(&:to_sym)
|
||||
|
||||
(valid_roles & sanitized_roles).inject(0) { |sum, role|
|
||||
sum + 2**valid_roles.index(role)
|
||||
}
|
||||
(valid_roles & sanitized_roles).inject(0) { |sum, role| sum + 2**valid_roles.index(role) }
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -40,7 +36,7 @@ module RoleModel
|
|||
#
|
||||
# declare valid roles
|
||||
def roles(*roles)
|
||||
self.valid_roles = roles.flatten.map { |r| r.to_sym }
|
||||
self.valid_roles = roles.flatten.map(&:to_sym)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ module RoleModel
|
|||
# check if ALL of the given roles have been assigned
|
||||
# this method is aliased as #is? and #has_roles?
|
||||
def has_all_roles?(*roles)
|
||||
roles.flatten.map { |r| r.to_sym }.all? { |r| self.roles.include?(r) }
|
||||
roles.flatten.map(&:to_sym).all? { |r| self.roles.include?(r) }
|
||||
end
|
||||
alias_method :is?, :has_all_roles?
|
||||
alias_method :has_roles?, :has_all_roles?
|
||||
|
@ -39,7 +39,7 @@ module RoleModel
|
|||
# check if any (at least ONE) of the given roles have been assigned
|
||||
# this method is aliased as #is_any_of? and #has_role?
|
||||
def has_any_role?(*roles)
|
||||
roles.flatten.map { |r| r.to_sym }.any? { |r| self.roles.include?(r) }
|
||||
roles.flatten.map(&:to_sym).any? { |r| self.roles.include?(r) }
|
||||
end
|
||||
alias_method :is_any_of?, :has_any_role?
|
||||
alias_method :has_role?, :has_any_role?
|
||||
|
|
Loading…
Add table
Reference in a new issue