Module: LucidUser::Authorization

Included in:
Anonymous, LocalSystem
Defined in:
lib/lucid_user/authorization.rb

Instance Method Summary collapse

Instance Method Details

#authorization_reasonObject



12
13
14
# File 'lib/lucid_user/authorization.rb', line 12

def authorization_reason
  @_isomorfeus_authorization_reason
end

#authorized!(target_class, target_method = nil, props = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/lucid_user/authorization.rb', line 31

def authorized!(target_class, target_method = nil, props = nil)
  class_name = self.class.name
  class_name = class_name.split('>::').last if class_name.start_with?('#<')
  policy_class = Isomorfeus.cached_policy_class("#{class_name}Policy")
  Isomorfeus.raise_error(error_class: LucidPolicy::Exception, message: "#{self}: policy class #{class_name}Policy not found!") unless policy_class
  policy_instance = policy_class.new(self, @_isomorfeus_record_authorization_reason)
  result = policy_instance.authorized!(target_class, target_method, props)
  @_isomorfeus_authorization_reason = policy_instance.reason
  result
end

#authorized?(target_class, target_method = nil, props = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

def authorized?(target_class, target_method = nil, props = nil)
  begin
    class_name = self.class.name
    class_name = class_name.split('>::').last if class_name.start_with?('#<')
    policy_class = Isomorfeus.cached_policy_class("#{class_name}Policy")
  rescue ::NameError
    policy_class = nil
  end
  return false unless policy_class
  policy_instance = policy_class.new(self, @_isomorfeus_record_authorization_reason)
  result = policy_instance.authorized?(target_class, target_method, props)
  @_isomorfeus_authorization_reason = policy_instance.reason
  result
end

#record_authorization_reasonObject



3
4
5
# File 'lib/lucid_user/authorization.rb', line 3

def record_authorization_reason
  @_isomorfeus_record_authorization_reason = true
end

#stop_to_record_authorization_reasonObject



7
8
9
10
# File 'lib/lucid_user/authorization.rb', line 7

def stop_to_record_authorization_reason
  @_isomorfeus_record_authorization_reason = false
  @_isomorfeus_authorization_reason = nil
end