Module: Rolify::Finders

Defined in:
lib/rolify/finders.rb

Instance Method Summary collapse

Instance Method Details

#with_all_roles(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rolify/finders.rb', line 7

def with_all_roles(*args)
  users = []
  args.each do |arg|
    if arg.is_a? Hash
      users_to_add = self.with_role(arg[:name], arg[:resource])
    elsif arg.is_a?(String) || arg.is_a?(Symbol)
      users_to_add = self.with_role(arg)
    else
      raise ArgumentError, "Invalid argument type: only hash or string or symbol allowed"
    end
    users = users_to_add if users.empty?
    users &= users_to_add
    return [] if users.empty?
  end
  users
end

#with_any_role(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rolify/finders.rb', line 24

def with_any_role(*args)
  users = []
  args.each do |arg|
    if arg.is_a? Hash
      users_to_add = self.with_role(arg[:name], arg[:resource])
    elsif arg.is_a?(String) || arg.is_a?(Symbol)
      users_to_add = self.with_role(arg)
    else
      raise ArgumentError, "Invalid argument type: only hash or string or symbol allowed"
    end
    users += users_to_add
  end
  users.uniq
end

#with_role(role_name, resource = nil) ⇒ Object



3
4
5
# File 'lib/rolify/finders.rb', line 3

def with_role(role_name, resource = nil)
  self.adapter.scope(self, :name => role_name, :resource => resource)
end