Module: BravoGuard::Model::InstanceMethods
- Defined in:
- lib/bravo_guard/model.rb
Overview
nodoc
Instance Method Summary collapse
-
#allows?(actor, *permissions) ⇒ Boolean
nodoc.
-
#no! ⇒ Object
shorthand for ‘return false’.
-
#permission_name(permission) ⇒ Object
nodoc.
-
#yes! ⇒ Object
see no!().
Instance Method Details
#allows?(actor, *permissions) ⇒ Boolean
nodoc
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bravo_guard/model.rb', line 45 def allows?(actor, *) begin = .join('_') method_name = [:allows, ()].join('_') + '?' self.actor = actor send method_name rescue BravoGuard::PermissionDenied return false rescue BravoGuard::PermissionGranted return true ensure self.actor = nil end end |
#no! ⇒ Object
shorthand for ‘return false’. allows?() will catch this and return false
63 64 65 |
# File 'lib/bravo_guard/model.rb', line 63 def no! raise BravoGuard::PermissionDenied end |
#permission_name(permission) ⇒ Object
nodoc
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bravo_guard/model.rb', line 75 def () case when 'new' then :create when 'edit' then :update when 'delete' then :destroy when 'show' then :read when 'index' then :list else .to_s.to_sym end end |
#yes! ⇒ Object
see no!()
69 70 71 |
# File 'lib/bravo_guard/model.rb', line 69 def yes! raise BravoGuard::PermissionGranted end |