varar-config 0.5.0

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/varar/config.rb +67 -0
  3. metadata +42 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c2c0da492569d54a8b33324db73cc6019de71d7ff09c8036227c0e7b04533fc
4
+ data.tar.gz: 5e174fa1a9fa0b8d70d8a389e67e9d9be2021d2a25334d0e34a87bb0d35d5c18
5
+ SHA512:
6
+ metadata.gz: c8a08392f6626526013badf54370564a4bb4c40ce237d8aeb55ebd191bcbe9f806b55c325f1813f9be97e72347424e2740b5d263fe6dac2d9315466b701394ce
7
+ data.tar.gz: 67e1e9d43475caf0d9eaa0e8b986c2634bcfd1259ca0f389b2540929e1a47eca867d878f34af501c0b4ddec7dda708a2a9fb393c76fdcaf814170de818ca75d3
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Varar
6
+ # Strict, fail-loud reader for the shared varar.config.json format. Missing
7
+ # file → empty config; malformed JSON, wrong types, or unknown keys → an
8
+ # error starting with the file path. See conformance/config/README.md.
9
+ module Config
10
+ VERSION = '0.5.0'
11
+
12
+ # The parsed config. All fields default to empty.
13
+ VarConfig = Data.define(:docs_include, :docs_exclude, :steps, :snippets, :scanner_plugins) do
14
+ def initialize(docs_include: [], docs_exclude: [], steps: [], snippets: {}, scanner_plugins: [])
15
+ super
16
+ end
17
+ end
18
+
19
+ KNOWN_KEYS = %w[$schema docs steps snippets scannerPlugins].freeze
20
+ KNOWN_DOCS_KEYS = %w[include exclude].freeze
21
+
22
+ module_function
23
+
24
+ def read_var_config(root)
25
+ path = File.join(root.to_s, 'varar.config.json')
26
+ return VarConfig.new unless File.file?(path)
27
+
28
+ data = begin
29
+ JSON.parse(File.read(path, encoding: 'UTF-8'))
30
+ rescue JSON::ParserError => e
31
+ raise ArgumentError, "#{path}: invalid JSON: #{e.message}"
32
+ end
33
+ raise ArgumentError, "#{path}: top level must be an object" unless data.is_a?(::Hash)
34
+
35
+ unknown = data.keys - KNOWN_KEYS
36
+ raise ArgumentError, "#{path}: unknown key(s): #{unknown.sort.join(', ')}" unless unknown.empty?
37
+
38
+ docs = data['docs'] || {}
39
+ raise ArgumentError, "#{path}: 'docs' must be an object" unless docs.is_a?(::Hash)
40
+
41
+ unknown_docs = docs.keys - KNOWN_DOCS_KEYS
42
+ raise ArgumentError, "#{path}: unknown docs key(s): #{unknown_docs.sort.join(', ')}" unless unknown_docs.empty?
43
+
44
+ snippets = data['snippets'] || {}
45
+ unless snippets.is_a?(::Hash) && snippets.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
46
+ raise ArgumentError, "#{path}: 'snippets' must be an object of strings"
47
+ end
48
+
49
+ VarConfig.new(
50
+ docs_include: string_array(docs['include'], 'docs.include', path),
51
+ docs_exclude: string_array(docs['exclude'], 'docs.exclude', path),
52
+ steps: string_array(data['steps'], 'steps', path),
53
+ snippets: snippets,
54
+ scanner_plugins: string_array(data['scannerPlugins'], 'scannerPlugins', path)
55
+ )
56
+ end
57
+
58
+ def string_array(value, key, path)
59
+ return [] if value.nil?
60
+ unless value.is_a?(Array) && value.all?(String)
61
+ raise ArgumentError, "#{path}: '#{key}' must be an array of strings"
62
+ end
63
+
64
+ value
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,42 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: varar-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Aslak Hellesøy
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Strict, fail-loud reader for the shared varar.config.json format.
13
+ email:
14
+ - aslak@oselvar.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/varar/config.rb
20
+ homepage: https://varar.dev
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ rubygems_mfa_required: 'true'
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 4.0.16
40
+ specification_version: 4
41
+ summary: Markdown-native BDD — varar.config.json reader
42
+ test_files: []