lib/jss/api_object/scopable/scope.rb
def validate_item(realm, key, ident, error_if_not_found: true)
        # which keys allowed depends on how the item is used...
        possible_keys =
          case realm
          when :target then @target_keys
          when :limitation then LIMITATIONS
          when :exclusion then @exclusion_keys
          else
            raise ArgumentError, 'Unknown realm, must be :target, :limitation, or :exclusion'
          end

        key = pluralize_key(key)

        raise JSS::InvalidDataError, "#{realm} key must be one of :#{possible_keys.join(', :')}" \
          unless possible_keys.include? key

        id = nil

        # id will be a string
        if key == :jamf_ldap_users
          id = ident if JSS::User.all_names(:refresh, api: container.api).include?(ident) || JSS::LDAPServer.user_in_ldap?(ident)

        # id will be a string
        elsif key == :ldap_user_groups
          id = ident if JSS::LDAPServer.group_in_ldap? ident, api: container.api

        # id will be an integer
        else
          id = SCOPING_CLASSES[key].valid_id ident, api: container.api
        end

        raise JSS::NoSuchItemError, "No existing #{key} matching '#{ident}'" if error_if_not_found && id.nil?

        id
      end
# look up a valid id or nil, for use in a scope type
# Raise an error if not found, unless error_if_not_found is falsey
#
# @param realm [Symbol] How is this key being used in the scope?
#   :target, :limitation, or :exclusion
#
# @param key [Symbol] What kind of thing are we adding to the scope?
#  e.g computer, network_segment, etc.
#
# @param ident [String, Integer] A unique identifier for the item being
#   validated, jss id, name, serial number, etc.
#
# @param error_if_not_found [Boolean] raise an error if no match for the ident
#
# @return [Integer, String, nil] the valid id or string for the item, or nil if not found
#
look up a valid id or nil, for use in a scope type
Raise an error if not found, unless error_if_not_found is falsey
look up a valid id or nil for use in a scope type Raise an error if not found unless error_if_not_found is falsey
def validate_item(realm, key, ident, error_if_not_found: true)
        possible_keys =
          case realm
          when :target then @target_keys
          when :limitation then LIMITATIONS
          when :exclusion then @exclusion_keys
          else
            raise ArgumentError, 'Unknown realm, must be :target, :limitation, or :exclusion'
          end
        key = pluralize_key(key)
        raise JSS::InvalidDataError, "#{realm} key must be one of :#{possible_keys.join(', :')}" \
          unless possible_keys.include? key
        id = nil
        if key == :jamf_ldap_users
          id = ident if JSS::User.all_names(:refresh, api: container.api).include?(ident) || JSS::LDAPServer.user_in_ldap?(ident)
        elsif key == :ldap_user_groups
          id = ident if JSS::LDAPServer.group_in_ldap? ident, api: container.api
        else
          id = SCOPING_CLASSES[key].valid_id ident, api: container.api
        end
        raise JSS::NoSuchItemError, "No existing #{key} matching '#{ident}'" if error_if_not_found && id.nil?
        id
      end
def validate_item ( realm , key , ident , error_if_not_found : true ) possible_keys = case realm when :target then @target_keys when :limitation then LIMITATIONS when :exclusion then @exclusion_keys else raise ArgumentError , 'Unknown realm, must be :target, :limitation, or :exclusion' end key = pluralize_key ( key ) raise JSS :: InvalidDataError , "#{realm} key must be one of :#{possible_keys.join(', :')}" unless possible_keys . include? key id = nil if key == :jamf_ldap_users id = ident if JSS :: User . all_names ( :refresh , api : container . api ) . include? ( ident ) || JSS :: LDAPServer . user_in_ldap? ( ident ) elsif key == :ldap_user_groups id = ident if JSS :: LDAPServer . group_in_ldap? ident , api : container . api else id = SCOPING_CLASSES [ key ] . valid_id ident , api : container . api end raise JSS :: NoSuchItemError , "No existing #{key} matching '#{ident}'" if error_if_not_found && id . nil? id end
look up a valid id or nil, for use in a scope type
Raise an error if not found, unless error_if_not_found is falsey
look up a valid id or nil for use in a scope type Raise an error if not found unless error_if_not_found is falsey
# which keys allowed depends on how the item is used... # id will be a string # id will be a string # id will be an integer
the valid id or string for the item, or nil if not found
the valid id or string for the item or nil if not found
Integer, String, nil
realm
None
key
None
ident
A unique identifier for the item being validated, jss id, name, serial number, etc.
A unique identifier for the item being validated jss id name serial number etc .
error_if_not_found
raise an error if no match for the ident
raise an error if no match for the ident