simple_scripting 0.11.0 → 0.11.1
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd6f01ad9ea507d97ac4024fa8e78feb1093e67f75b16d4ac5c5db79354caf18
|
4
|
+
data.tar.gz: a0a1ad4b67822086544890b54590af03a2877a7210f3198109d605a6fa772d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ee276b4af46f3746523f9ed11d7b11b4097f65c7139709506363708f1e6303ec1ead4d48c182f480918597272f2c1af92af6620920dad296967540c5b14105c
|
7
|
+
data.tar.gz: 9059bae5453cc7e64eeea88c8279167020bd7cae0c1b67337c4bf83acb055a0ab04b75c746e7c0ea6d2a9184a8b1df5af0754dcfff55a8ad8e9e2b2409c8fe59
|
@@ -10,11 +10,16 @@ module SimpleScripting
|
|
10
10
|
|
11
11
|
extend self
|
12
12
|
|
13
|
-
|
13
|
+
# `required`: list of strings. this currently support only keys outside a group; group names
|
14
|
+
# are not considered keys.
|
15
|
+
#
|
16
|
+
def load(config_file: default_config_file, passwords_key: nil, required: [])
|
14
17
|
create_empty_file(config_file) if !File.exists?(config_file)
|
15
18
|
|
16
19
|
configuration = ParseConfig.new(config_file)
|
17
20
|
|
21
|
+
enforce_required_keys(configuration.params, required)
|
22
|
+
|
18
23
|
convert_to_cool_format(OpenStruct.new, configuration.params, passwords_key)
|
19
24
|
end
|
20
25
|
|
@@ -30,6 +35,12 @@ module SimpleScripting
|
|
30
35
|
File.expand_path(base_config_filename, '~')
|
31
36
|
end
|
32
37
|
|
38
|
+
def enforce_required_keys(configuration, required)
|
39
|
+
missing_keys = required - configuration.select { |key, value| !value.is_a?(Hash) }.keys
|
40
|
+
|
41
|
+
raise "Missing required configuration key(s): #{missing_keys.join(', ')}" if !missing_keys.empty?
|
42
|
+
end
|
43
|
+
|
33
44
|
# Performs two conversions:
|
34
45
|
#
|
35
46
|
# 1. the configuration as a whole is converted to an OpenStruct
|
data/simple_scripting.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
11
11
|
s.required_ruby_version = '>= 2.3.0'
|
12
12
|
s.authors = ["Saverio Miroddi"]
|
13
|
-
s.date = "2019-03-
|
13
|
+
s.date = "2019-03-31"
|
14
14
|
s.email = ["saverio.pub2@gmail.com"]
|
15
15
|
s.homepage = "https://github.com/saveriomiroddi/simple_scripting"
|
16
16
|
s.summary = "Library for simplifying some typical scripting functionalities."
|
@@ -54,6 +54,14 @@ g2_key=bang
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should raise an error when required keys are missing" do
|
58
|
+
with_tempfile(configuration_text) do |config_file|
|
59
|
+
error_call = -> { described_class.load(config_file: config_file, required: %w(abspath_key missing_key group1)) }
|
60
|
+
|
61
|
+
expect(error_call).to raise_error(RuntimeError, "Missing required configuration key(s): missing_key, group1")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
57
65
|
it "should create the configuration file if it doesn't exist" do
|
58
66
|
temp_config_file = File.join(Dir.tmpdir, '.test_simple_scripting_config')
|
59
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_scripting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saverio Miroddi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parseconfig
|