Module: RailsAuthorize
- Defined in:
- lib/rails_authorize.rb,
lib/rails_authorize/version.rb
Defined Under Namespace
Classes: NotAuthorizedError
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
-
#authorization(target, options = {}) ⇒ Object
Finds authorization class for given target and returns new instance.
-
#authorization_scope(target, options = {}) ⇒ Scope
Retrieves the authorization scope for the given target.
-
#authorize(target, options = {}) ⇒ Object
Throwing an error if the user is not authorized to perform the given action.
-
#authorized_scope(target, options = {}) ⇒ Scope
Throwing an error if the user is not authorized to perform the given action.
Instance Method Details
#authorization(target, options = {}) ⇒ Object
Finds authorization class for given target and returns new instance
18 19 20 21 22 23 |
# File 'lib/rails_authorize.rb', line 18 def (target, ={}) user = [:user] || current_user klass = [:authorization] || "#{target.model_name.name}Authorization".constantize klass.new(user, target, [:context]) end |
#authorization_scope(target, options = {}) ⇒ Scope
Retrieves the authorization scope for the given target
52 53 54 |
# File 'lib/rails_authorize.rb', line 52 def (target, ={}) (target, ).scope end |
#authorize(target, options = {}) ⇒ Object
Throwing an error if the user is not authorized to perform the given action
35 36 37 38 39 40 41 42 |
# File 'lib/rails_authorize.rb', line 35 def (target, ={}) action = .delete(:action) || "#{action_name}?" = (target, ) raise(NotAuthorizedError) unless .public_send(action) target end |
#authorized_scope(target, options = {}) ⇒ Scope
Throwing an error if the user is not authorized to perform the given action
66 67 68 69 70 71 72 73 |
# File 'lib/rails_authorize.rb', line 66 def (target, ={}) action = .delete(:action) || "#{action_name}?" = (target, ) raise(NotAuthorizedError) unless .public_send(action) .scope end |