using instance_exec to change scope of can blocks to instance of ability, this is a bit ugly so I may end up using methods instead

This commit is contained in:
Ryan Bates
2009-11-16 16:24:36 -08:00
parent be1892cca8
commit c663effc06
4 changed files with 32 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
module CanCan
module Ability
attr_accessor :user
def self.included(base)
base.extend ClassMethods
base.alias_action :index, :show, :to => :read
@@ -18,7 +20,7 @@ module CanCan
block_args << action if can_action == :manage
block_args << (target.class == Class ? target : target.class) if can_target == :all
block_args << (target.class == Class ? nil : target)
return can_block.call(*block_args)
return instance_exec(*block_args, &can_block)
end
end
end
@@ -48,6 +50,12 @@ module CanCan
target = args.pop[:to]
@aliased_actions[target] = args
end
def for_user(user)
ability = new
ability.user = user
ability
end
end
end
end