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, #read_only!, #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.
36 37 38 39 40 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 36 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.
52 53 54 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 52 def empty_schema? document_schema.schema.empty? end |
#schema ⇒ Hash
The JSON Schema for the namespace
45 46 47 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 45 def schema document_schema.schema end |
#schema_property_names ⇒ String[]
Name of all the top level properties for the schema
59 60 61 62 63 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 59 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
68 69 70 71 72 73 74 75 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 68 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
80 81 82 |
# File 'lib/pdk/config/json_schema_namespace.rb', line 80 def validate_document!(document) ::JSON::Validator.validate!(schema, document) end |