Class: PDK::Config::JSONSchemaNamespace
- Defined in:
- lib/pdk/config/json_schema_namespace.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Namespace
Instance Method Summary collapse
-
#empty_schema? ⇒ Boolean
Whether the schema is valid but empty.
-
#initialize(name = nil, file: nil, parent: nil, persistent_defaults: false, schema_file: nil, &block) ⇒ JSONSchemaNamespace
constructor
Initialises the PDK::Config::JSONSchemaNamespace object.
-
#schema ⇒ Hash
The JSON Schema for the namespace.
-
#schema_property_names ⇒ String[]
Name of all the top level properties for the schema.
-
#to_h ⇒ Object
Extends the to_h namespace method to include unmanaged settings.
-
#validate_document!(document) ⇒ Boolean
Validates a document (Hash table) against the schema.
Methods inherited from Namespace
#[], #[]=, #child_namespace?, #fetch, #include_in_parent?, #mount, #namespace, #resolve, #setting
Constructor Details
#initialize(name = nil, file: nil, parent: nil, persistent_defaults: false, schema_file: nil, &block) ⇒ JSONSchemaNamespace
Initialises the PDK::Config::JSONSchemaNamespace object.
34 35 36 37 38 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 34 def initialize(name = nil, file: nil, parent: nil, persistent_defaults: false, schema_file: nil, &block) super(name, file: file, parent: parent, persistent_defaults: persistent_defaults, &block) @schema_file = schema_file @unmanaged_settings = {} end |
Instance Method Details
#empty_schema? ⇒ Boolean
Whether the schema is valid but empty.
50 51 52 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 50 def empty_schema? document_schema.schema.empty? end |
#schema ⇒ Hash
The JSON Schema for the namespace
43 44 45 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 43 def schema document_schema.schema end |
#schema_property_names ⇒ String[]
Name of all the top level properties for the schema
57 58 59 60 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 57 def schema_property_names return [] if schema['properties'].nil? schema['properties'].keys end |
#to_h ⇒ Object
Extends the to_h namespace method to include unmanaged settings
65 66 67 68 69 70 71 72 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 65 def to_h # This may seem counter-intuitive but we need to call super first as the settings # may not have been loaded yet, which means @unmanaged_settings will be empty. # We call super first to force any file loading and then merge the unmanaged settings settings_hash = super @unmanaged_settings = {} if @unmanaged_settings.nil? @unmanaged_settings.merge(settings_hash) end |
#validate_document!(document) ⇒ Boolean
Validates a document (Hash table) against the schema
77 78 79 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 77 def validate_document!(document) ::JSON::Validator.validate!(schema, document) end |