Class: Grant::Grantor
Instance Method Summary collapse
- #authorize!(model, user = Grant::User.current_user) ⇒ Object
- #authorized?(model, user = Grant::User.current_user) ⇒ Boolean
-
#initialize(action, &callback) ⇒ Grantor
constructor
A new instance of Grantor.
Methods included from Status
disable_grant, do_as, enable_grant, grant_disabled?, grant_enabled?, switch_to_monothread, switch_to_multithread, with_grant, without_grant
Methods included from Status::MonoThread
Constructor Details
#initialize(action, &callback) ⇒ Grantor
Returns a new instance of Grantor.
8 9 10 11 |
# File 'lib/grant/grantor.rb', line 8 def initialize(action, &callback) @action = action @callback = callback end |
Instance Method Details
#authorize!(model, user = Grant::User.current_user) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/grant/grantor.rb', line 13 def (model, user=Grant::User.current_user) unless grant_disabled? without_grant do raise Grant::Error.new(user, @action, model) unless @callback.call(user, model, @action) end end end |
#authorized?(model, user = Grant::User.current_user) ⇒ Boolean
21 22 23 24 25 |
# File 'lib/grant/grantor.rb', line 21 def (model, user=Grant::User.current_user) without_grant do @callback.call(user, model, @action) end end |