Sha256: 8e0e4d7375cb8a76ed67176136ce825ac42e209dc3c1670b583db99267efc3a0

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# This class is responsible for executing a set of similar Permits and collecting their rule results into one rule collection
# which can be cached under some key and later reused
#
module CanTango
  class UserAcEngine < Engine
    class Executor
      include CanTango::Ability::CacheHelpers

      attr_reader :ability, :permits

      delegate :session, :user, :subject, :cached?, :to => :ability

      def initialize ability, permit_type, permissions
        @ability        = ability
        @permissions    = permissions
      end

      def cache_key
        :user_ac
      end

      def rules
        @rules ||= []
      end

      def clear_rules!
        @rules ||= []
      end

      def cache
        @cache ||= CanTango::Ability::Cache.new self, :cache_key => cache_key, :key_method_names => key_method_names
      end

      def execute!
        return if cached_rules?

        clear_rules!
        permit_rules

        cache_rules!
      end

      def permit_rules
        # TODO: somehow type specific caching of result of permits!
        permits.each do |permit|
          CanTango.config.permits.was_executed(permit, ability) if CanTango.debug?
          break if permit.execute == :break
        end
      end

      protected

      def key_method_names
        [:permissions_hash]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.9.3.2 lib/cantango/user_ac_engine/executor.rb