Class: Senko::Compiler
- Inherits:
-
Object
- Object
- Senko::Compiler
- Defined in:
- lib/senko/compiler.rb,
lib/senko/compiler/optimizer.rb,
lib/senko/compiler/ref_resolver.rb
Defined Under Namespace
Classes: Optimizer, RefResolver, ResolvedRef
Constant Summary collapse
- DEFAULT_OPTIONS =
{ draft: nil, format: :annotation, ref_resolver: nil, schemas: {}, fail_fast: false, validate_meta_schema: false, custom_formats: {}, custom_keywords: {}, codegen: :auto, messages: {} }.freeze
- APPLICATOR_KEYWORDS =
%w[allOf anyOf oneOf].freeze
- SCHEMA_ARRAY_KEYWORDS =
%w[allOf anyOf oneOf prefixItems].freeze
- SCHEMA_MAP_KEYWORDS =
%w[properties patternProperties $defs definitions dependentSchemas].freeze
- SCHEMA_VALUE_KEYWORDS =
%w[ items additionalItems additionalProperties propertyNames contains not if then else unevaluatedProperties unevaluatedItems ].freeze
- DATA_VALUE_KEYWORDS =
%w[const enum default examples required dependentRequired].freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #compile(schema) ⇒ Object
-
#initialize(options = {}) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(options = {}) ⇒ Compiler
Returns a new instance of Compiler.
38 39 40 41 42 43 |
# File 'lib/senko/compiler.rb', line 38 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() @ref_cache = {} @resolving = Set.new @instruction_arrays = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
36 37 38 |
# File 'lib/senko/compiler.rb', line 36 def @options end |
Instance Method Details
#compile(schema) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/senko/compiler.rb', line 45 def compile(schema) stringified = deep_stringify(schema) (stringified) if @options[:validate_meta_schema] @draft = Dialect.detect(stringified, @options[:draft]) @root_schema = normalize_schema(stringified, @draft) @ref_resolver = RefResolver.new( @root_schema, schemas: @options[:schemas] || {}, ref_resolver: @options[:ref_resolver] ) @root_scope = RefResolver::ROOT_SCOPE @validation_vocabulary_enabled = validation_vocabulary_enabled?(@root_schema) Optimizer.new.optimize(compile_schema(@root_schema, '', @root_scope)) end |