Sha256: 0672150eb465910a02cab3e58548f1f65fadc9d030412bce6d04055a91a5a28f
Contents?: true
Size: 738 Bytes
Versions: 3
Compression:
Stored size: 738 Bytes
Contents
require "action_authorization/version" require "action_authorization/base_policy" require "action_authorization/authorization_failure" require "active_support/core_ext/string/inflections" module ActionAuthorization def self.included(base) base.class_eval do helper_method :policy end end protected def authorize(object, action: action_name, policy_class: nil) if policy(object, policy_class).send("#{action}?") object else raise ActionAuthorization::AuthorizationFailure end end def policy(object, policy_class = nil) (policy_class || policy_class_for(object)).new(current_user, object) end def policy_class_for(object) "#{object.class.name}Policy".constantize end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
action_authorization-0.2.2 | lib/action_authorization.rb |
action_authorization-0.2.1 | lib/action_authorization.rb |
action_authorization-0.2.0 | lib/action_authorization.rb |