king_konf 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/king_konf/config.rb +3 -5
- data/lib/king_konf/variable.rb +16 -15
- data/lib/king_konf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7097bd818496d31561799b6756a83779daade1ff0e7b6be133d2c287ad60e646
|
4
|
+
data.tar.gz: fbf115254e0d7bf1a906011624cee8daa43b97fcf5a1330a35f12cc2d973b450
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 643c92f40690416dc179f79e83617f0ff5f8cd40aaea2dc1f04b941ccec69c4ea2217ecaba7f8af2881bf90e1fa8f1458eafc439354bdd4b7f266c55ee3a917e
|
7
|
+
data.tar.gz: 2d858fffd1123d9282c705dc85ba090ab95f5ffee6e0e93a3945e87801e87103768a278b93531cf87392f2f8c8b7b904a6bce900c9ebabfaf4c15d269fe916a5
|
data/lib/king_konf/config.rb
CHANGED
@@ -100,15 +100,13 @@ module KingKonf
|
|
100
100
|
|
101
101
|
variable = self.class.variable(name)
|
102
102
|
|
103
|
-
|
104
|
-
raise ConfigError, "invalid value #{value.inspect} for variable `#{name}`, expected #{variable.type}"
|
105
|
-
end
|
103
|
+
cast_value = value.nil? ? nil : variable.cast(value)
|
106
104
|
|
107
|
-
if !variable.allowed?(
|
105
|
+
if !variable.allowed?(cast_value)
|
108
106
|
raise ConfigError, "invalid value #{value.inspect} for variable `#{name}`, allowed values are #{variable.allowed_values}"
|
109
107
|
end
|
110
108
|
|
111
|
-
instance_variable_set("@#{name}",
|
109
|
+
instance_variable_set("@#{name}", cast_value)
|
112
110
|
end
|
113
111
|
|
114
112
|
def validate!
|
data/lib/king_konf/variable.rb
CHANGED
@@ -10,16 +10,20 @@ module KingKonf
|
|
10
10
|
@required = required
|
11
11
|
@allowed_values = allowed_values
|
12
12
|
@options = options
|
13
|
-
@default = cast(default)
|
13
|
+
@default = cast(default) unless default.nil?
|
14
14
|
end
|
15
15
|
|
16
16
|
def cast(value)
|
17
17
|
case @type
|
18
|
-
when :
|
19
|
-
when :
|
20
|
-
when :
|
18
|
+
when :boolean then [true, false].include?(value) ? value : Decoder.boolean(value, **options)
|
19
|
+
when :integer then Integer(value)
|
20
|
+
when :float then Float(value)
|
21
|
+
when :duration then value.is_a?(Integer) ? value : Decoder.duration(value)
|
22
|
+
when :symbol then value.to_sym
|
21
23
|
else value
|
22
24
|
end
|
25
|
+
rescue ArgumentError, NoMethodError
|
26
|
+
raise ConfigError, "invalid value #{value.inspect} for variable `#{name}`, expected #{type}"
|
23
27
|
end
|
24
28
|
|
25
29
|
def required?
|
@@ -27,20 +31,17 @@ module KingKonf
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def valid?(value)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
when :duration then value.is_a?(Float) || value.is_a?(Integer) || value.is_a?(String) || value.nil?
|
36
|
-
when :boolean then value == true || value == false
|
37
|
-
when :symbol then value.is_a?(Symbol) || value.is_a?(String)
|
38
|
-
else raise "invalid type #{@type}"
|
39
|
-
end
|
34
|
+
cast(value)
|
35
|
+
rescue ConfigError
|
36
|
+
false
|
37
|
+
else
|
38
|
+
true
|
40
39
|
end
|
41
40
|
|
42
41
|
def allowed?(value)
|
43
|
-
allowed_values.nil? || allowed_values.include?(value)
|
42
|
+
allowed_values.nil? || allowed_values.include?(cast(value))
|
43
|
+
rescue ConfigError
|
44
|
+
false
|
44
45
|
end
|
45
46
|
|
46
47
|
def decode(value)
|
data/lib/king_konf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: king_konf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|