Sha256: bed9c391355049bf8ff2cf7ea26d35bb4c272bbfc3ecd7068947516ffb889ef2

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

module Zuul
  module ActionController
    module Evaluators
      class ForTarget
        def for_target(&block)
          return self if @dsl.nil?
          if match?
            @controller.instance_eval do
              yield
            end if block_given?
          end
          self
        end

        def else(&block)
          return self if @dsl.nil?
          if !match?
            @controller.instance_eval do
              yield
            end if block_given?
          end
          self
        end

        def else_for(target, context=nil, force_context=nil, &block)
          return self.class.new(@controller, target, context, force_context, &block)
        end

        protected

        def initialize(controller, target, context=nil, force_context=nil, &block)
          @controller = controller
          @dsl = @controller.acl_dsl
          @target = target
          @context = context
          @force_context = force_context
          for_target &block
        end
      end

      class ForRole < ForTarget
        def match?
          (@dsl.subject.nil? && @target == @dsl.logged_out) || (!@dsl.subject.nil? && (@target == @dsl.logged_in || @dsl.subject.has_role?(@target, @context, @force_context)))
        end
      end

      class ForRoleOrHigher < ForTarget
        def match?
          (@dsl.subject.nil? && @target == @dsl.logged_out) || (!@dsl.subject.nil? && (@target == @dsl.logged_in || @dsl.subject.has_role_or_higher?(@target, @context, @force_context)))
        end
      end
      
      class ForPermission < ForTarget
        def match?
          !@dsl.subject.nil? && @dsl.subject.has_permission?(@target, @context, @force_context)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
zuul-0.2.8 lib/zuul/action_controller/evaluators.rb
zuul-0.2.7 lib/zuul/action_controller/evaluators.rb
zuul-0.2.6 lib/zuul/action_controller/evaluators.rb
zuul-0.2.5 lib/zuul/action_controller/evaluators.rb
zuul-0.2.4 lib/zuul/action_controller/evaluators.rb
zuul-0.2.3 lib/zuul/action_controller/evaluators.rb
zuul-0.2.2 lib/zuul/action_controller/evaluators.rb
zuul-0.2.1 lib/zuul/action_controller/evaluators.rb
zuul-0.2.0 lib/zuul/action_controller/evaluators.rb