Module: D3::Package::Validate
- Extended by:
- Validate
- Included in:
- D3::Package, Validate
- Defined in:
- lib/d3/package/validate.rb,
lib/d3/package.rb
Overview
This module contains methods for validating attribute values in d3 Packages
Each method takes an argument, and either raises an exception if the argument isn’t valid for its destination, or converts it to the proper type for its destination.
For example, the #validate_groups takes either a comma-seprated String or an Array of computer group names, converts the String to an Array if needed, and then confirms that each group exists in the JSS If they all do, the Array is returned.
Class Method Summary collapse
-
.basename_exist?(name) ⇒ Boolean
Check the existence of a basename in d3.
-
.edition_exist?(edition) ⇒ Boolean
Check the existence of an edition in d3.
-
.filename_exist?(name) ⇒ Boolean
Check the existence of a filename in the JSS.
- .validate_auto_groups(groups) ⇒ Object
-
.validate_category(cat) ⇒ String
Check the validity of a category name Raise an exception if not valid.
-
.validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid.
-
.validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens.
- .validate_excluded_groups(groups) ⇒ Object
-
.validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration.
-
.validate_expiration_path(path) ⇒ Pathname
Confirm the validity of an expiration path.
-
.validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths.
-
.validate_filename(name) ⇒ String
check that the given filename doesn’t already exist.
-
.validate_groups(groups, check_for_std = false) ⇒ Array
Confirm the existence of a list of Computer Group names (String or Array) and return them as an Array.
-
.validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
-
.validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid.
-
.validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist.
-
.validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script.
-
.validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
.validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script.
-
.validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
.validate_prohibiting_process(process_name) ⇒ String
Check a single prohibiting process for validity.
-
.validate_revision(rev) ⇒ Integer
Confirm the validity of a revision.
-
.validate_script(script) ⇒ Pathname, String
Check the validity of a script, either Pathname, JSS id, or JSS name Raise an exception if not valid.
-
.validate_version(vers) ⇒ String
Confirm the validity of a version.
-
.validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no,true/false,1/0 input value.
Instance Method Summary collapse
-
#basename_exist?(name) ⇒ Boolean
Check the existence of a basename in d3.
-
#edition_exist?(edition) ⇒ Boolean
Check the existence of an edition in d3.
-
#filename_exist?(name) ⇒ Boolean
Check the existence of a filename in the JSS.
- #validate_auto_groups(groups) ⇒ Object
-
#validate_category(cat) ⇒ String
Check the validity of a category name Raise an exception if not valid.
-
#validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid.
-
#validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens.
- #validate_excluded_groups(groups) ⇒ Object
-
#validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration.
-
#validate_expiration_path(path) ⇒ Pathname
Confirm the validity of an expiration path.
-
#validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths.
-
#validate_filename(name) ⇒ String
check that the given filename doesn’t already exist.
-
#validate_groups(groups, check_for_std = false) ⇒ Array
Confirm the existence of a list of Computer Group names (String or Array) and return them as an Array.
-
#validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
-
#validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid.
-
#validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist.
-
#validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script.
-
#validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
#validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script.
-
#validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
#validate_prohibiting_process(process_name) ⇒ String
Check a single prohibiting process for validity.
-
#validate_revision(rev) ⇒ Integer
Confirm the validity of a revision.
-
#validate_script(script) ⇒ Pathname, String
Check the validity of a script, either Pathname, JSS id, or JSS name Raise an exception if not valid.
-
#validate_version(vers) ⇒ String
Confirm the validity of a version.
-
#validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no,true/false,1/0 input value.
Class Method Details
.basename_exist?(name) ⇒ Boolean
Check the existence of a basename in d3.
113 114 115 |
# File 'lib/d3/package/validate.rb', line 113 def basename_exist?(name) D3::Package.all_basenames.include? name end |
.edition_exist?(edition) ⇒ Boolean
Check the existence of an edition in d3.
123 124 125 |
# File 'lib/d3/package/validate.rb', line 123 def edition_exist?(edition) D3::Package.all_editions.include? edition end |
.filename_exist?(name) ⇒ Boolean
Check the existence of a filename in the JSS.
133 134 135 |
# File 'lib/d3/package/validate.rb', line 133 def filename_exist?(name) D3::Package.all_filenames.values.include? name end |
.validate_auto_groups(groups) ⇒ Object
256 257 258 |
# File 'lib/d3/package/validate.rb', line 256 def validate_auto_groups(groups) validate_groups groups, :check_for_std end |
.validate_category(cat) ⇒ String
Check the validity of a category name Raise an exception if not valid. nil and empty strings are acceptable to unset the category.
359 360 361 362 363 364 |
# File 'lib/d3/package/validate.rb', line 359 def validate_category(cat) cat = nil if cat.to_s =~ /^n(one)?$/i return '' if cat.to_s.empty? raise JSS::NoSuchItemError, "No category '#{cat}' in the JSS" unless JSS::Category.all_names.include? cat cat end |
.validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid
340 341 342 343 344 345 346 347 348 349 |
# File 'lib/d3/package/validate.rb', line 340 def validate_cpu_type(type) type = JSS::Package::DEFAULT_PROCESSOR if type.to_s.empty? type = 'None' if type =~ /^n(one)?$/i type = 'x86' if type.casecmp('intel').zero? type = 'ppc' if type.casecmp('ppc').zero? unless JSS::Package::CPU_TYPES.include? type raise JSS::InvalidDataError, "CPU type must be one of: #{JSS::Package::CPU_TYPES.join ', '}" end type end |
.validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens
164 165 166 167 168 |
# File 'lib/d3/package/validate.rb', line 164 def validate_edition(edition) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the edition '#{edition}'" if edition_exist? edition raise JSS::InvalidDataError, "'#{edition}' doesn't seem like a valid edition" unless edition.count('-') >= 2 edition end |
.validate_excluded_groups(groups) ⇒ Object
261 262 263 |
# File 'lib/d3/package/validate.rb', line 261 def validate_excluded_groups(groups) validate_groups groups end |
.validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration. Raise an exception if invalid.
416 417 418 419 420 421 |
# File 'lib/d3/package/validate.rb', line 416 def validate_expiration(exp) exp ||= '0' raise JSS::InvalidDataError, 'Expiration must be a non-negative Integer.' unless exp.to_s =~ /^\d+$/ exp = 0 if exp.to_i < 0 exp.to_i end |
.validate_expiration_path(path) ⇒ Pathname
Confirm the validity of an expiration path. Any string that starts with a / is valid, d3 can’t confirm the paths existing on client machines.
451 452 453 454 455 |
# File 'lib/d3/package/validate.rb', line 451 def validate_expiration_path(path) path = path.to_s raise JSS::InvalidDataError, 'Expiration Path must be a full path starting with /.' unless path.start_with? '/' Pathname.new path end |
.validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths. Any string that starts with a / is valid. The strings “n” or “none” returns an empty array.
431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/d3/package/validate.rb', line 431 def validate_expiration_paths(paths) return [] if paths.to_s.empty? || paths.to_s =~ /^n(one)?$/i paths = paths.chomp.split(/\s*,\s*/) if paths.is_a? String if paths.is_a? Array return paths.map! { |p| validate_expiration_path p } else return [validate_expiration_path(paths)] end end |
.validate_filename(name) ⇒ String
check that the given filename doesn’t already exist
152 153 154 155 |
# File 'lib/d3/package/validate.rb', line 152 def validate_filename(name) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the filename '#{name}'" if self.filename_exist? name name end |
.validate_groups(groups, check_for_std = false) ⇒ Array
Confirm the existence of a list of Computer Group names (String or Array) and return them as an Array
If “n”, “”, “none” or nil are passed, an empty array is returned.
Raise an exception if any group is not valid.
278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/d3/package/validate.rb', line 278 def validate_groups(groups, check_for_std = false) groups = [] if groups.to_s =~ /^n(one)?$/i group_array = JSS.to_s_and_a(groups)[:arrayform].compact return [] if group_array.empty? return [] if group_array.reject { |g| g =~ /^n(one)$/i }.empty? # ['n'], ['None'], case-free return [D3::STANDARD_AUTO_GROUP] if check_for_std && group_array.include?(D3::STANDARD_AUTO_GROUP) group_array.each do |group| raise JSS::NoSuchItemError, "No ComputerGroup named '#{group}' in the JSS" unless JSS::ComputerGroup.all_names.include? group end group_array end |
.validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
300 301 302 303 304 305 306 |
# File 'lib/d3/package/validate.rb', line 300 def validate_non_overlapping_groups(auto, excl) return nil unless auto && excl auto = JSS.to_s_and_a(auto)[:arrayform] excl = JSS.to_s_and_a(excl)[:arrayform] raise JSS::InvalidDataError, "Auto and Excluded group-lists can't contain groups in common." unless (auto & excl).empty? true end |
.validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/d3/package/validate.rb', line 315 def validate_oses(os_list) os_list = nil if os_list.to_s =~ /^n(one)?$/i return [] if os_list.to_s.empty? ### if any value starts with >=, expand it case os_list when String os_list = JSS.(os_list) if os_list =~ /^>=/ when Array os_list.map! { |a| a =~ /^>=/ ? JSS.(a) : a } os_list.flatten! os_list.uniq! else raise JSS::InvalidDataError, 'os_list must be a String or an Array of strings' end ### return the array version JSS.to_s_and_a(os_list)[:arrayform] end |
.validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist
141 142 143 144 |
# File 'lib/d3/package/validate.rb', line 141 def validate_package_name(name) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the name '#{name}'" if JSS::Package.all_names.include? name name end |
.validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script
206 207 208 |
# File 'lib/d3/package/validate.rb', line 206 def validate_post_install_script(script) validate_script script end |
.validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
222 223 224 |
# File 'lib/d3/package/validate.rb', line 222 def validate_post_remove_script(script) validate_script script end |
.validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script
198 199 200 |
# File 'lib/d3/package/validate.rb', line 198 def validate_pre_install_script(script) validate_script script end |
.validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
214 215 216 |
# File 'lib/d3/package/validate.rb', line 214 def validate_pre_remove_script(script) validate_script script end |
.validate_prohibiting_process(process_name) ⇒ String
Check a single prohibiting process for validity
372 373 374 375 376 |
# File 'lib/d3/package/validate.rb', line 372 def validate_prohibiting_process(process_name) process_name = nil if process_name.to_s =~ /^n(one)?$/i return nil if process_name.nil? || process_name.empty? process_name.to_s end |
.validate_revision(rev) ⇒ Integer
Confirm the validity of a revision. Raise an exception if invalid.
189 190 191 192 |
# File 'lib/d3/package/validate.rb', line 189 def validate_revision(rev) raise JSS::InvalidDataError, 'Revision must be an Integer.' unless rev.to_s =~ /^\d+$/ rev.to_i end |
.validate_script(script) ⇒ Pathname, String
Check the validity of a script, either Pathname, JSS id, or JSS name Raise an exception if not valid
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/d3/package/validate.rb', line 233 def validate_script(script) script = nil if script.to_s =~ /^n(one)?$/i return nil if script.to_s.empty? script = script.to_s.strip if script =~ /^\d+$/ script = script.to_i return JSS::Script.map_all_ids_to(:name)[script] if JSS::Script.all_ids.include? script raise JSS::NoSuchItemError, "No JSS script with id '#{script}'" else # if its a file path, return it fully expanded path = Pathname.new script return path. if path.file? # otherwise, its a JSS Script name,return its id return script if JSS::Script.all_names.include? script.to_s raise JSS::NoSuchItemError, "No local file or JSS script named '#{script}'" end # if a fixnum end |
.validate_version(vers) ⇒ String
Confirm the validity of a version. Raise an exception if invalid.
176 177 178 179 180 |
# File 'lib/d3/package/validate.rb', line 176 def validate_version(vers) raise JSS::InvalidDataError, 'Version must be a String.' unless vers.is_a? String raise JSS::InvalidDataError, "Version can't be empty." if vers.empty? vers.gsub(' ', '_') end |
.validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no,true/false,1/0 input value
TrueClass, “true”, “y”,“yes”, and 1 are true
FalseClass, nil, “false”, “n”, “no”, and 0 are false
(Strings are case-insensitive) Anything else raises an exception.
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/d3/package/validate.rb', line 391 def validate_yes_no(yn) case yn when Integer return true if yn == 1 return false if yn.zero? when String return true if yn.strip =~ /^y(es)?$/i return false if yn.strip =~ /^no?$/i when TrueClass return true when FalseClass return false when nil return false end raise JSS::InvalidDataError, "Value must be one of: 'yes', 'y', 'true', '1', 'no', 'n', 'false', '0'" end |
Instance Method Details
#basename_exist?(name) ⇒ Boolean
Check the existence of a basename in d3.
113 114 115 |
# File 'lib/d3/package/validate.rb', line 113 def basename_exist?(name) D3::Package.all_basenames.include? name end |
#edition_exist?(edition) ⇒ Boolean
Check the existence of an edition in d3.
123 124 125 |
# File 'lib/d3/package/validate.rb', line 123 def edition_exist?(edition) D3::Package.all_editions.include? edition end |
#filename_exist?(name) ⇒ Boolean
Check the existence of a filename in the JSS.
133 134 135 |
# File 'lib/d3/package/validate.rb', line 133 def filename_exist?(name) D3::Package.all_filenames.values.include? name end |
#validate_auto_groups(groups) ⇒ Object
256 257 258 |
# File 'lib/d3/package/validate.rb', line 256 def validate_auto_groups(groups) validate_groups groups, :check_for_std end |
#validate_category(cat) ⇒ String
Check the validity of a category name Raise an exception if not valid. nil and empty strings are acceptable to unset the category.
359 360 361 362 363 364 |
# File 'lib/d3/package/validate.rb', line 359 def validate_category(cat) cat = nil if cat.to_s =~ /^n(one)?$/i return '' if cat.to_s.empty? raise JSS::NoSuchItemError, "No category '#{cat}' in the JSS" unless JSS::Category.all_names.include? cat cat end |
#validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid
340 341 342 343 344 345 346 347 348 349 |
# File 'lib/d3/package/validate.rb', line 340 def validate_cpu_type(type) type = JSS::Package::DEFAULT_PROCESSOR if type.to_s.empty? type = 'None' if type =~ /^n(one)?$/i type = 'x86' if type.casecmp('intel').zero? type = 'ppc' if type.casecmp('ppc').zero? unless JSS::Package::CPU_TYPES.include? type raise JSS::InvalidDataError, "CPU type must be one of: #{JSS::Package::CPU_TYPES.join ', '}" end type end |
#validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens
164 165 166 167 168 |
# File 'lib/d3/package/validate.rb', line 164 def validate_edition(edition) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the edition '#{edition}'" if edition_exist? edition raise JSS::InvalidDataError, "'#{edition}' doesn't seem like a valid edition" unless edition.count('-') >= 2 edition end |
#validate_excluded_groups(groups) ⇒ Object
261 262 263 |
# File 'lib/d3/package/validate.rb', line 261 def validate_excluded_groups(groups) validate_groups groups end |
#validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration. Raise an exception if invalid.
416 417 418 419 420 421 |
# File 'lib/d3/package/validate.rb', line 416 def validate_expiration(exp) exp ||= '0' raise JSS::InvalidDataError, 'Expiration must be a non-negative Integer.' unless exp.to_s =~ /^\d+$/ exp = 0 if exp.to_i < 0 exp.to_i end |
#validate_expiration_path(path) ⇒ Pathname
Confirm the validity of an expiration path. Any string that starts with a / is valid, d3 can’t confirm the paths existing on client machines.
451 452 453 454 455 |
# File 'lib/d3/package/validate.rb', line 451 def validate_expiration_path(path) path = path.to_s raise JSS::InvalidDataError, 'Expiration Path must be a full path starting with /.' unless path.start_with? '/' Pathname.new path end |
#validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths. Any string that starts with a / is valid. The strings “n” or “none” returns an empty array.
431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/d3/package/validate.rb', line 431 def validate_expiration_paths(paths) return [] if paths.to_s.empty? || paths.to_s =~ /^n(one)?$/i paths = paths.chomp.split(/\s*,\s*/) if paths.is_a? String if paths.is_a? Array return paths.map! { |p| validate_expiration_path p } else return [validate_expiration_path(paths)] end end |
#validate_filename(name) ⇒ String
check that the given filename doesn’t already exist
152 153 154 155 |
# File 'lib/d3/package/validate.rb', line 152 def validate_filename(name) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the filename '#{name}'" if self.filename_exist? name name end |
#validate_groups(groups, check_for_std = false) ⇒ Array
Confirm the existence of a list of Computer Group names (String or Array) and return them as an Array
If “n”, “”, “none” or nil are passed, an empty array is returned.
Raise an exception if any group is not valid.
278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/d3/package/validate.rb', line 278 def validate_groups(groups, check_for_std = false) groups = [] if groups.to_s =~ /^n(one)?$/i group_array = JSS.to_s_and_a(groups)[:arrayform].compact return [] if group_array.empty? return [] if group_array.reject { |g| g =~ /^n(one)$/i }.empty? # ['n'], ['None'], case-free return [D3::STANDARD_AUTO_GROUP] if check_for_std && group_array.include?(D3::STANDARD_AUTO_GROUP) group_array.each do |group| raise JSS::NoSuchItemError, "No ComputerGroup named '#{group}' in the JSS" unless JSS::ComputerGroup.all_names.include? group end group_array end |
#validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
300 301 302 303 304 305 306 |
# File 'lib/d3/package/validate.rb', line 300 def validate_non_overlapping_groups(auto, excl) return nil unless auto && excl auto = JSS.to_s_and_a(auto)[:arrayform] excl = JSS.to_s_and_a(excl)[:arrayform] raise JSS::InvalidDataError, "Auto and Excluded group-lists can't contain groups in common." unless (auto & excl).empty? true end |
#validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/d3/package/validate.rb', line 315 def validate_oses(os_list) os_list = nil if os_list.to_s =~ /^n(one)?$/i return [] if os_list.to_s.empty? ### if any value starts with >=, expand it case os_list when String os_list = JSS.(os_list) if os_list =~ /^>=/ when Array os_list.map! { |a| a =~ /^>=/ ? JSS.(a) : a } os_list.flatten! os_list.uniq! else raise JSS::InvalidDataError, 'os_list must be a String or an Array of strings' end ### return the array version JSS.to_s_and_a(os_list)[:arrayform] end |
#validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist
141 142 143 144 |
# File 'lib/d3/package/validate.rb', line 141 def validate_package_name(name) raise JSS::AlreadyExistsError, "There's already a package in the JSS with the name '#{name}'" if JSS::Package.all_names.include? name name end |
#validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script
206 207 208 |
# File 'lib/d3/package/validate.rb', line 206 def validate_post_install_script(script) validate_script script end |
#validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
222 223 224 |
# File 'lib/d3/package/validate.rb', line 222 def validate_post_remove_script(script) validate_script script end |
#validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script
198 199 200 |
# File 'lib/d3/package/validate.rb', line 198 def validate_pre_install_script(script) validate_script script end |
#validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
214 215 216 |
# File 'lib/d3/package/validate.rb', line 214 def validate_pre_remove_script(script) validate_script script end |
#validate_prohibiting_process(process_name) ⇒ String
Check a single prohibiting process for validity
372 373 374 375 376 |
# File 'lib/d3/package/validate.rb', line 372 def validate_prohibiting_process(process_name) process_name = nil if process_name.to_s =~ /^n(one)?$/i return nil if process_name.nil? || process_name.empty? process_name.to_s end |
#validate_revision(rev) ⇒ Integer
Confirm the validity of a revision. Raise an exception if invalid.
189 190 191 192 |
# File 'lib/d3/package/validate.rb', line 189 def validate_revision(rev) raise JSS::InvalidDataError, 'Revision must be an Integer.' unless rev.to_s =~ /^\d+$/ rev.to_i end |
#validate_script(script) ⇒ Pathname, String
Check the validity of a script, either Pathname, JSS id, or JSS name Raise an exception if not valid
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/d3/package/validate.rb', line 233 def validate_script(script) script = nil if script.to_s =~ /^n(one)?$/i return nil if script.to_s.empty? script = script.to_s.strip if script =~ /^\d+$/ script = script.to_i return JSS::Script.map_all_ids_to(:name)[script] if JSS::Script.all_ids.include? script raise JSS::NoSuchItemError, "No JSS script with id '#{script}'" else # if its a file path, return it fully expanded path = Pathname.new script return path. if path.file? # otherwise, its a JSS Script name,return its id return script if JSS::Script.all_names.include? script.to_s raise JSS::NoSuchItemError, "No local file or JSS script named '#{script}'" end # if a fixnum end |
#validate_version(vers) ⇒ String
Confirm the validity of a version. Raise an exception if invalid.
176 177 178 179 180 |
# File 'lib/d3/package/validate.rb', line 176 def validate_version(vers) raise JSS::InvalidDataError, 'Version must be a String.' unless vers.is_a? String raise JSS::InvalidDataError, "Version can't be empty." if vers.empty? vers.gsub(' ', '_') end |
#validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no,true/false,1/0 input value
TrueClass, “true”, “y”,“yes”, and 1 are true
FalseClass, nil, “false”, “n”, “no”, and 0 are false
(Strings are case-insensitive) Anything else raises an exception.
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/d3/package/validate.rb', line 391 def validate_yes_no(yn) case yn when Integer return true if yn == 1 return false if yn.zero? when String return true if yn.strip =~ /^y(es)?$/i return false if yn.strip =~ /^no?$/i when TrueClass return true when FalseClass return false when nil return false end raise JSS::InvalidDataError, "Value must be one of: 'yes', 'y', 'true', '1', 'no', 'n', 'false', '0'" end |