Class: Cuprum::Collections::Errors::UnknownOperator

Inherits:
Error
  • Object
show all
Defined in:
lib/cuprum/collections/errors/unknown_operator.rb

Overview

An error returned when a query attempts to filter by an unknown operator.

Constant Summary collapse

TYPE =

Short string used to identify the type of error.

'cuprum.collections.errors.unknown_operator'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator:) ⇒ UnknownOperator

Returns a new instance of UnknownOperator.

Parameters:

  • operator (String, Symbol)

    The unknown operator.



13
14
15
16
17
18
19
20
# File 'lib/cuprum/collections/errors/unknown_operator.rb', line 13

def initialize(operator:)
  @operator = operator

  super(
    message:  generate_message,
    operator: operator
  )
end

Instance Attribute Details

#operatorString, Symbol (readonly)

Returns the unknown operator.

Returns:

  • (String, Symbol)

    the unknown operator.



23
24
25
# File 'lib/cuprum/collections/errors/unknown_operator.rb', line 23

def operator
  @operator
end

Instance Method Details

#correctionsArray<String>

Returns Suggested possible values for the operator.

Returns:

  • (Array<String>)

    Suggested possible values for the operator.



26
27
28
29
30
31
# File 'lib/cuprum/collections/errors/unknown_operator.rb', line 26

def corrections
  @corrections ||=
    DidYouMean::SpellChecker
      .new(dictionary: Cuprum::Collections::Queries::VALID_OPERATORS.to_a)
      .correct(operator)
end