Module: BravoGuard::Model::ObjectMethods
- Defined in:
- lib/bravo_guard/model.rb
Overview
ObjectMethods to avoid deprecation warnings on InstanceMethods
Instance Method Summary collapse
-
#allows?(actor, *permissions) ⇒ Boolean
nodoc.
-
#anon_permissions ⇒ Object
nodoc.
-
#check_anon_permissions!(permission) ⇒ Object
auto-reject anons.
-
#no! ⇒ Object
shorthand for ‘return false’.
-
#permission_name(permission) ⇒ Object
nodoc.
-
#yes! ⇒ Object
see no!().
Instance Method Details
#allows?(actor, *permissions) ⇒ Boolean
nodoc
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bravo_guard/model.rb', line 46 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 |
#anon_permissions ⇒ Object
nodoc
65 66 67 |
# File 'lib/bravo_guard/model.rb', line 65 def [] end |
#check_anon_permissions!(permission) ⇒ Object
auto-reject anons
71 72 73 74 |
# File 'lib/bravo_guard/model.rb', line 71 def () return unless actor.nil? no! unless .include?() end |
#no! ⇒ Object
shorthand for ‘return false’. allows?() will catch this and return false
78 79 80 |
# File 'lib/bravo_guard/model.rb', line 78 def no! raise BravoGuard::PermissionDenied end |
#permission_name(permission) ⇒ Object
nodoc
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bravo_guard/model.rb', line 90 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!()
84 85 86 |
# File 'lib/bravo_guard/model.rb', line 84 def yes! raise BravoGuard::PermissionGranted end |