Sha256: 72eec5b4b4f7242d645becf762925ecd12cf810f3b57ab942bc4053a63f3cb7a

Contents?: true

Size: 1.01 KB

Versions: 36

Compression:

Stored size: 1.01 KB

Contents

require 'cancancan'

module Ddr::Auth
  # @abstract
  class AbstractAbility
    include CanCan::Ability

    class_attribute :ability_definitions
    self.ability_definitions = []

    # CanCan default aliases:
    #
    #   alias_action :index, :show, :to => :read
    #   alias_action :new, :to => :create
    #   alias_action :edit, :to => :update
    #
    class_attribute :exclude_default_aliases
    self.exclude_default_aliases = false

    attr_reader :auth_context

    delegate :anonymous?, :authenticated?, :user, :groups, :agents, :member_of?,
             :authorized_to_act_as_superuser?,
             to: :auth_context

    def initialize(auth_context)
      @auth_context = auth_context
      if exclude_default_aliases
        clear_aliased_actions
      end
      apply_ability_definitions
    end

    def cache
      @cache ||= {}
    end

    private

    def apply_ability_definitions
      ability_definitions.reduce(self, :apply)
    end

    def apply(ability_def)
      ability_def.call(self)
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ddr-models-3.0.8 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.7 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.6 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.5 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.4 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.3 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.2 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.1 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc6 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc5 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc4 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc3 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc2 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.rc1 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.22 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.21 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.20 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.18 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.17 lib/ddr/auth/abstract_ability.rb