supporting arrays, ranges, and nested hashes in ability conditions
This commit is contained in:
@@ -244,15 +244,26 @@ module CanCan
|
||||
if subject.class == Class
|
||||
true
|
||||
else
|
||||
defined_conditions.all? do |name, value|
|
||||
subject.send(name) == value
|
||||
end
|
||||
matches_conditions? subject, defined_conditions
|
||||
end
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def matches_conditions?(subject, defined_conditions)
|
||||
defined_conditions.all? do |name, value|
|
||||
attribute = subject.send(name)
|
||||
if value.kind_of?(Hash)
|
||||
matches_conditions? attribute, value
|
||||
elsif value.kind_of?(Array) || value.kind_of?(Range)
|
||||
value.include? attribute
|
||||
else
|
||||
attribute == value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def includes_action?(actions, action)
|
||||
actions.include?(:manage) || actions.include?(action)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user