From b473d8827f18cbd2ed33a042d11695fc26f231ef Mon Sep 17 00:00:00 2001 From: Yura Sokolov Date: Tue, 25 May 2010 12:23:39 +0400 Subject: [PATCH] CanDefinition#only_block? --- lib/cancan/ability.rb | 4 ++-- lib/cancan/can_definition.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/cancan/ability.rb b/lib/cancan/ability.rb index 361d10c..ba308dc 100644 --- a/lib/cancan/ability.rb +++ b/lib/cancan/ability.rb @@ -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) diff --git a/lib/cancan/can_definition.rb b/lib/cancan/can_definition.rb index f4a2116..b075f9f 100644 --- a/lib/cancan/can_definition.rb +++ b/lib/cancan/can_definition.rb @@ -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?