def authorize(required = nil, options)
      if through = options[:through]
        name = through.to_s.singularize.to_sym
      else
        name = options[:resource]
      end

      record = instance_variable_get("@#{name}")

      if record.nil? # must be devise scope
        record = send("current_#{name}")
        send "authenticate_#{name}!"
      end

      role_attr = record.class.role_attribute_name
      actual = record.send(role_attr)

      required ||= options[role_attr]
      required = [required] unless Array === required

      # actual roles must have at least
      # one required role (array intersection)
      ((required & actual).size > 0).tap do |res|
        raise Denied.new(role_attr, required, actual) unless res
      end
    end
def authorize(required = nil, options)
      if through = options[:through]
        name = through.to_s.singularize.to_sym
      else
        name = options[:resource]
      end

      record = instance_variable_get("@#{name}")

      if record.nil? # must be devise scope
        record = send("current_#{name}")
        send "authenticate_#{name}!"
      end

      role_attr = record.class.role_attribute_name
      actual = record.send(role_attr)

      required ||= options[role_attr]
      required = [required] unless Array === required

      # actual roles must have at least
      # one required role (array intersection)
      ((required & actual).size > 0).tap do |res|
        raise Denied.new(role_attr, required, actual) unless res
      end
    end
Internal authorize instance method

 @private
 @param [Symbol, String] one or more required roles
 @param [Hash] options authorizer options