Exception: LocoMotion::UnknownPartError

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of UnknownPartError.



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/loco_motion/errors.rb', line 3

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}"
  ].join(' ')

  super(custom_message || default_message)
end