Class: GenericAuth::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/generic_auth/rules.rb

Class Method Summary collapse

Class Method Details

.context(&block) ⇒ Object



31
32
33
34
# File 'lib/generic_auth/rules.rb', line 31

def self.context &block
	raise 'Context must be declared inside an activity' if @activity.nil?
	Engine.instance.add_context @role, @activity, &block if block_given?
end

.define(&block) ⇒ Object



7
8
9
# File 'lib/generic_auth/rules.rb', line 7

def self.define &block
	instance_eval(&block)
end

.includes(role) ⇒ Object



36
37
38
39
40
41
# File 'lib/generic_auth/rules.rb', line 36

def self.includes role
	activities = Engine.instance.activities(role)
	activities.each do |activity|
		Engine.instance.add_activity(@role, activity)
	end
end

.permitted_to(activities, options = {}, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/generic_auth/rules.rb', line 17

def self.permitted_to activities, options = {}, &block
	activities = [activities] unless activities.is_a?(Array)
	activities.each do |activity|
		Engine.instance.add_activity(@role, activity)
		@activity = activity
		instance_eval(&block) if block_given?
		unless @wrapped.include?(options[:on])
			Engine.instance.wrap_class(options[:on]) 
			@wrapped << options[:on]
		end
	end
	@activity = nil
end

.role(role, &block) ⇒ Object



11
12
13
14
15
# File 'lib/generic_auth/rules.rb', line 11

def self.role role, &block
	Engine.instance.add_role(role)
	@role = role
	yield
end