Class: Rolypoly::RoleGatekeepers

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/rolypoly/role_gatekeepers.rb

Instance Method Summary collapse

Constructor Details

#initialize(gatekeepers = []) ⇒ RoleGatekeepers

Returns a new instance of RoleGatekeepers.



13
14
15
# File 'lib/rolypoly/role_gatekeepers.rb', line 13

def initialize(gatekeepers = [])
  @gatekeepers = Array(gatekeepers)
end

Instance Method Details

#allow?(role_objects, action, options = {}) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/rolypoly/role_gatekeepers.rb', line 25

def allow?(role_objects, action, options = {})
  return true if empty?

  any? { |gatekeeper| gatekeeper.allow?(role_objects, action, options) }
end

#allowed_roles(role_objects, action, options = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/rolypoly/role_gatekeepers.rb', line 31

def allowed_roles(role_objects, action, options = {})
  return [] if empty?

  reduce([]) do |allowed_role_objects, gatekeeper|
    allowed_role_objects | gatekeeper.allowed_roles(role_objects, action, options)
  end
end

#initialize_copy(other) ⇒ Object



17
18
19
# File 'lib/rolypoly/role_gatekeepers.rb', line 17

def initialize_copy(other)
  @gatekeepers = @gatekeepers.map(&:dup)
end

#public?(action) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/rolypoly/role_gatekeepers.rb', line 39

def public?(action)
  return true if empty?

  any? do |gatekeeper|
    gatekeeper.action?(action) && gatekeeper.public?
  end
end

#publicize(*actions) ⇒ Object



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

def publicize(*actions)
  restrict(*actions).to_none
end