Module: Html2rss::Config::Schema
- Defined in:
- lib/html2rss/config/schema.rb
Overview
JSON export adapter from the runtime validators to the packaged schema artifact.
Defined Under Namespace
Classes: Builder
Constant Summary collapse
- SCHEMA_FILENAME =
Canonical filename for the exported config JSON schema artifact.
'html2rss-config.schema.json'
Class Method Summary collapse
-
.apply_selector_registry_refs!(schema) ⇒ Hash
Wires extractor / post_process to thin oneOf $refs into the registry catalog.
- .extractor_wire_schema ⇒ Hash{Symbol => Object}
-
.json_schema ⇒ Hash{String => Object}
Returns the exported configuration JSON Schema.
- .load_json_schema_extension! ⇒ void
-
.path ⇒ String
Resolves the packaged schema path used by downstream tools.
- .post_process_wire_schema ⇒ Hash{Symbol => Object}
-
.registry_ref_list(catalog, registry) ⇒ Array<Hash>
OneOf entries of
{ '$ref' => ... }.
Class Method Details
.apply_selector_registry_refs!(schema) ⇒ Hash
Wires extractor / post_process to thin oneOf $refs into the registry catalog.
195 196 197 198 199 200 |
# File 'lib/html2rss/config/schema.rb', line 195 def apply_selector_registry_refs!(schema) properties = schema.fetch(:properties) properties[:extractor] = extractor_wire_schema properties[:post_process] = post_process_wire_schema schema end |
.extractor_wire_schema ⇒ Hash{Symbol => Object}
203 204 205 206 207 208 |
# File 'lib/html2rss/config/schema.rb', line 203 def extractor_wire_schema { description: 'Extractor used to pull a value from the selected element.', oneOf: registry_ref_list('extractors', Selectors::Extractors::NAME_TO_CLASS) } end |
.json_schema ⇒ Hash{String => Object}
Returns the exported configuration JSON Schema.
17 18 19 20 |
# File 'lib/html2rss/config/schema.rb', line 17 def json_schema load_json_schema_extension! Builder.call end |
.load_json_schema_extension! ⇒ void
This method returns an undefined value.
43 44 45 46 |
# File 'lib/html2rss/config/schema.rb', line 43 def load_json_schema_extension! require 'dry/schema/extensions/json_schema' Dry::Schema.load_extensions(:json_schema) end |
.path ⇒ String
Resolves the packaged schema path used by downstream tools.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/html2rss/config/schema.rb', line 26 def path search_path = File.(__dir__) loop do candidate = File.join(search_path, 'schema', SCHEMA_FILENAME) return candidate if File.exist?(candidate) parent_path = File.dirname(search_path) break if parent_path == search_path search_path = parent_path end File.("../../../schema/#{SCHEMA_FILENAME}", __dir__) end |
.post_process_wire_schema ⇒ Hash{Symbol => Object}
211 212 213 214 215 216 217 218 219 |
# File 'lib/html2rss/config/schema.rb', line 211 def post_process_wire_schema { type: 'array', description: 'Ordered transforms applied to the extracted value.', items: { oneOf: registry_ref_list('post_processors', Selectors::PostProcessors::NAME_TO_CLASS) } } end |
.registry_ref_list(catalog, registry) ⇒ Array<Hash>
Returns oneOf entries of { '$ref' => ... }.
225 226 227 228 229 |
# File 'lib/html2rss/config/schema.rb', line 225 def registry_ref_list(catalog, registry) registry.keys.sort.map do |name| { '$ref' => "#/$defs/#{catalog}/#{name}" } end end |