lib/critic/controller.rb in critic-0.1.1 vs lib/critic/controller.rb in critic-0.2.0
- old
+ new
@@ -7,11 +7,11 @@
hide_action(:authorize)
hide_action(:authorize_scope)
end
end
- def authorize(resource, action=default_action, policy: policy(resource), with: nil)
+ def authorize(resource, action = default_action, policy: policy(resource), with: nil)
authorizing!
args = [with] if !with.is_a?(Array) && !with.nil?
@authorization = policy.authorize(action, critic, resource, args)
@@ -25,33 +25,29 @@
authorize(resource, *args, **options)
rescue Critic::AuthorizationDenied
false
end
- def authorize_scope(scope, *args, action: nil, policy: policy(scope))
+ def authorize_scope(scope, *args, action: nil, policy: policy(scope), **options)
authorization_action = action || policy.scope
- authorize(scope, authorization_action, *args, policy: policy)
+ authorize(scope, authorization_action, *args, policy: policy, **options)
end
protected
attr_reader :authorization
def authorization_failed!
- raise Critic::AuthorizationDenied, authorization.messages
+ raise Critic::AuthorizationDenied, authorization
end
def authorization_missing!
raise Critic::AuthorizationMissing
end
def verify_authorized
- unless true == @_authorizing
- authorization_missing!
- else
- true
- end
+ (true == @_authorizing) || authorization_missing!
end
def authorizing!
@_authorizing = true
end