Sha256: 8e2b7df314420d2aae41c1f31d3fb2a801aeade7fcbafacfe61bc43118767a92

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

require 'cantango/permit_engine/util'

module CanTango
  class Ability
    autoload_modules :Scope, :Cache
    autoload_modules :MasqueradeHelpers, :PermitHelpers, :PermissionHelpers
    autoload_modules :UserHelpers, :RoleHelpers, :CacheHelpers

    include CanCan::Ability

    attr_reader :options, :subject, :session, :candidate

    # Equivalent to a CanCan Ability#initialize call
    # which executes all the permission logic
    def initialize candidate, options = {}
      raise "Candidate must be something!" if !candidate
      @candidate, @options = candidate, options
      @session = options[:session] || {} # seperate session cache for each type of user?

      return if cached_rules?

      clear_rules!
      permit_rules
      execute_engines!

      cache_rules! if caching_on?
    end

    include CanTango::PermitEngine::Util

    def permit_rules
    end

    def clear_rules!
      @rules = []
    end

    def execute_engines!
      each_engine {|engine| engine.new(self).execute! if engine  }
    end

    def each_engine &block
      engines.execution_order.each do |name| 
        
        yield engines.registered[name] if engines.active? name
      end
    end

    def engines
      CanTango.config.engines
    end

    def subject
      return candidate.active_user if masquerade_user?
      return candidate.active_account if masquerade_account?
      candidate
    end

    def config
      CanTango.config
    end

    include CacheHelpers
    include MasqueradeHelpers
    include PermissionHelpers
    include PermitHelpers
    include UserHelpers
    include RoleHelpers
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cantango-0.8.9.5 lib/cantango/ability.rb
cantango-0.8.9.4 lib/cantango/ability.rb
cantango-0.8.9.3 lib/cantango/ability.rb
cantango-0.8.9.2 lib/cantango/ability.rb
cantango-0.8.9.1 lib/cantango/ability.rb
cantango-0.8.9 lib/cantango/ability.rb
cantango-0.8.8.1 lib/cantango/ability.rb
cantango-0.8.8 lib/cantango/ability.rb
cantango-0.8.7 lib/cantango/ability.rb