Module: Authem::Controller::ClassMethods

Defined in:
lib/authem/controller.rb

Instance Method Summary collapse

Instance Method Details

#authem_for(role_name, options = {}) ⇒ Object



31
32
33
34
# File 'lib/authem/controller.rb', line 31

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

#authem_role_for(record) ⇒ Object



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

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