Class: Compel::Builder::Array

Inherits:
Schema
  • Object
show all
Defined in:
lib/compel/builder/array.rb

Instance Attribute Summary

Attributes inherited from Schema

#options, #type

Instance Method Summary collapse

Methods inherited from Schema

#default_value, #required?

Methods included from Common

#default, #length, #required

Constructor Details

#initializeArray

Returns a new instance of Array.



6
7
8
# File 'lib/compel/builder/array.rb', line 6

def initialize
  super(Coercion::Array)
end

Instance Method Details

#is(value) ⇒ Object



19
20
21
22
# File 'lib/compel/builder/array.rb', line 19

def is(value)
  options[:is] = Coercion.coerce!(value, ::Array)
  self
end

#items(schema) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/compel/builder/array.rb', line 10

def items(schema)
  if !schema.is_a?(Schema)
    raise Compel::TypeError, '#items must be a valid Schema'
  end

  options[:items] = schema
  self
end

#validate(object) ⇒ Object



24
25
26
# File 'lib/compel/builder/array.rb', line 24

def validate(object)
  Contract.new(object, self).validate
end