Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
CanDefinition#only_block?
Browse files Browse the repository at this point in the history
  • Loading branch information
Yura Sokolov committed May 25, 2010
1 parent bcab8d6 commit b473d88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cancan/ability.rb
Expand Up @@ -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|
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/cancan/can_definition.rb
Expand Up @@ -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?
Expand Down

0 comments on commit b473d88

Please sign in to comment.