Exception: LocoMotion::InvalidModifierError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/loco_motion/errors.rb

Overview

Raised when a component is given a modifier (via the modifier: / modifiers: options) that isn't listed in that component's valid_modifiers.

Instance Method Summary collapse

Constructor Details

#initialize(modifier, component, custom_message = nil) ⇒ InvalidModifierError

Returns a new instance of InvalidModifierError.

Parameters:

  • modifier (Symbol)

    The invalid modifier that was passed.

  • component (LocoMotion::BaseComponent)

    The component instance the modifier was passed to, used to list its valid modifiers.

  • custom_message (String, nil) (defaults to: nil)

    An optional message to use instead of the generated default.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/loco_motion/errors.rb', line 50

def initialize(modifier, component, custom_message = nil)
  no_modifiers_explanation = "No modifiers are defined on the component."
  default_explanation = "Valid modifiers are #{component.valid_modifiers.map(&:inspect).to_sentence}."

  has_modifiers = component.valid_modifiers.present?

  default_message = [
    "Unknown modifier #{modifier.inspect}.",
    (has_modifiers ? default_explanation : no_modifiers_explanation).to_s
  ].join(" ")

  super(custom_message || default_message)
end