legion-settings 0.1.1 → 0.2.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/.circleci/config.yml +34 -140
- data/.rubocop.yml +3 -5
- data/CHANGELOG.md +4 -0
- data/legion-settings.gemspec +5 -4
- data/lib/legion/settings.rb +10 -1
- data/lib/legion/settings/loader.rb +32 -33
- data/lib/legion/settings/rules.rb +3 -81
- data/lib/legion/settings/validator.rb +0 -17
- data/lib/legion/settings/validators/legion.rb +0 -8
- data/lib/legion/settings/version.rb +1 -1
- metadata +30 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88c48b0708d96f97993a42390a6c6d6d17a8e24394dee86b42d876b37ea26698
|
|
4
|
+
data.tar.gz: 04e4a033cb797c6bee0a9e63062ad8a43dc0cbaeeaee4a8a7124f90dee608967
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f4a84d333b9fda8e729f2090eb68da8a65d79e01a4a17286eb97ebb2dd13836746afcd8ec4ef012857599539b23a5de71d313010178cfc650f862c40e2dddc6
|
|
7
|
+
data.tar.gz: 50afc947274be3acbe9d56fb359f51ee044e93a3c7fcfb8ff53d9c05c2a888ed9d97aa375ff6d4691e8f5ed10a32d0deab66a96cf8ea4d3b3a4cb2def6282e5a
|
data/.circleci/config.yml
CHANGED
|
@@ -1,167 +1,61 @@
|
|
|
1
|
-
version: 2.1
|
|
1
|
+
version: 2.1
|
|
2
|
+
orbs:
|
|
3
|
+
ruby: circleci/ruby@0.2.1
|
|
4
|
+
|
|
2
5
|
jobs:
|
|
3
6
|
"rubocop":
|
|
4
7
|
docker:
|
|
5
|
-
- image: circleci/ruby:2.
|
|
8
|
+
- image: circleci/ruby:2.5-node
|
|
6
9
|
steps:
|
|
7
10
|
- checkout
|
|
8
|
-
-
|
|
11
|
+
- ruby/load-cache
|
|
12
|
+
- ruby/install-deps
|
|
9
13
|
- run:
|
|
10
14
|
name: Run Rubocop
|
|
11
|
-
command: rubocop
|
|
12
|
-
-
|
|
13
|
-
path: test_results
|
|
14
|
-
"ruby-two-zero":
|
|
15
|
-
docker:
|
|
16
|
-
- image: circleci/ruby:2.0
|
|
17
|
-
steps:
|
|
18
|
-
- checkout
|
|
19
|
-
- run:
|
|
20
|
-
name: Bundle Install
|
|
21
|
-
command: bundle install
|
|
22
|
-
- run:
|
|
23
|
-
name: Run RSpec
|
|
24
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
25
|
-
when: always
|
|
26
|
-
- store_test_results:
|
|
27
|
-
path: test-results
|
|
28
|
-
"ruby-two-one":
|
|
29
|
-
docker:
|
|
30
|
-
- image: circleci/ruby:2.1
|
|
31
|
-
steps:
|
|
32
|
-
- checkout
|
|
33
|
-
- run:
|
|
34
|
-
name: Bundle Install
|
|
35
|
-
command: bundle install
|
|
36
|
-
- run:
|
|
37
|
-
name: Run RSpec
|
|
38
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
39
|
-
when: always
|
|
40
|
-
- store_test_results:
|
|
41
|
-
path: test-results
|
|
42
|
-
"ruby-two-two":
|
|
43
|
-
docker:
|
|
44
|
-
- image: circleci/ruby:2.2
|
|
45
|
-
steps:
|
|
46
|
-
- checkout
|
|
47
|
-
- run:
|
|
48
|
-
name: Bundle Install
|
|
49
|
-
command: bundle install
|
|
50
|
-
- run:
|
|
51
|
-
name: Run RSpec
|
|
52
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
53
|
-
when: always
|
|
54
|
-
- store_test_results:
|
|
55
|
-
path: test-results
|
|
56
|
-
|
|
57
|
-
"ruby-two-three":
|
|
58
|
-
docker:
|
|
59
|
-
- image: circleci/ruby:2.3
|
|
60
|
-
steps:
|
|
61
|
-
- checkout
|
|
62
|
-
- run:
|
|
63
|
-
name: Bundle Install
|
|
64
|
-
command: bundle install
|
|
65
|
-
- run:
|
|
66
|
-
name: Run RSpec
|
|
67
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
68
|
-
when: always
|
|
69
|
-
- store_test_results:
|
|
70
|
-
path: test-results
|
|
71
|
-
|
|
72
|
-
"ruby-two-four":
|
|
73
|
-
docker:
|
|
74
|
-
- image: circleci/ruby:2.4-node
|
|
75
|
-
steps:
|
|
76
|
-
- checkout
|
|
77
|
-
- run:
|
|
78
|
-
name: Bundle Install
|
|
79
|
-
command: bundle install
|
|
80
|
-
- run:
|
|
81
|
-
name: Run RSpec
|
|
82
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
83
|
-
when: always
|
|
84
|
-
- store_test_results:
|
|
85
|
-
path: test-results
|
|
15
|
+
command: bundle exec rubocop
|
|
16
|
+
- ruby/save-cache
|
|
86
17
|
"ruby-two-five":
|
|
87
18
|
docker:
|
|
88
|
-
- image: circleci/ruby:2.5
|
|
19
|
+
- image: circleci/ruby:2.5
|
|
20
|
+
- image: memcached:1.5-alpine
|
|
89
21
|
steps:
|
|
90
22
|
- checkout
|
|
91
|
-
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
-
|
|
95
|
-
name: Run RSpec
|
|
96
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
97
|
-
when: always
|
|
98
|
-
- store_test_results:
|
|
99
|
-
path: test-results
|
|
23
|
+
- ruby/load-cache
|
|
24
|
+
- ruby/install-deps
|
|
25
|
+
- ruby/run-tests
|
|
26
|
+
- ruby/save-cache
|
|
100
27
|
"ruby-two-six":
|
|
101
28
|
docker:
|
|
102
|
-
- image: circleci/ruby:2.6
|
|
29
|
+
- image: circleci/ruby:2.6
|
|
30
|
+
- image: memcached:1.5-alpine
|
|
103
31
|
steps:
|
|
104
32
|
- checkout
|
|
105
|
-
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
-
|
|
109
|
-
|
|
110
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
111
|
-
when: always
|
|
112
|
-
- store_test_results:
|
|
113
|
-
path: test-results
|
|
114
|
-
"jruby-nine-two":
|
|
33
|
+
- ruby/load-cache
|
|
34
|
+
- ruby/install-deps
|
|
35
|
+
- ruby/run-tests
|
|
36
|
+
- ruby/save-cache
|
|
37
|
+
"ruby-two-seven":
|
|
115
38
|
docker:
|
|
116
|
-
- image: circleci/
|
|
39
|
+
- image: circleci/ruby:2.7
|
|
40
|
+
- image: memcached:1.5-alpine
|
|
117
41
|
steps:
|
|
118
42
|
- checkout
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
-
|
|
123
|
-
name: Run RSpec
|
|
124
|
-
command: bundle exec rspec --format progress --format RspecJunitFormatter -o test-results/rspec/results.xml
|
|
125
|
-
when: always
|
|
126
|
-
- store_test_results:
|
|
127
|
-
path: test-results
|
|
43
|
+
- ruby/load-cache
|
|
44
|
+
- ruby/install-deps
|
|
45
|
+
- ruby/run-tests
|
|
46
|
+
- ruby/save-cache
|
|
128
47
|
|
|
129
48
|
workflows:
|
|
130
49
|
version: 2
|
|
131
|
-
|
|
50
|
+
rubocop-rspec:
|
|
132
51
|
jobs:
|
|
133
52
|
- rubocop
|
|
134
|
-
# - ruby-two-two:
|
|
135
|
-
# requires:
|
|
136
|
-
# - ruby-two-four
|
|
137
|
-
# filters:
|
|
138
|
-
# branches:
|
|
139
|
-
# only: /\bdevelop\b|\bmaster\b/
|
|
140
|
-
- ruby-two-three:
|
|
141
|
-
requires:
|
|
142
|
-
- ruby-two-four
|
|
143
|
-
filters:
|
|
144
|
-
branches:
|
|
145
|
-
only: /\bdevelop\b|\bmaster\b/
|
|
146
|
-
- ruby-two-four:
|
|
147
|
-
requires:
|
|
148
|
-
- rubocop
|
|
149
53
|
- ruby-two-five:
|
|
150
54
|
requires:
|
|
151
|
-
-
|
|
152
|
-
filters:
|
|
153
|
-
branches:
|
|
154
|
-
only: /\bdevelop\b|\bmaster\b/
|
|
55
|
+
- rubocop
|
|
155
56
|
- ruby-two-six:
|
|
156
57
|
requires:
|
|
157
|
-
- ruby-two-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
# - jruby-nine-two:
|
|
162
|
-
# requires:
|
|
163
|
-
# - ruby-two-two
|
|
164
|
-
# - ruby-two-three
|
|
165
|
-
# - ruby-two-four
|
|
166
|
-
# - ruby-two-five
|
|
167
|
-
# - ruby-two-six
|
|
58
|
+
- ruby-two-five
|
|
59
|
+
- ruby-two-seven:
|
|
60
|
+
requires:
|
|
61
|
+
- ruby-two-five
|
data/.rubocop.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Layout/LineLength:
|
|
2
2
|
Max: 120
|
|
3
3
|
Metrics/MethodLength:
|
|
4
4
|
Max: 30
|
|
@@ -10,15 +10,13 @@ Layout/SpaceAroundEqualsInParameterDefault:
|
|
|
10
10
|
EnforcedStyle: space
|
|
11
11
|
Style/SymbolArray:
|
|
12
12
|
Enabled: true
|
|
13
|
-
Layout/
|
|
13
|
+
Layout/HashAlignment:
|
|
14
14
|
EnforcedHashRocketStyle: table
|
|
15
15
|
EnforcedColonStyle: table
|
|
16
|
-
Style/HashSyntax:
|
|
17
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
|
18
16
|
Style/Documentation:
|
|
19
17
|
Enabled: false
|
|
20
18
|
AllCops:
|
|
21
|
-
TargetRubyVersion: 2.
|
|
19
|
+
TargetRubyVersion: 2.5
|
|
22
20
|
Style/FrozenStringLiteralComment:
|
|
23
21
|
Enabled: false
|
|
24
22
|
Naming/FileName:
|
data/CHANGELOG.md
CHANGED
data/legion-settings.gemspec
CHANGED
|
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
21
|
spec.require_paths = ['lib']
|
|
22
22
|
|
|
23
|
-
spec.add_development_dependency 'bundler'
|
|
23
|
+
spec.add_development_dependency 'bundler'
|
|
24
24
|
# spec.add_development_dependency 'codecov', '~> 0'
|
|
25
|
-
spec.add_development_dependency 'rake'
|
|
26
|
-
spec.add_development_dependency 'rspec'
|
|
27
|
-
spec.add_development_dependency 'rspec_junit_formatter'
|
|
25
|
+
spec.add_development_dependency 'rake'
|
|
26
|
+
spec.add_development_dependency 'rspec'
|
|
27
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
|
28
|
+
spec.add_development_dependency 'rubocop'
|
|
28
29
|
if RUBY_ENGINE == 'jruby'
|
|
29
30
|
spec.add_dependency('legion-json-jruby', '~> 0.1')
|
|
30
31
|
else
|
data/lib/legion/settings.rb
CHANGED
|
@@ -26,13 +26,22 @@ module Legion
|
|
|
26
26
|
Legion::Logging.info('Legion::Settings was not loading, auto loading now!') if @loader.nil?
|
|
27
27
|
@loader = load if @loader.nil?
|
|
28
28
|
@loader[key]
|
|
29
|
+
rescue NoMethodError, TypeError
|
|
30
|
+
Legion::Logging.fatal 'rescue inside [](key)'
|
|
31
|
+
nil
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
def set_prop(key, value)
|
|
32
|
-
Legion::Logging.info('Legion::Settings was not loading, auto loading now!') if @loader.nil?
|
|
33
35
|
@loader = load if @loader.nil?
|
|
34
36
|
@loader[key] = value
|
|
35
37
|
end
|
|
38
|
+
|
|
39
|
+
def merge_settings(key, hash)
|
|
40
|
+
@loader = load if @loader.nil?
|
|
41
|
+
thing = {}
|
|
42
|
+
thing[key.to_sym] = hash
|
|
43
|
+
@loader.load_module_default(thing)
|
|
44
|
+
end
|
|
36
45
|
end
|
|
37
46
|
end
|
|
38
47
|
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
require 'socket'
|
|
2
|
+
|
|
1
3
|
module Legion
|
|
2
4
|
module Settings
|
|
3
|
-
# This is the main settings class, needs refactor
|
|
4
5
|
class Loader
|
|
5
|
-
# This is the standard error
|
|
6
6
|
class Error < RuntimeError; end
|
|
7
7
|
|
|
8
8
|
attr_reader :warnings
|
|
9
9
|
attr_reader :errors
|
|
10
10
|
attr_reader :loaded_files
|
|
11
|
+
attr_reader :settings
|
|
11
12
|
|
|
12
13
|
def initialize
|
|
13
14
|
@warnings = []
|
|
@@ -20,43 +21,35 @@ module Legion
|
|
|
20
21
|
|
|
21
22
|
def client_defaults
|
|
22
23
|
{
|
|
23
|
-
|
|
24
|
-
address:
|
|
24
|
+
hostname: system_hostname,
|
|
25
|
+
address: system_address,
|
|
26
|
+
name: "#{::Socket.gethostname.gsub('.', '_')}.#{::Process.pid}"
|
|
25
27
|
}
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
def default_settings
|
|
29
|
-
|
|
30
|
-
client:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
def default_settings
|
|
31
|
+
{
|
|
32
|
+
client: client_defaults,
|
|
33
|
+
cluster: { public_keys: {} },
|
|
34
|
+
crypt: {
|
|
35
|
+
cluster_secret: nil,
|
|
36
|
+
cluster_secret_timeout: 5,
|
|
37
|
+
vault: { connected: false }
|
|
38
|
+
},
|
|
39
|
+
cache: { enabled: true, connected: false, driver: 'dalli' },
|
|
40
|
+
extensions: {},
|
|
41
|
+
default_extension_settings: {
|
|
42
|
+
logger: { level: 'info', trace: false, extended: false }
|
|
36
43
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
44
|
+
logging: {
|
|
45
|
+
level: 'debug',
|
|
46
|
+
location: 'stdout',
|
|
47
|
+
trace: true,
|
|
48
|
+
backtrace_logging: true
|
|
43
49
|
},
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
user: 'legion',
|
|
47
|
-
password: 'legion',
|
|
48
|
-
max_connections: 20,
|
|
49
|
-
database: 'legion',
|
|
50
|
-
host: '127.0.0.1',
|
|
51
|
-
debug: false
|
|
52
|
-
},
|
|
53
|
-
models: {},
|
|
54
|
-
connection: {},
|
|
55
|
-
migrations: { continue_on_fail: false }
|
|
56
|
-
}
|
|
50
|
+
transport: { connected: false },
|
|
51
|
+
data: { connected: false }
|
|
57
52
|
}
|
|
58
|
-
default[:client] = client_defaults if %w[client rspec].include?(legion_service_name)
|
|
59
|
-
default
|
|
60
53
|
end
|
|
61
54
|
|
|
62
55
|
def self.create_category_methods
|
|
@@ -103,6 +96,12 @@ module Legion
|
|
|
103
96
|
load_api_env
|
|
104
97
|
end
|
|
105
98
|
|
|
99
|
+
def load_module_default(config)
|
|
100
|
+
merged = deep_merge(@settings, config)
|
|
101
|
+
deep_diff(@settings, merged) unless @loaded_files.empty?
|
|
102
|
+
@settings = merged
|
|
103
|
+
end
|
|
104
|
+
|
|
106
105
|
def load_file(file) # rubocop:disable Metrics/AbcSize
|
|
107
106
|
Legion::Logging.debug("Trying to load file #{file}")
|
|
108
107
|
if File.file?(file) && File.readable?(file)
|
|
@@ -1,120 +1,62 @@
|
|
|
1
1
|
module Legion
|
|
2
2
|
module Settings
|
|
3
3
|
module Rules
|
|
4
|
-
# Check that a value is a hash.
|
|
5
|
-
#
|
|
6
|
-
# @param value [Object] to check.
|
|
7
|
-
# @return [TrueClass, FalseClass]
|
|
8
4
|
def must_be_a_hash(value)
|
|
9
5
|
value.is_a?(Hash)
|
|
10
6
|
end
|
|
11
7
|
alias is_a_hash? must_be_a_hash
|
|
12
8
|
|
|
13
|
-
# Check that a value is a hash, if set (not nil).
|
|
14
|
-
#
|
|
15
|
-
# @param value [Object] to check.
|
|
16
|
-
# @return [TrueClass, FalseClass]
|
|
17
9
|
def must_be_a_hash_if_set(value)
|
|
18
10
|
value.nil? ? true : must_be_a_hash(value)
|
|
19
11
|
end
|
|
20
12
|
|
|
21
|
-
# Check that a value is an array.
|
|
22
|
-
#
|
|
23
|
-
# @param value [Object] to check.
|
|
24
|
-
# @return [TrueClass, FalseClass]
|
|
25
13
|
def must_be_an_array(value)
|
|
26
14
|
value.is_a?(Array)
|
|
27
15
|
end
|
|
28
16
|
alias is_an_array? must_be_an_array
|
|
29
17
|
|
|
30
|
-
# Check that a value is an array, if set (not nil).
|
|
31
|
-
#
|
|
32
|
-
# @param value [Object] to check.
|
|
33
|
-
# @return [TrueClass, FalseClass]
|
|
34
18
|
def must_be_an_array_if_set(value)
|
|
35
19
|
value.nil? ? true : must_be_an_array(value)
|
|
36
20
|
end
|
|
37
21
|
|
|
38
|
-
# Check that a value is a string.
|
|
39
|
-
#
|
|
40
|
-
# @param value [Object] to check.
|
|
41
|
-
# @return [TrueClass, FalseClass]
|
|
42
22
|
def must_be_a_string(value)
|
|
43
23
|
value.is_a?(String)
|
|
44
24
|
end
|
|
45
25
|
alias is_a_string? must_be_a_string
|
|
46
26
|
|
|
47
|
-
# Check that a value is a string, if set (not nil).
|
|
48
|
-
#
|
|
49
|
-
# @param value [Object] to check.
|
|
50
|
-
# @return [TrueClass, FalseClass]
|
|
51
27
|
def must_be_a_string_if_set(value)
|
|
52
28
|
value.nil? ? true : must_be_a_string(value)
|
|
53
29
|
end
|
|
54
30
|
|
|
55
|
-
# Check that a value is an integer.
|
|
56
|
-
#
|
|
57
|
-
# @param value [Object] to check.
|
|
58
|
-
# @return [TrueClass, FalseClass]
|
|
59
31
|
def must_be_an_integer(value)
|
|
60
32
|
value.is_a?(Integer)
|
|
61
33
|
end
|
|
62
34
|
alias is_an_integer? must_be_an_integer
|
|
63
35
|
|
|
64
|
-
# Check that a value is an integer, if set (not nil).
|
|
65
|
-
#
|
|
66
|
-
# @param value [Object] to check.
|
|
67
|
-
# @return [TrueClass, FalseClass]
|
|
68
36
|
def must_be_an_integer_if_set(value)
|
|
69
37
|
value.nil? ? true : must_be_an_integer(value)
|
|
70
38
|
end
|
|
71
39
|
|
|
72
|
-
# Check that a value is numeric.
|
|
73
|
-
#
|
|
74
|
-
# @param value [Object] to check.
|
|
75
|
-
# @return [TrueClass, FalseClass]
|
|
76
40
|
def must_be_a_numeric(value)
|
|
77
41
|
value.is_a?(Numeric)
|
|
78
42
|
end
|
|
79
43
|
|
|
80
|
-
# Check that a value is numeric, if set (not nil).
|
|
81
|
-
#
|
|
82
|
-
# @param value [Object] to check.
|
|
83
|
-
# @return [TrueClass, FalseClass]
|
|
84
44
|
def must_be_a_numeric_if_set(value)
|
|
85
45
|
value.nil? ? true : must_be_a_numeric(value)
|
|
86
46
|
end
|
|
87
47
|
|
|
88
|
-
# Check that a value matches a regular expression.
|
|
89
|
-
#
|
|
90
|
-
# @param regex [Regexp] pattern to compare with value.
|
|
91
|
-
# @param value [Object] to check if matches pattern.
|
|
92
|
-
# @return [TrueClass, FalseClass]
|
|
93
48
|
def must_match_regex(regex, value)
|
|
94
49
|
(value =~ regex).zero?
|
|
95
50
|
end
|
|
96
51
|
|
|
97
|
-
# Check if a value is boolean.
|
|
98
|
-
#
|
|
99
|
-
# @param value [Object] to check.
|
|
100
|
-
# @return [TrueClass, FalseClass]
|
|
101
52
|
def must_be_boolean(value)
|
|
102
53
|
!value.nil?
|
|
103
54
|
end
|
|
104
55
|
|
|
105
|
-
# Check if a value is boolean, if set (no nil).
|
|
106
|
-
#
|
|
107
|
-
# @param value [Object] to check.
|
|
108
|
-
# @return [TrueClass, FalseClass]
|
|
109
56
|
def must_be_boolean_if_set(value)
|
|
110
57
|
value.nil? ? true : must_be_boolean(value)
|
|
111
58
|
end
|
|
112
59
|
|
|
113
|
-
# Check that value items are all strings and not empty.
|
|
114
|
-
#
|
|
115
|
-
# @param value [Array] with items to check.
|
|
116
|
-
# @param regex [Regexp] to validate string items with.
|
|
117
|
-
# @return [TrueClass, FalseClass]
|
|
118
60
|
def items_must_be_strings(value, regex = nil)
|
|
119
61
|
value.all? do |item|
|
|
120
62
|
item.is_a?(String) && !item.empty? &&
|
|
@@ -122,46 +64,26 @@ module Legion
|
|
|
122
64
|
end
|
|
123
65
|
end
|
|
124
66
|
|
|
125
|
-
# Check if either of the values are set (not nil).
|
|
126
|
-
#
|
|
127
|
-
# @param values [Array<Object>] to check if not nil.
|
|
128
|
-
# @return [TrueClass, FalseClass]
|
|
129
67
|
def either_are_set?(*values)
|
|
130
68
|
values.any? do |value|
|
|
131
69
|
!value.nil?
|
|
132
70
|
end
|
|
133
71
|
end
|
|
134
72
|
|
|
135
|
-
# Check if values are valid times (can be parsed).
|
|
136
|
-
#
|
|
137
|
-
# @param values [Array<Object>] to check if valid time.
|
|
138
|
-
# @return [TrueClass, FalseClass]
|
|
139
73
|
def must_be_time(*values)
|
|
140
74
|
values.all? do |value|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
false
|
|
145
|
-
end
|
|
75
|
+
Time.parse(value)
|
|
76
|
+
rescue StandardError
|
|
77
|
+
false
|
|
146
78
|
end
|
|
147
79
|
end
|
|
148
80
|
|
|
149
|
-
# Check if values are allowed.
|
|
150
|
-
#
|
|
151
|
-
# @param allowed [Array<Object>] allowed values.
|
|
152
|
-
# @param values [Array<Object>] to check if allowed.
|
|
153
|
-
# @return [TrueClass, FalseClass]
|
|
154
81
|
def must_be_either(allowed, *values)
|
|
155
82
|
values.flatten.all? do |value|
|
|
156
83
|
allowed.include?(value)
|
|
157
84
|
end
|
|
158
85
|
end
|
|
159
86
|
|
|
160
|
-
# Check if values are allowed, if set (not nil).
|
|
161
|
-
#
|
|
162
|
-
# @param allowed [Array<Object>] allowed values.
|
|
163
|
-
# @param values [Array<Object>] to check if allowed.
|
|
164
|
-
# @return [TrueClass, FalseClass]
|
|
165
87
|
def must_be_either_if_set(allowed, *values)
|
|
166
88
|
values[0].nil? ? true : must_be_either(allowed, values)
|
|
167
89
|
end
|
|
@@ -8,19 +8,12 @@ module Legion
|
|
|
8
8
|
include Rules
|
|
9
9
|
include Validators
|
|
10
10
|
|
|
11
|
-
# @!attribute [r] failures
|
|
12
|
-
# @return [Array] validation failures.
|
|
13
11
|
attr_reader :failures
|
|
14
12
|
|
|
15
13
|
def initialize
|
|
16
14
|
@failures = []
|
|
17
15
|
end
|
|
18
16
|
|
|
19
|
-
# Run the validator.
|
|
20
|
-
#
|
|
21
|
-
# @param settings [Hash] legion settings to validate.
|
|
22
|
-
# @param service [String] legion service to validate for.
|
|
23
|
-
# @return [Array] validation failures.
|
|
24
17
|
def run(settings, service = nil)
|
|
25
18
|
validate_legion(settings[:legion])
|
|
26
19
|
validate_transport(settings[:transport])
|
|
@@ -46,10 +39,6 @@ module Legion
|
|
|
46
39
|
|
|
47
40
|
private
|
|
48
41
|
|
|
49
|
-
# Validate setting categories: checks, filters, mutators, and
|
|
50
|
-
# handlers.
|
|
51
|
-
#
|
|
52
|
-
# @param settings [Hash] legion settings to validate.
|
|
53
42
|
def validate_categories(settings)
|
|
54
43
|
CATEGORIES.each do |category|
|
|
55
44
|
if is_a_hash?(settings[category])
|
|
@@ -63,12 +52,6 @@ module Legion
|
|
|
63
52
|
end
|
|
64
53
|
end
|
|
65
54
|
|
|
66
|
-
# Record an invalid object with a message.
|
|
67
|
-
#
|
|
68
|
-
# @param object [Object] invalid object.
|
|
69
|
-
# @param message [String] message explaining why the object is
|
|
70
|
-
# invalid.
|
|
71
|
-
# @return [Array] current validation failures.
|
|
72
55
|
def invalid(object, message)
|
|
73
56
|
@failures << {
|
|
74
57
|
object: object,
|
|
@@ -2,10 +2,6 @@ module Legion
|
|
|
2
2
|
module Settings
|
|
3
3
|
module Validators
|
|
4
4
|
module Legion
|
|
5
|
-
# Validate Legion spawn.
|
|
6
|
-
# Validates: limit
|
|
7
|
-
#
|
|
8
|
-
# @param legion [Hash] legion definition.
|
|
9
5
|
def validate_legion_spawn(legion)
|
|
10
6
|
spawn = legion[:spawn]
|
|
11
7
|
if is_a_hash?(spawn)
|
|
@@ -20,10 +16,6 @@ module Legion
|
|
|
20
16
|
end
|
|
21
17
|
end
|
|
22
18
|
|
|
23
|
-
# Validate a Legion definition.
|
|
24
|
-
# Validates: spawn
|
|
25
|
-
#
|
|
26
|
-
# @param legion [Hash] legion definition.
|
|
27
19
|
def validate_legion(legion)
|
|
28
20
|
if is_a_hash?(legion)
|
|
29
21
|
validate_legion_spawn(legion)
|
metadata
CHANGED
|
@@ -1,69 +1,83 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: legion-settings
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :development
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: rake
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: rspec_junit_formatter
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
67
81
|
- !ruby/object:Gem::Version
|
|
68
82
|
version: '0'
|
|
69
83
|
- !ruby/object:Gem::Dependency
|