Module: Aclatraz::Guard::ClassMethods

Defined in:
lib/aclatraz/guard.rb

Instance Method Summary collapse

Instance Method Details

#acl_guard?Boolean

:nodoc:

Returns:

  • (Boolean)


9
10
11
# File 'lib/aclatraz/guard.rb', line 9

def acl_guard? # :nodoc:
  true
end

#suspects(suspect = nil, &block) ⇒ Object Also known as: access_control

Define access controll list for current class.

Examples

suspects :foo do # foo method result will be treated as suspect
  deny all 
  allow :admin

  on :create do 
    allow :manager
    allow :manager_of => ClassName 
  end

  on :edit do
    # only @object_name instance variable owner is allowed to edit it. 
    allow :owner_of => "object_name" 
  end 
end 

# When called second time don't have to specify suspected object.  
suspects do 
  allow :manager
end


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

def suspects(suspect=nil, &block)
  if acl = Aclatraz.acl[name]
    acl.suspect = suspect if suspect
    acl.evaluate(&block)
  elsif superclass.respond_to?(:acl_guard?) && acl = Aclatraz.acl[superclass.name]
    Aclatraz.acl[name] = acl.clone(&block)
  else
    Aclatraz.acl[name] = Aclatraz::ACL.new(suspect, &block)
  end
end