Sha256: 63b767d7d838e9c381dd046ed2b941804ba89ed3c9e76a6282602af48aa61b5f

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

require 'cantango/permit_engine/util'

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

    include CanCan::Ability

    attr_reader :options, :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

      clear_rules!
      permit_rules

      execute_engines! if engines_on?
    end

    include CanTango::PermitEngine::Util

    def cached?
      false
    end

    def permit_rules
    end

    def clear_rules!
      @rules ||= default_rules
    end

    def session
      @session = options[:session] || {} # seperate session cache for each type of user?
    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 EngineHelpers
    include CacheHelpers
    include MasqueradeHelpers
    include PermissionHelpers
    include PermitHelpers
    include UserHelpers
    include RoleHelpers

    protected

    def default_rules
      []
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
cantango-0.9.4.7 lib/cantango/ability.rb
cantango-0.9.4.6 lib/cantango/ability.rb
cantango-0.9.4.5 lib/cantango/ability.rb
cantango-0.9.4.3 lib/cantango/ability.rb
cantango-0.9.4.2 lib/cantango/ability.rb
cantango-0.9.4.1 lib/cantango/ability.rb
cantango-0.9.4 lib/cantango/ability.rb