Class: RoleAuthorization::Rules::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, options, &block) ⇒ Rule

Returns a new instance of Rule.



10
11
12
13
14
15
16
# File 'lib/role_authorization/rules/rule.rb', line 10

def initialize(role, options, &block)
  @returning = block
  @role = role
  @options = options

  self
end

Instance Attribute Details

#actionObject

for calls to authorized?



8
9
10
# File 'lib/role_authorization/rules/rule.rb', line 8

def action
  @action
end

#controllerObject

for calls to authorized?



8
9
10
# File 'lib/role_authorization/rules/rule.rb', line 8

def controller
  @controller
end

#controller_instanceObject

for calls to authorized?



8
9
10
# File 'lib/role_authorization/rules/rule.rb', line 8

def controller_instance
  @controller_instance
end

#idObject

for calls to authorized?



8
9
10
# File 'lib/role_authorization/rules/rule.rb', line 8

def id
  @id
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/role_authorization/rules/rule.rb', line 4

def options
  @options
end

#returningObject

Returns the value of attribute returning.



5
6
7
# File 'lib/role_authorization/rules/rule.rb', line 5

def returning
  @returning
end

#roleObject

Returns the value of attribute role.



4
5
6
# File 'lib/role_authorization/rules/rule.rb', line 4

def role
  @role
end

Instance Method Details

#authorized?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

def authorized?(*args)
  @controller_instance, @controller, @action, @id = args

  if instance_eval(&returning)
    true
  else
    # need to run an on_fail proc?
    controller_instance.instance_eval(&options[:on_fail]) if options[:on_fail]
    false
  end
end