Class: Copland::DefaultSchemaProcessor
- Inherits:
-
Object
- Object
- Copland::DefaultSchemaProcessor
- Defined in:
- lib/copland/default-schema-processor.rb
Overview
The DefaultSchemaProcessor is the default processor class used for processing (validating and pre-processing) schema elements.
Instance Method Summary collapse
-
#process(owner, client, schema, data, path = "/") ⇒ Object
Pre-processes the
data
, possibly in conjuction with theschema
. -
#validate(owner, client, schema, data, path = "/") ⇒ Object
Validates the given
data
against the givenschema
.
Instance Method Details
#process(owner, client, schema, data, path = "/") ⇒ Object
Pre-processes the data
, possibly in conjuction with the schema
. The parameters are identical to those given for #validate. The default implementation simply calls Copland::translate_value on the data
, using client
as the reference value.
The primary purpose of this call is to convert/translate values to their actual types, like “!!service service.name” values.
91 92 93 94 95 96 |
# File 'lib/copland/default-schema-processor.rb', line 91 def process( owner, client, schema, data, path="/" ) return Copland::translate_value( client.owner.registry, client.owner, client, data ) end |
#validate(owner, client, schema, data, path = "/") ⇒ Object
Validates the given data
against the given schema
. owner
is the object associated with the schema, and +client“ is the object associated with the data. If path
is given, it specifies the path up to the current schema element (for error reporting purposes).
If this method returns, then the validation succeeded. Otherwise, it will raise a ValidationException.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/copland/default-schema-processor.rb', line 50 def validate( owner, client, schema, data, path="/" ) return unless schema.definition schema_keys = schema.definition.keys data = data.value if data.respond_to?( :type_id ) data_keys = data.keys extra_keys = data_keys - schema_keys unless extra_keys.empty? validation_error owner, client, path, "illegal parameter(s) #{extra_keys.inspect}" end schema.definition.each_pair do |key, subschema| subpath = path + ( path[-1] == ?/ ? "" : "/" ) + key if data[key] validate_type owner, client, subschema.type, data[key], subpath subschema.validate owner, client, data[key], subpath elsif subschema.required validation_error owner, client, path, "required parameter #{key.inspect} missing" end end end |