consult 1.0.0.pre → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0cf440030413aa3a130de66a00f1b349a232dfe0a56a8517c5fda6590bef31a
4
- data.tar.gz: 63e51ae272e2504f3be979d10a4d46c2d954210b68c6cb2584a481862f80f8c9
3
+ metadata.gz: 1c7a54f7fb838f2f50a3553e2f798b75d569cf227c4c9d927d2185d4b597f882
4
+ data.tar.gz: be503dd900d460f14d8ae2ecaddd6eec05193859b2668d32762dd62e3e2f4cb1
5
5
  SHA512:
6
- metadata.gz: 41891ee20a9018c7db6ed5c366a87273e5b58102813f3e7db6ff6c906b4ed7c390eaa898fdb6a5c9a849f399ca19753ca6c2541e20945a81ff309a2aa3a21e5b
7
- data.tar.gz: b3ad3e1a3d688292eecdbd2e2984fa347b5bae91024d9a5f65f2ec5ca340326ae336a8f9d0693c0c7978960912fb0c35d3eb2f5595b90733ecc218e54e65e48c
6
+ metadata.gz: f736a61ae78df99d70d778ec0a61bbaf6b702cc2e7d7b5e10f4a4c40682dd21cb72975cb49d6db28b502334b3027c793b17caa2b3a818f20fb05e52389a84a55
7
+ data.tar.gz: e786886e41c2a6c81b169c4d781465e422bae03b059b65dd6b156c8d30c2530c773157d752a150d569e514a56e6ccfa05b537f498d9bcc8c1078bdb336109688
data/CHANGELOG.md CHANGED
@@ -9,6 +9,7 @@
9
9
  * Development: adjust require's to be able to run CLI from any folder
10
10
  * Enable defining vars at the env block level, rather than only on template blocks
11
11
  * Create directories for rendered files as needed
12
+ * Add the `skip_missing_template` config for templates
12
13
 
13
14
  #### 0.11.0
14
15
 
data/README.md CHANGED
@@ -98,6 +98,13 @@ test:
98
98
  vars:
99
99
  test_specific_key: and_the_value
100
100
 
101
+ extra_test_config:
102
+ # normally there's an error for missing templates, but this can be allowed via config
103
+ skip_missing_template: true
104
+ # config files are also processed through ERB, so paths can be made dynamic
105
+ path: config/templates/<%= ENV['extra_test_file'] %>.yml
106
+ dest: config/extra_test_config.yml
107
+
101
108
  production:
102
109
  # vars can be defined at the environment level, which are available to these templates
103
110
  vars:
@@ -19,6 +19,10 @@ module Consult
19
19
  end
20
20
 
21
21
  def render(save: true)
22
+ if contents.empty? && @config[:skip_missing_template]
23
+ return
24
+ end
25
+
22
26
  # Attempt to render
23
27
  renderer = ERB.new(contents, nil, '-')
24
28
  result = renderer.result(binding)
@@ -76,20 +80,34 @@ module Consult
76
80
 
77
81
  # Concatenate all the source templates together, in the order provided
78
82
  def contents
79
- ordered_locations.map do |location|
83
+ @_contents ||= ordered_locations.map do |location|
80
84
  location.to_s.start_with?('consul') ? consul_contents(location) : disk_contents(location)
81
- end.join
85
+ end.compact.join
82
86
  end
83
87
 
84
88
  def consul_contents(location)
85
89
  [@config[location]].compact.flatten.map do |key|
86
- Diplomat::Kv.get(key, options: {}, not_found: :return, found: :return).force_encoding 'utf-8'
90
+ Diplomat::Kv.get(key, {}, :reject, :return).force_encoding 'utf-8'
91
+ rescue Diplomat::KeyNotFound
92
+ if @config[:skip_missing_template]
93
+ STDERR.puts "Consult: Skipping missing template: #{name}"
94
+ next
95
+ end
96
+
97
+ raise
87
98
  end.join
88
99
  end
89
100
 
90
101
  def disk_contents(location)
91
102
  [public_send(location)].compact.flatten.map do |file_path|
92
103
  File.read file_path, encoding: 'utf-8'
104
+ rescue Errno::ENOENT
105
+ if @config[:skip_missing_template]
106
+ STDERR.puts "Consult: Skipping missing template: #{name}"
107
+ next
108
+ end
109
+
110
+ raise
93
111
  end.join
94
112
  end
95
113
  end
@@ -1,3 +1,3 @@
1
1
  module Consult
2
- VERSION = '1.0.0.pre'
2
+ VERSION = '1.0.0.pre1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consult
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre
4
+ version: 1.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Fraser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-18 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diplomat