Exception: LocoMotion::UnknownPartError

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

Overview

Raised when a component is asked to operate on a part (e.g. via BaseComponent#part, ComponentConfig#get_part, or ComponentConfig#validate_part) that isn't declared on that component.

Instance Method Summary collapse

Constructor Details

#initialize(part, component, custom_message = nil) ⇒ UnknownPartError

Returns a new instance of UnknownPartError.

Parameters:

  • part (Symbol)

    The unknown part name that was requested.

  • component (LocoMotion::BaseComponent)

    The component instance the part was requested from, used to list its valid parts.

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

    An optional message to use instead of the generated default.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/loco_motion/errors.rb', line 20

def initialize(part, component, custom_message = nil)
  no_parts_explanation = "No parts are defined on the component."
  default_explanation = "Valid parts are #{component.config.valid_parts.map(&:inspect).to_sentence}."

  has_parts = component.config.valid_parts.present?

  default_message = [
    "Unknown part #{part.inspect}.",
    (has_parts ? default_explanation : no_parts_explanation).to_s
  ].join(" ")

  super(custom_message || default_message)
end