Module: Authem::Controller::ClassMethods

Defined in:
lib/authem/controller.rb

Instance Method Summary collapse

Instance Method Details

#authem_for(role_name, **options) ⇒ Object



33
34
35
36
# File 'lib/authem/controller.rb', line 33

def authem_for(role_name, **options)
  include SessionManagementMethods
  Authem::Role.new(self, role_name, options).setup!
end

#authem_role_for(record) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/authem/controller.rb', line 38

def authem_role_for(record)
  fail ArgumentError if record.nil?

  matches = authem_roles.select{ |role| record.class == role.klass }

  fail UnknownRoleError.build(record) if matches.empty?
  fail AmbigousRoleError.build(record, matches) unless matches.one?

  matches.first.name
end