class Rolypoly::RoleGatekeepers
Public Class Methods
new(gatekeepers = [])
click to toggle source
# File lib/rolypoly/role_gatekeepers.rb, line 13 def initialize(gatekeepers = []) @gatekeepers = Array(gatekeepers) end
Public Instance Methods
allow?(role_objects, action, options = {})
click to toggle source
# 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 = {})
click to toggle source
# 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)
click to toggle source
# File lib/rolypoly/role_gatekeepers.rb, line 17 def initialize_copy(other) @gatekeepers = @gatekeepers.map(&:dup) end
public?(action)
click to toggle source
# 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)
click to toggle source
# File lib/rolypoly/role_gatekeepers.rb, line 21 def publicize(*actions) restrict(*actions).to_none end
Private Instance Methods
build_gatekeeper(roles = nil, actions = nil, resource = nil)
click to toggle source
# File lib/rolypoly/role_gatekeepers.rb, line 47 def build_gatekeeper(roles = nil, actions = nil, resource = nil) new_gatekeeper = RoleGatekeeper.new(roles, actions, resource) @gatekeepers << new_gatekeeper new_gatekeeper end