merging with master and resolving a couple conflicts
This commit is contained in:
@@ -267,6 +267,15 @@ module CanCan
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Accepts a hash of aliased actions and returns an array of actions which match.
|
||||
# This should be called before "matches?" and other checking methods since they
|
||||
# rely on the actions to be expanded.
|
||||
def expand_actions(actions)
|
||||
actions.map do |action|
|
||||
aliased_actions[action] ? [action, *expand_actions(aliased_actions[action])] : action
|
||||
end.flatten
|
||||
end
|
||||
|
||||
def can_definitions
|
||||
@can_definitions ||= []
|
||||
@@ -275,7 +284,7 @@ module CanCan
|
||||
def matching_can_definition(action, subject)
|
||||
if block_given?
|
||||
can_definitions.reverse.each do |can_definition|
|
||||
can_definition.expand_actions(aliased_actions)
|
||||
can_definition.expanded_actions = expand_actions(can_definition.actions)
|
||||
if can_definition.matches? action, subject
|
||||
yield can_definition
|
||||
break if can_definition.definitive?
|
||||
|
||||
@@ -5,7 +5,10 @@ module CanCan
|
||||
class CanDefinition # :nodoc:
|
||||
attr_reader :conditions, :block, :base_behavior, :definitive
|
||||
include ActiveSupport::Inflector
|
||||
|
||||
attr_reader :block
|
||||
attr_reader :actions
|
||||
attr_writer :expanded_actions
|
||||
|
||||
# The first argument when initializing is the base_behavior which is a true/false
|
||||
# value. True for "can" and false for "cannot". The next two arguments are the action
|
||||
# and subject respectively (such as :read, @project). The third argument is a hash
|
||||
@@ -18,15 +21,6 @@ module CanCan
|
||||
@block = block
|
||||
end
|
||||
|
||||
# Accepts a hash of aliased actions and returns an array of actions which match.
|
||||
# This should be called before "matches?" and other checking methods since they
|
||||
# rely on the actions to be expanded.
|
||||
def expand_actions(aliased_actions)
|
||||
@expanded_actions = @actions.map do |action|
|
||||
aliased_actions[action] ? [action, *aliased_actions[action]] : action
|
||||
end.flatten
|
||||
end
|
||||
|
||||
def matches?(action, subject)
|
||||
matches_action?(action) && matches_subject?(subject)
|
||||
end
|
||||
@@ -54,7 +48,7 @@ module CanCan
|
||||
def definitive?
|
||||
conditions_empty? && @block.nil?
|
||||
end
|
||||
|
||||
|
||||
def only_block?
|
||||
conditions_empty? && !@block.nil?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user