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 =
'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



16
17
18
19
# File 'lib/html2rss/config/schema.rb', line 16

def json_schema
  load_json_schema_extension!
  Builder.call
end

.load_json_schema_extension!Object



41
42
43
44
# File 'lib/html2rss/config/schema.rb', line 41

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/html2rss/config/schema.rb', line 25

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