Sha256: 664e1cfd6355330492838bed6b0bf681e0ab46335bed9c5711647d2aa7b9256c

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

module CanTango
  class PermitEngine < Engine
    autoload_modules :Builder, :Compatibility, :Executor
    autoload_modules :Factory, :Finder, :Loaders, :Util, :RoleMatcher

    def initialize ability
      super
    end

    def execute!
      if CanTango.config.debug.on?
        puts "Permit Engine executing..." 
        puts "No permits found!" if permits.empty?
      end
      # CanTango.config.permits.clear_executed! # should there be an option clear before each execution?
      permits.each do |permit|
        CanTango.config.permits.was_executed(permit, ability) if CanTango.config.debug.on?
        break if permit.execute == :break
      end
    end

    # by default, only execute permits for which the user
    # has a role or a role group
    # also execute any permit marked as special
    def permits
      @permits ||= permit_factory.build!
    end

    def permit_class_names
      @permit_class_names ||= permits.map{|p| p.class.to_s}
    end

    protected

    def permit_factory
      @permit_factory ||= CanTango::PermitEngine::Factory.new ability
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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