varar-config 0.7.0 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/varar/config.rb +20 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e93131e443101c0628a1e67d83ba68c197c95b254dd9800db6e413b3cb24ae71
|
|
4
|
+
data.tar.gz: 26a3c0a34a4971fd5ce0ed1802d0e95aa10281107a984041dc2d9f31a385bdd6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e85adc5c52174eed20ace4087a264bc09653fb03e33dc84e39f59f73a76db8eed7c83425ab399aa14b4b4a3f7e04643cd5c506832d3b26163e43aed1bcfe9d64
|
|
7
|
+
data.tar.gz: 72607b0a9fc533cf644dbaabedc7020836b84ee0a5f12454ed4ee1ce3931fb9ef0269aa90739a0b76ebed3ca59b6e02eeb7f6ec652c39f9caa67e0773d9a8e41
|
data/lib/varar/config.rb
CHANGED
|
@@ -7,10 +7,10 @@ module Varar
|
|
|
7
7
|
# file → empty config; malformed JSON, wrong types, or unknown keys → an
|
|
8
8
|
# error starting with the file path. See conformance/config/README.md.
|
|
9
9
|
module Config
|
|
10
|
-
VERSION = '0.
|
|
10
|
+
VERSION = '0.8.0'
|
|
11
11
|
|
|
12
12
|
# The parsed config. All fields default to empty.
|
|
13
|
-
|
|
13
|
+
Config = Data.define(:docs_include, :docs_exclude, :steps, :snippets) do
|
|
14
14
|
def initialize(docs_include: [], docs_exclude: [], steps: [], snippets: {})
|
|
15
15
|
super
|
|
16
16
|
end
|
|
@@ -21,12 +21,26 @@ module Varar
|
|
|
21
21
|
|
|
22
22
|
module_function
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
# Read <root>/varar.config.json. The filesystem edge over #parse_config;
|
|
25
|
+
# a missing file yields the empty config (tools no-op, as in every port).
|
|
26
|
+
def read_config(root)
|
|
25
27
|
path = File.join(root.to_s, 'varar.config.json')
|
|
26
|
-
return
|
|
28
|
+
return Config.new unless File.file?(path)
|
|
27
29
|
|
|
30
|
+
parse_config(File.read(path, encoding: 'UTF-8'), path)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Parse varar.config.json TEXT. Pure — no filesystem.
|
|
34
|
+
#
|
|
35
|
+
# +source+ only labels errors (a path, a URL, '<memory>'); nothing is read
|
|
36
|
+
# from it. Splitting this out from #read_config is what lets a caller
|
|
37
|
+
# with the text already in hand — an editor buffer, an in-memory fixture,
|
|
38
|
+
# the LSP — validate it without inventing a file, and mirrors TypeScript's
|
|
39
|
+
# parseConfig / Java's Config.parse.
|
|
40
|
+
def parse_config(text, source)
|
|
41
|
+
path = source
|
|
28
42
|
data = begin
|
|
29
|
-
JSON.parse(
|
|
43
|
+
JSON.parse(text)
|
|
30
44
|
rescue JSON::ParserError => e
|
|
31
45
|
raise ArgumentError, "#{path}: invalid JSON: #{e.message}"
|
|
32
46
|
end
|
|
@@ -46,7 +60,7 @@ module Varar
|
|
|
46
60
|
raise ArgumentError, "#{path}: 'snippets' must be an object of strings"
|
|
47
61
|
end
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
Config.new(
|
|
50
64
|
docs_include: string_array(docs['include'], 'docs.include', path),
|
|
51
65
|
docs_exclude: string_array(docs['exclude'], 'docs.exclude', path),
|
|
52
66
|
steps: string_array(data['steps'], 'steps', path),
|