Sha256: 17085ed1cc9cbbbef421bcbb549ec5ed4d436d19382c1f02169fef5ebedf3a4e

Contents?: true

Size: 799 Bytes

Versions: 13

Compression:

Stored size: 799 Bytes

Contents

module Aegis
  class PermissionEvaluator

	def initialize(role)
	  @role = role
	end

	def evaluate(permissions, rule_args)
	  @result = @role.allow_by_default?
	  permissions.each do |permission|
		instance_exec(*rule_args, &permission)
	  end
	  @result
	end

	def allow(*role_name_or_names, &block)
	  rule_encountered(role_name_or_names, true, &block)
	end

	def deny(*role_name_or_names, &block)
	  rule_encountered(role_name_or_names, false, &block)
	end

	def rule_encountered(role_name_or_names, is_allow, &block)
	  role_names = Array(role_name_or_names)
	  if role_names.include?(@role.name) || role_names.include?(Aegis::Constants::EVERYONE_ROLE_NAME)
		@result = (block ? block.call : true) 
		@result = !@result unless is_allow
	  end
	end

  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
makandra-aegis-1.1.1 lib/aegis/permission_evaluator.rb
makandra-aegis-1.1.2 lib/aegis/permission_evaluator.rb
aegis-1.1.8 lib/aegis/permission_evaluator.rb
thelinuxlich-aegis-1.1.9 lib/aegis/permission_evaluator.rb
thelinuxlich-aegis-1.1.8 lib/aegis/permission_evaluator.rb
thelinuxlich-aegis-1.1.7 lib/aegis/permission_evaluator.rb
aegis-1.1.7 lib/aegis/permission_evaluator.rb
bmaland-aegis-1.1.6 lib/aegis/permission_evaluator.rb
aegis-1.1.6 lib/aegis/permission_evaluator.rb
aegis-1.1.5 lib/aegis/permission_evaluator.rb
bmaland-aegis-1.1.5 lib/aegis/permission_evaluator.rb
aegis-1.1.4 lib/aegis/permission_evaluator.rb
aegis-1.1.3 lib/aegis/permission_evaluator.rb