CanDefinition#only_block?

This commit is contained in:
Yura Sokolov 2010-05-25 12:23:39 +04:00
parent bcab8d6369
commit b473d8827f
2 changed files with 6 additions and 2 deletions

View File

@ -202,7 +202,7 @@ module CanCan
def conditions(action, subject, options = {})
matched = matching_can_definition(action, subject)
unless matched.empty?
if matched.any?{|can_definition| can_definition.conditions_empty? && can_definition.block }
if matched.any?{|can_definition| can_definition.only_block? }
raise Error, "Cannot determine ability conditions from block for #{action.inspect} #{subject.inspect}"
end
matched.map{|can_definition|
@ -258,7 +258,7 @@ module CanCan
def association_joins(action, subject)
can_definitions = matching_can_definition(action, subject)
unless can_definitions.empty?
if can_definitions.any?{|can_definition| can_definition.conditions_empty? && can_definition.block }
if can_definitions.any?{|can_definition| can_definition.only_block? }
raise Error, "Cannot determine association joins from block for #{action.inspect} #{subject.inspect}"
end
collect_association_joins(can_definitions)

View File

@ -54,6 +54,10 @@ module CanCan
def definitive?
conditions_empty? && @block.nil?
end
def only_block?
conditions_empty? && !@block.nil?
end
def conditions_empty?
@conditions == {} || @conditions.nil?