Class: Saphyr::Engine::Context Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject (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

#errorsObject (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

#fragmentObject (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

#pathObject (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

#schemaObject (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

#validatorsObject (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_validateObject

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

Returns:

  • The full data or a fragment of data is it exists.



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.

Parameters:

  • schema (Saphyr::Schema)

    The schema associated with the new context.

  • fragment (Hash)

    The data fragment.

  • path (String)

    The path of the new context.



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.

Parameters:

  • name (Symbol)

    The name of the schema.

Returns:

Raises:



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.

Returns:

  • (String)


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