oselvar-var-config 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/oselvar/var/config.rb +69 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 629548dd7c8715ea670c8ecae6d14a6f7ea94f2e3603722aca05b0d3f0f7a7a3
4
+ data.tar.gz: 0e48cba6cf67f2be4b89b866dc29ad21f041b52a77e6acf81e6e6e115a88922c
5
+ SHA512:
6
+ metadata.gz: 46fd0a17b288a0d142f9fd5d769659a815f80500e59f21f673c1a39a70d84467b970fbdf8bc429e11fef9fed8433eb6fc7411f54f9a43e7a76379a768a648e0e
7
+ data.tar.gz: 426a067d9d9c601c6501b0a23f03647c5345eb8a19a53a19ff85e3d2e2568cb17c1fcba57f69058fa1ce7fa5398cdc349335db0c7a9fc326f5353652e461f1c7
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Oselvar
6
+ module Var
7
+ # Strict, fail-loud reader for the shared var.config.json format. Missing
8
+ # file → empty config; malformed JSON, wrong types, or unknown keys → an
9
+ # error starting with the file path. See conformance/config/README.md.
10
+ module Config
11
+ VERSION = '0.3.2'
12
+
13
+ # The parsed config. All fields default to empty.
14
+ VarConfig = Data.define(:docs_include, :docs_exclude, :steps, :snippets, :scanner_plugins) do
15
+ def initialize(docs_include: [], docs_exclude: [], steps: [], snippets: {}, scanner_plugins: [])
16
+ super
17
+ end
18
+ end
19
+
20
+ KNOWN_KEYS = %w[$schema docs steps snippets scannerPlugins].freeze
21
+ KNOWN_DOCS_KEYS = %w[include exclude].freeze
22
+
23
+ module_function
24
+
25
+ def read_var_config(root)
26
+ path = File.join(root.to_s, 'var.config.json')
27
+ return VarConfig.new unless File.file?(path)
28
+
29
+ data = begin
30
+ JSON.parse(File.read(path, encoding: 'UTF-8'))
31
+ rescue JSON::ParserError => e
32
+ raise ArgumentError, "#{path}: invalid JSON: #{e.message}"
33
+ end
34
+ raise ArgumentError, "#{path}: top level must be an object" unless data.is_a?(::Hash)
35
+
36
+ unknown = data.keys - KNOWN_KEYS
37
+ raise ArgumentError, "#{path}: unknown key(s): #{unknown.sort.join(', ')}" unless unknown.empty?
38
+
39
+ docs = data['docs'] || {}
40
+ raise ArgumentError, "#{path}: 'docs' must be an object" unless docs.is_a?(::Hash)
41
+
42
+ unknown_docs = docs.keys - KNOWN_DOCS_KEYS
43
+ raise ArgumentError, "#{path}: unknown docs key(s): #{unknown_docs.sort.join(', ')}" unless unknown_docs.empty?
44
+
45
+ snippets = data['snippets'] || {}
46
+ unless snippets.is_a?(::Hash) && snippets.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
47
+ raise ArgumentError, "#{path}: 'snippets' must be an object of strings"
48
+ end
49
+
50
+ VarConfig.new(
51
+ docs_include: string_array(docs['include'], 'docs.include', path),
52
+ docs_exclude: string_array(docs['exclude'], 'docs.exclude', path),
53
+ steps: string_array(data['steps'], 'steps', path),
54
+ snippets: snippets,
55
+ scanner_plugins: string_array(data['scannerPlugins'], 'scannerPlugins', path)
56
+ )
57
+ end
58
+
59
+ def string_array(value, key, path)
60
+ return [] if value.nil?
61
+ unless value.is_a?(Array) && value.all?(String)
62
+ raise ArgumentError, "#{path}: '#{key}' must be an array of strings"
63
+ end
64
+
65
+ value
66
+ end
67
+ end
68
+ end
69
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oselvar-var-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Aslak Hellesøy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Strict, fail-loud reader for the shared var.config.json format.
14
+ email:
15
+ - aslak@oselvar.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/oselvar/var/config.rb
21
+ homepage: https://var.oselvar.com
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ rubygems_mfa_required: 'true'
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '3.2'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.4.10
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Markdown-native BDD — var.config.json reader
45
+ test_files: []