Class: Jschematic::Attributes::AdditionalProperties
- Inherits:
-
Object
- Object
- Jschematic::Attributes::AdditionalProperties
- Includes:
- Element
- Defined in:
- lib/jschematic/attributes/additional_properties.rb
Instance Attribute Summary
Attributes included from Element
Instance Method Summary collapse
- #accepts?(instance) ⇒ Boolean
-
#initialize(value, &block) ⇒ AdditionalProperties
constructor
TODO: rename value to allowed.
Methods included from Element
#required?, #schema_for, #title, #to_s
Constructor Details
#initialize(value, &block) ⇒ AdditionalProperties
TODO: rename value to allowed
9 10 11 12 |
# File 'lib/jschematic/attributes/additional_properties.rb', line 9 def initialize(value, &block) @value = value @properties = block.call("properties").keys end |
Instance Method Details
#accepts?(instance) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jschematic/attributes/additional_properties.rb', line 14 def accepts?(instance) case @value when FalseClass (@properties == instance.keys) || fail_validation!(@properties, instance.keys) when Hash schema = Schema.new(@value) additional = instance.select{ |attribute, value| !@properties.include?(attribute) } additional.all? do |attribute, value| schema.accepts?(value) end || fail_validation!(@value, instance) end end |