Module: Acl9::Helpers

Defined in:
lib/acl9/helpers.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/acl9/helpers.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#show_to(*args, &block) ⇒ Object

Usage:

<% show_to(:owner, :supervisor, :of => :account) do -%>
  <%= 'hello' %>
<%- end -%>


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/acl9/helpers.rb', line 26

def show_to(*args, &block)
  user = eval(Acl9.config[:default_subject_method].to_s)
  return '' if user.nil?

  has_any = false

  if args.last.is_a?(Hash)
    an_obj  = args.pop.values.first
    has_any = args.detect { |role| user.has_role?(role, an_obj) }
  else
    has_any = args.detect { |role| user.has_role?(role) }
  end

  has_any ? yield(:block) : ''
end