chef-server-api/app/helpers/cookbook_version_helper.rb
# validate and return the number of versions requested
# by the user
#
# raises an exception if an invalid number is requested
#
# params:
# - default: the number of versions to default to
#
# valid num_versions query parameter:
# - an integer >= 0
# - the string "all"
validate and return the number of versions requested
by the user

raises an exception if an invalid number is requested

the number of versions to default to

valid num_versions query parameter:
an integer >= 0
the string "all"
validate and return the number of versions requested by the user raises an exception if an invalid number is requested the number of versions to default to valid num_versions query parameter : an integer > = 0 the string " all "
def num_versions!(default="1")
      input = params[:num_versions]
      result = if input
                 valid_input = (input == "all" || Integer(input) >= 0) rescue false
                 raise BadRequest, "You have requested an invalid number of versions (x >= 0 || 'all')" unless valid_input
                 input
               else
                 default
               end
    end
def num_versions! ( default = "1" ) input = params [ :num_versions ] result = if input valid_input = ( input == "all" || Integer ( input ) >= 0 ) rescue false raise BadRequest , "You have requested an invalid number of versions (x >= 0 || 'all')" unless valid_input input else default end end
validate and return the number of versions requested
by the user
validate and return the number of versions requested by the user
default
<not_specific>