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.0.beta.16 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.15 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.14 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.13 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.12 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.11 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.10 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.9 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.8 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.7 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.6 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.4 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.3 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.2 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.beta.1 lib/ddr/auth/abstract_ability.rb
ddr-models-3.0.0.alpha.4 lib/ddr/auth/abstract_ability.rb