Module: Html2rss::Config::Schema

Defined in:
lib/html2rss/config/schema.rb

Overview

Builds the exported configuration JSON Schema from the runtime validators.

Defined Under Namespace

Modules: Components, DeepStringifier, Selectors Classes: Builder

Constant Summary collapse

SCHEMA_FILENAME =

Canonical filename for the exported config JSON schema artifact.

'html2rss-config.schema.json'

Class Method Summary collapse

Class Method Details

.json_schemaHash{String => Object}

Returns the exported configuration JSON Schema.

Returns:

  • (Hash{String => Object})

    JSON Schema represented as a Ruby hash



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

.pathString

Resolves the packaged schema path used by downstream tools.

Returns:

  • (String)

    absolute path to the packaged JSON schema file



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.expand_path(__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.expand_path("../../../schema/#{SCHEMA_FILENAME}", __dir__)
end