Sha256: 39e7cb7cd89bcf11ec7ec715a5f675445226042bc653cb2610b1e88af02eaf00

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module CanTango
  module PermitEngine
    module Builder
      class Base
        attr_accessor :ability

        # creates the factory for the ability
        # note that the ability contains the roles and role groups of the user (or account)
        # @param [Permits::Ability] the ability
        def initialize ability
          @ability = ability
        end

        protected

        # Tries to create a new permit for the given role
        # If no permit Class can be found, it should return nil
        # @param [Symbol] the name
        # @return the permit Class or nil if not found
        def create_permit name
          begin
            permit_clazz(name).new ability
          rescue RuntimeError => e
            #raise "Error instantiating Permit instance for role #{role}, cause #{e}"
            nil
          end
        end

        def permit_clazz name
          finder.new(subject, name).get_permit
        end

        # delegate to ability
        [:options, :role_groups, :roles, :subject, :user, :user_account].each do |name|
          define_method name do
            ability.send(name)
          end
        end

        def available_role_groups
          CanTango.config.role_groups
        end

        def available_roles
          CanTango.config.roles
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permit_engine/builder/base.rb