Class: Saphyr::Engine::Context Private
- Inherits:
-
Object
- Object
- Saphyr::Engine::Context
- Defined in:
- lib/saphyr/engine.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class used to encapsule the validation engine context.
Instance Attribute Summary collapse
- #data ⇒ Object readonly private
- #errors ⇒ Object readonly private
- #fragment ⇒ Object readonly private
- #path ⇒ Object readonly private
- #schema ⇒ Object readonly private
- #validators ⇒ Object readonly private
Instance Method Summary collapse
-
#data_to_validate ⇒ Object
private
Get data needed for validation.
-
#derive(schema, fragment, path) ⇒ Object
private
Create a new context derived from the current one.
-
#find_schema(name) ⇒ Saphyr::Schema
private
Find a schema given his name.
-
#get_path(name) ⇒ String
private
Get the current field path from the root of the document.
-
#initialize(validators, schema, data, fragment, path, errors = []) ⇒ Context
constructor
private
A new instance of Context.
Constructor Details
#initialize(validators, schema, data, fragment, path, errors = []) ⇒ Context
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Context.
14 15 16 17 18 19 20 21 |
# File 'lib/saphyr/engine.rb', line 14 def initialize(validators, schema, data, fragment, path, errors=[]) @validators = validators @schema = schema @data = data @fragment = fragment @path = path @errors = errors end |
Instance Attribute Details
#data ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def data @data end |
#errors ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def errors @errors end |
#fragment ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def fragment @fragment end |
#path ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def path @path end |
#schema ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def schema @schema end |
#validators ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/saphyr/engine.rb', line 12 def validators @validators end |
Instance Method Details
#data_to_validate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get data needed for validation
57 58 59 60 |
# File 'lib/saphyr/engine.rb', line 57 def data_to_validate() return @data if @fragment.nil? @fragment end |
#derive(schema, fragment, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new context derived from the current one.
27 28 29 |
# File 'lib/saphyr/engine.rb', line 27 def derive(schema, fragment, path) Context.new @validators, schema, @data, fragment, path, @errors end |
#find_schema(name) ⇒ Saphyr::Schema
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Find a schema given his name. Lookup first into the local validators if there isn’t any schema found then lookup into the global schemas.
45 46 47 48 49 50 51 52 53 |
# File 'lib/saphyr/engine.rb', line 45 def find_schema(name) @validators.each do |validator| schema = validator.find_schema name return schema unless schema.nil? end schema = Saphyr.global_schema name raise Saphyr::Error.new "Cannot find schema name: #{name}" if schema.nil? schema end |
#get_path(name) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the current field path from the root of the document.
33 34 35 36 37 |
# File 'lib/saphyr/engine.rb', line 33 def get_path(name) return @path + name if @path == '//' return @path if name == '' @path + '.' + name end |