Class: Stoplight::Domain::CompatibilityResult

Inherits:
Object
  • Object
show all
Defined in:
lib/stoplight/domain/compatibility_result.rb

Overview

The CompatibilityResult class represents the result of a compatibility check for a strategy. It provides methods to determine if the strategy is compatible and to retrieve error messages when it is not.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors: []) ⇒ CompatibilityResult

Initializes a new ‘CompatibilityResult` instance.

Parameters:

  • errors (defaults to: [])

    List of error messages if the strategy is not compatible.



28
29
30
# File 'lib/stoplight/domain/compatibility_result.rb', line 28

def initialize(errors: [])
  @errors = errors.freeze
end

Instance Attribute Details

#errorsObject (readonly)

Retrieves the list of error messages.

Returns:

  • The list of error messages.



42
43
44
# File 'lib/stoplight/domain/compatibility_result.rb', line 42

def errors
  @errors
end

Class Method Details

.compatibleObject

Creates a new CompatibilityResult instance representing a compatible strategy.

Returns:

  • An instance with no errors.



13
14
15
# File 'lib/stoplight/domain/compatibility_result.rb', line 13

def compatible
  new(errors: [])
end

.incompatible(*errors) ⇒ Object

Creates a new CompatibilityResult instance representing an incompatible strategy.

Parameters:

  • errors

    List of error messages indicating incompatibility.

Returns:

  • An instance with the provided errors.



21
22
23
# File 'lib/stoplight/domain/compatibility_result.rb', line 21

def incompatible(*errors)
  new(errors:)
end

Instance Method Details

#compatible?Boolean

Checks if the strategy is compatible.

Returns:

  • (Boolean)

    ‘true` if there are no errors, `false` otherwise.



34
35
36
# File 'lib/stoplight/domain/compatibility_result.rb', line 34

def compatible?
  @errors.empty?
end

#error_messagesObject

Retrieves a concatenated error message string.

Returns:

  • A string containing all error messages joined by “; ”, or ‘nil` if the strategy is compatible.



47
48
49
50
51
# File 'lib/stoplight/domain/compatibility_result.rb', line 47

def error_messages
  unless compatible?
    @errors.join("; ")
  end
end

#incompatible?Boolean

Returns:

  • (Boolean)


38
# File 'lib/stoplight/domain/compatibility_result.rb', line 38

def incompatible? = !compatible?