Class: Cerbos::Output::ValidationError

Inherits:
Object
  • Object
show all
Defined in:
lib/cerbos/output/validation_error.rb

Overview

An error that occurred while validating the principal or resource attributes against a schema.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messageString (readonly)

The error message.

Returns:

  • (String)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cerbos/output/validation_error.rb', line 6

ValidationError = Output.new_class(:path, :message, :source) do
  # @!attribute [r] path
  #   The path to the attribute that failed validation.
  #
  #   @return [String]

  # @!attribute [r] message
  #   The error message.
  #
  #   @return [String]

  # @!attribute [r] source
  #   The source of the invalid attributes.
  #
  #   @return [:SOURCE_PRINCIPAL, :SOURCE_RESOURCE]

  def self.from_protobuf(validation_error)
    new(
      path: validation_error.path,
      message: validation_error.message,
      source: validation_error.source
    )
  end

  # Check if the principal's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_principal?
    source == :SOURCE_PRINCIPAL
  end

  # Check if the resource's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_resource?
    source == :SOURCE_RESOURCE
  end
end

#pathString (readonly)

The path to the attribute that failed validation.

Returns:

  • (String)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cerbos/output/validation_error.rb', line 6

ValidationError = Output.new_class(:path, :message, :source) do
  # @!attribute [r] path
  #   The path to the attribute that failed validation.
  #
  #   @return [String]

  # @!attribute [r] message
  #   The error message.
  #
  #   @return [String]

  # @!attribute [r] source
  #   The source of the invalid attributes.
  #
  #   @return [:SOURCE_PRINCIPAL, :SOURCE_RESOURCE]

  def self.from_protobuf(validation_error)
    new(
      path: validation_error.path,
      message: validation_error.message,
      source: validation_error.source
    )
  end

  # Check if the principal's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_principal?
    source == :SOURCE_PRINCIPAL
  end

  # Check if the resource's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_resource?
    source == :SOURCE_RESOURCE
  end
end

#source:SOURCE_PRINCIPAL, :SOURCE_RESOURCE (readonly)

The source of the invalid attributes.

Returns:

  • (:SOURCE_PRINCIPAL, :SOURCE_RESOURCE)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cerbos/output/validation_error.rb', line 6

ValidationError = Output.new_class(:path, :message, :source) do
  # @!attribute [r] path
  #   The path to the attribute that failed validation.
  #
  #   @return [String]

  # @!attribute [r] message
  #   The error message.
  #
  #   @return [String]

  # @!attribute [r] source
  #   The source of the invalid attributes.
  #
  #   @return [:SOURCE_PRINCIPAL, :SOURCE_RESOURCE]

  def self.from_protobuf(validation_error)
    new(
      path: validation_error.path,
      message: validation_error.message,
      source: validation_error.source
    )
  end

  # Check if the principal's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_principal?
    source == :SOURCE_PRINCIPAL
  end

  # Check if the resource's attributes failed schema validation.
  #
  # @return [Boolean]
  def from_resource?
    source == :SOURCE_RESOURCE
  end
end

Instance Method Details

#from_principal?Boolean

Check if the principal's attributes failed schema validation.

Returns:

  • (Boolean)


33
34
35
# File 'lib/cerbos/output/validation_error.rb', line 33

def from_principal?
  source == :SOURCE_PRINCIPAL
end

#from_resource?Boolean

Check if the resource's attributes failed schema validation.

Returns:

  • (Boolean)


40
41
42
# File 'lib/cerbos/output/validation_error.rb', line 40

def from_resource?
  source == :SOURCE_RESOURCE
end