Class: Jschematic::Attributes::Items

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/jschematic/attributes/items.rb

Instance Attribute Summary

Attributes included from Element

#id, #parent

Instance Method Summary collapse

Methods included from Element

#required?, #schema_for, #title, #to_s

Constructor Details

#initialize(schema) ⇒ Items

Returns a new instance of Items.



8
9
10
# File 'lib/jschematic/attributes/items.rb', line 8

def initialize(schema)
  @schema = schema
end

Instance Method Details

#accepts?(instance) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/jschematic/attributes/items.rb', line 12

def accepts?(instance)
  case @schema
  when Hash
    instance.all?{ |item| Schema.new(@schema).accepts?(item) }
  when Array
    @schema.zip(instance).all?{ |schema, item| Schema.new(schema).accepts?(item) }
      # TODO: There is a bug here similar to the one in the Union type;
      #       the error reported does not mention the failure is w/i an item attribute
  end || fail_validation!(@schema, instance) 
end