Sha256: 68bb5ff8c127951e2da5bc0d32e929e80aade71825a9d725aeefa2cf7685fadb

Contents?: true

Size: 781 Bytes

Versions: 6

Compression:

Stored size: 781 Bytes

Contents

require 'jschematic/element'

module Jschematic
  module Attributes
    class AdditionalProperties
      include Jschematic::Element

      # TODO: rename value to allowed
      def initialize(value, &block)
        @value = value
        @properties = block.call("properties").keys
      end

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jschematic-0.1.0 lib/jschematic/attributes/additional_properties.rb
jschematic-0.0.9 lib/jschematic/attributes/additional_properties.rb
jschematic-0.0.6 lib/jschematic/attributes/additional_properties.rb
jschematic-0.0.5 lib/jschematic/attributes/additional_properties.rb
jschematic-0.0.2 lib/jschematic/attributes/additional_properties.rb
jschematic-0.0.1 lib/jschematic/attributes/additional_properties.rb