app/models/concerns/the_role/api/user.rb
# FALSE if object is nil
# If object is a USER - check for youself
# Check for owner field - :user_id
# Check for owner _object_ if owner field is not :user_id
FALSE if object is nil
If object is a USER - check for youself
Check for owner field - :user_id
Check for owner _object_ if owner field is not :user_id
FALSE if object is nil If object is a USER - check for youself Check for owner field - : user_id Check for owner _object_ if owner field is not : user_id
def owner? obj
        return false unless obj
        return true  if admin?
        section_name = obj.class.to_s.tableize
        return true if moderator?(section_name)
        return id == obj.id if obj.is_a?(self.class)
        return id == obj.user_id     if obj.respond_to? :user_id
        return id == obj[:user_id]   if obj[:user_id]
        return id == obj[:user][:id] if obj[:user]
        false
      end
def owner? obj return false unless obj return true if admin? section_name = obj . class . to_s . tableize return true if moderator? ( section_name ) return id == obj . id if obj . is_a? ( self . class ) return id == obj . user_id if obj . respond_to? :user_id return id == obj [ :user_id ] if obj [ :user_id ] return id == obj [ :user ] [ :id ] if obj [ :user ] false end
FALSE if object is nil
If object is a USER - check for youself
Check for owner field - :user_id
Check for owner _object_ if owner field is not :user_id
FALSE if object is nil If object is a USER - check for youself Check for owner field - : user_id Check for owner _object_ if owner field is not : user_id
# obj is User, simple way to define user_id # few ways to define user_id
obj
<not_specific>