Class: Rolypoly::RoleGatekeepers
- Inherits:
-
Object
- Object
- Rolypoly::RoleGatekeepers
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rolypoly/role_gatekeepers.rb
Instance Method Summary collapse
- #allow?(role_objects, action, options = {}) ⇒ Boolean
- #allowed_roles(role_objects, action, options = {}) ⇒ Object
-
#initialize(gatekeepers = []) ⇒ RoleGatekeepers
constructor
A new instance of RoleGatekeepers.
- #initialize_copy(other) ⇒ Object
- #public?(action) ⇒ Boolean
- #publicize(*actions) ⇒ Object
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
25 26 27 28 29 |
# File 'lib/rolypoly/role_gatekeepers.rb', line 25 def allow?(role_objects, action, = {}) return true if empty? any? { |gatekeeper| gatekeeper.allow?(role_objects, action, ) } 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, = {}) return [] if empty? reduce([]) do |allowed_role_objects, gatekeeper| allowed_role_objects | gatekeeper.allowed_roles(role_objects, action, ) 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
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 |