lib/cancannible/grantee.rb in cancannible-1.0.1 vs lib/cancannible/grantee.rb in cancannible-2.0.0

- old
+ new

@@ -33,40 +33,43 @@ proxy_association.owner.instance_variable_set :@abilities, nil # invalidate the owner's ability collection permission end end - end module ClassMethods - # Command: configures the set of associations (array of symbols) from which permissions should be inherited def inherit_permissions_from(*relations) self.inheritable_permissions = relations end - end # Returns the Ability set for the owner. # Set +refresh+ to true to force a reload of permissions. def abilities(refresh = false) @abilities = if refresh nil elsif Cancannible.get_cached_abilities.respond_to?(:call) - Cancannible.get_cached_abilities.call(self) + result = Cancannible.get_cached_abilities.call(self) + if result + # performs a crude compatibility check + rules_size = result.send(:rules).size rescue nil + rules_index_size = (result.instance_variable_get(:@rules_index) || []).size + result if !rules_size.nil? && rules_index_size == rules_size + end end return @abilities if @abilities @abilities ||= if ability_class = ('Ability'.constantize rescue nil) unless ability_class.included_modules.include?(Cancannible::PreloadAdapter) ability_class.send :include, Cancannible::PreloadAdapter end ability_class.new(self) end - Cancannible.store_cached_abilities.call(self,@abilities) if Cancannible.store_cached_abilities.respond_to?(:call) + Cancannible.store_cached_abilities.call(self, @abilities) if Cancannible.store_cached_abilities.respond_to?(:call) @abilities end # Returns the collection of inherited permission records def inherited_permissions @@ -96,14 +99,12 @@ # Command: prohibit the permission to do +ability+ on +resource+ def cannot(ability, resource) permissions << [ability, resource, false] end - end - module Cancannible # This module is automatically included into all controllers. # It overrides some CanCan ControllerAdditions module ControllerAdditions # Returns abilities cached in the current_user model. @@ -113,10 +114,9 @@ ability_class.new(current_user) end end end end - if defined? ActionController::Base ActionController::Base.class_eval do include Cancannible::ControllerAdditions end