Permalink
Browse files

CanDefinition#only_block?

  • Loading branch information...
1 parent bcab8d6 commit b473d8827f18cbd2ed33a042d11695fc26f231ef Yura Sokolov committed May 25, 2010
Showing with 6 additions and 2 deletions.
  1. +2 −2 lib/cancan/ability.rb
  2. +4 −0 lib/cancan/can_definition.rb
View
4 lib/cancan/ability.rb
@@ -202,7 +202,7 @@ def clear_aliased_actions
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 @@ def sql_conditions(action, subject, options = {})
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
4 lib/cancan/can_definition.rb
@@ -54,6 +54,10 @@ def conditions(options = {})
def definitive?
conditions_empty? && @block.nil?
end
+
+ def only_block?
+ conditions_empty? && !@block.nil?
+ end
def conditions_empty?
@conditions == {} || @conditions.nil?

0 comments on commit b473d88

Please sign in to comment.