Module: Sbuilder::Utils::Validate
- Defined in:
- lib/utils/validate.rb
Class Method Summary collapse
- .oneOf(defintionHash, propList, min = 1, max = 1) ⇒ Object
-
.validateProperties(defintionHash, required, allowed = []) ⇒ Object
validate ‘defintionHash’ all ‘required’/only ‘allowed’ props set.
Class Method Details
.oneOf(defintionHash, propList, min = 1, max = 1) ⇒ Object
29 30 31 32 |
# File 'lib/utils/validate.rb', line 29 def self.oneOf( defintionHash, propList, min=1, max=1 ) props = propList.select {|prop| defintionHash.has_key?(prop) }.length raise ValidateException.new "Must give min #{min} - max #{max} #{propList} in #{defintionHash}" unless props >= min && props <= max end |
.validateProperties(defintionHash, required, allowed = []) ⇒ Object
validate ‘defintionHash’ all ‘required’/only ‘allowed’ props set
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/utils/validate.rb', line 16 def self.validateProperties( defintionHash, required, allowed=[] ) allowed = required unless allowed allowed = (required + allowed).uniq missingProps = required - defintionHash.keys raise ValidateException.new "Missing properties #{missingProps} in #{defintionHash} - required #{required}" if missingProps.any? invalidProps = defintionHash.keys - allowed raise ValidateException.new "Unknown properties #{invalidProps} in #{defintionHash} - allowed #{allowed}" if invalidProps.any? end |