Sha256: 1e4dfc84e2fd2ab13c8b9ef33a5f654a72deb66d240a03d7c4546e6e0471266a
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
module Schemacop class Schema # Create a new Schema # # For detailed usage, please refer to README.md in the root of this project. # # @param args [Array] An array of arguments to apply to the root node of the # Schema. # @param block A block with further Schema specification. # @raise [Schemacop::Exceptions::InvalidSchemaError] If the Schema defined # is invalid. def initialize(*args, &block) @root = HashValidator.new do req :root, *args, &block end end # Query data validity # # @param data The data to validate. # @return [Boolean] True if the data is valid, false otherwise. def valid?(data) validate(data).valid? end # Query data validity # # @param data The data to validate. # @return [Boolean] True if data is invalid, false otherwise. def invalid?(data) !valid?(data) end # Validate data for the defined Schema # # @param data The data to validate. # @return [Schemacop::Collector] The object that collected errors # throughout the validation. def validate(data) collector = Collector.new(data.deep_dup) @root.fields[:root].validate({ root: data }, collector.ignore_next_segment) return collector end # Validate data for the defined Schema # # @param data The data to validate. # @raise [Schemacop::Exceptions::ValidationError] If the data is invalid, # this exception is thrown. # @return nil def validate!(data) collector = validate(data) unless collector.valid? fail Exceptions::ValidationError, collector.exception_message end return collector.data end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
schemacop-2.4.2 | lib/schemacop/schema.rb |
schemacop-2.4.1 | lib/schemacop/schema.rb |
schemacop-2.4.0 | lib/schemacop/schema.rb |