module Bali::Statics::Authorizer::HelperFunctions
Public Instance Methods
check(term, obj, arg1, arg2, arg3)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 37 def check(term, obj, arg1, arg2, arg3) # try to infer current user if only passing one arg if arg2.nil? && arg3.nil? && obj.respond_to?(:current_user) arg2 = arg1 arg1 = obj.current_user elsif arg3.nil? && obj.respond_to?(:current_user) arg3 = arg2 arg2 = arg1 arg1 = obj.current_user end arg3 = HelperFunctions.determine_model_class! obj, arg1, arg2, arg3 actor = HelperFunctions.find_actor(arg1, arg2, arg3) operation = HelperFunctions.find_operation(arg1, arg2, arg3) record = HelperFunctions.find_record(arg1, arg2, arg3) Bali::Judge.check(term, actor, operation, record) end
determine_model_class!(obj, arg1, arg2, arg3)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 29 def determine_model_class!(obj, arg1, arg2, arg3) if arg2.nil? && arg3.nil? && !obj.respond_to?(:model_class) raise Bali::Error, "Cannot perform checking when the actor is not known" end arg3 = obj.model_class if (arg2.nil? || arg1.nil?) && arg3.nil? arg3 end
find_actor(actor, operation, record = nil)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 9 def find_actor(actor, operation, record = nil) return actor unless not_true_actor?(actor) end
find_operation(actor, operation, record = nil)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 13 def find_operation(actor, operation, record = nil) not_true_actor?(actor) ? actor : operation end
find_record(actor, operation, record = nil)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 19 def find_record(actor, operation, record = nil) if not_true_actor?(actor) && record.nil? operation elsif actor.is_a?(ActiveRecord::Base) && record.nil? actor.class else record end end
not_true_actor?(actor)
click to toggle source
# File lib/bali/statics/authorizer.rb, line 5 def not_true_actor?(actor) Symbol === actor || String === actor end