Skip to content

Builtin Validations

mosop edited this page Dec 5, 2016 · 11 revisions

Inclusion (any_of)

Tests if a parsed value is any of the specified values.

Can be applied to:

  • String Option
  • String Argument
class Trip < Optarg::Model
  arg "somewhere_warm", any_of: %w(tahiti okinawa hawaii)
end

Trip.parse %w(gotland) # => raises an error

Element Inclusion (any_item_of)

Tests if a parsed element value of array is any of the specified values.

Can be applied to:

  • String Array Option
  • String Array Argument
class EuropeanWallet < Optarg::Model
  arg_array "bill", any_item_of: %w(€5 €10 €20 €50 €100 €200 €500)
end

EuropeanWallet.parse %w(€10 $50 €100) # => raises an error

Minimum Length of Array (min)

Tests if the count of a parsed array is equal to or greater than the specified number.

class TeamOfCanoePolo < Optarg::Model
  arg_array "member", min: 5
end

TeamOfCanoePolo.parse %w(freddie brian roger john) # => raises an error

Existence (required)

[WIP]

Clone this wiki locally