Skip to content

Instantly share code, notes, and snippets.

@joaquimadraz
Created January 16, 2016 12:14
Show Gist options
  • Save joaquimadraz/e3a19eac824f34ec9746 to your computer and use it in GitHub Desktop.
Save joaquimadraz/e3a19eac824f34ec9746 to your computer and use it in GitHub Desktop.
compel_array_validation.rb
schema = Compel.array.items(
Compel.hash.keys({
a: Compel.string.required,
b: Compel.string.format(/^abc$/)
})
)
object = [
{ a: 'A', b: 'abc' },
{ a: 'B' },
{ a: 'C', b: 'abcd' }
]
result = schema.validate(object)
=> <Compel::Result:0x007fe88c3ded80
@errors={"2"=>{"b"=>["must match format ^abc$"]}},
@valid=false,
@value=[{"a"=>"A", "b"=>"abc"}, {"a"=>"B"}, {"a"=>"C", "b"=>"abcd", "errors"=>{"b"=>["must match format ^abc$"]}}]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment