Module: Authoritah::Controller::ClassMethods

Defined in:
lib/authoritah.rb

Instance Method Summary collapse

Instance Method Details

#apply_declaration(perm_type, action_identifier, args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/authoritah.rb', line 29

def apply_declaration(perm_type, action_identifier, args)
  options = args.extract_options!
  args.each {|a| options[a] = nil}
  actions = options.delete(action_identifier)
  on_reject = options.delete(:on_reject) || :render_404
  
  raise ":on_reject must be a symbol or a Proc" unless on_reject.is_a?(Symbol) || on_reject.is_a?(Proc)
  
  check_role_selectors(options)

  role_method     = options.to_a.first[0]
  role_predicate  = options.to_a.first[1]
  
  controller_permissions << {
    :type => perm_type,
    :role_method => role_method,
    :role_predicate => role_predicate,
    :actions => actions ? Array(actions) : nil,
    :on_reject => on_reject
  }
end

#forbids(*args) ⇒ Object



25
26
27
# File 'lib/authoritah.rb', line 25

def forbids(*args)
  apply_declaration(:forbid, :from, args)
end

#permits(*args) ⇒ Object



21
22
23
# File 'lib/authoritah.rb', line 21

def permits(*args)
  apply_declaration(:permit, :to, args)
end