Method: JSS::Extendable#validate_popup_value

Defined in:
lib/jss/api_object/extendable.rb

#validate_popup_value(ea_name, value, refresh) ⇒ Object

Raise an error if the named EA has a popup menu, but the provided value isn’t one of the menu items


294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/jss/api_object/extendable.rb', line 294

def validate_popup_value(ea_name, value, refresh)
  # get the ea def. instance from the api cache, or the api
  api.ext_attr_definition_cache[self.class] ||= {}
  api.ext_attr_definition_cache[self.class][ea_name] = nil if refresh
  api.ext_attr_definition_cache[self.class][ea_name] ||= self.class::EXT_ATTRIB_CLASS.fetch name: ea_name, api: api

  ea_def = api.ext_attr_definition_cache[self.class][ea_name]
  return unless ea_def.from_popup_menu?

  return if ea_def.popup_choices.include? value.to_s

  raise JSS::UnsupportedError, "The value for #{ea_name} must be one of: '#{ea_def.popup_choices.join("' '")}'"
end