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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/varar/config.rb +20 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b79fc32fa1f2cf69465aff1a8295d9575584dd696c2356518ad8fbc1b3bea5c
4
- data.tar.gz: 0dbaf2c855f4dc4ef6af59dfb397c66b71759462e3c825f47cd138a865f15685
3
+ metadata.gz: e93131e443101c0628a1e67d83ba68c197c95b254dd9800db6e413b3cb24ae71
4
+ data.tar.gz: 26a3c0a34a4971fd5ce0ed1802d0e95aa10281107a984041dc2d9f31a385bdd6
5
5
  SHA512:
6
- metadata.gz: 7dde8f0743dc917ef88952de2869be1f949d3689872ee98d8a9983834f3cacd010b1de75ac7d5876545e08934e2a3f0dca7d725ba424e3f7902394561e8d5d2f
7
- data.tar.gz: 03f20b75c8acb6e59cbb51fa17b90310554e6b0562d650bf206f1a9f4a0326570e2d1f82e3e916f971cf22b24b7108ca8454fd0905d446084e7714eb65fec0c1
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.7.0'
10
+ VERSION = '0.8.0'
11
11
 
12
12
  # The parsed config. All fields default to empty.
13
- VarConfig = Data.define(:docs_include, :docs_exclude, :steps, :snippets) do
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
- def read_var_config(root)
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 VarConfig.new unless File.file?(path)
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(File.read(path, encoding: 'UTF-8'))
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
- VarConfig.new(
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),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varar-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy