king_konf 0.3.0 → 0.3.1
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/variable.rb +4 -1
- data/lib/king_konf/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 545014c7184c51ce8ee6f2ce007d46421654599624a1423c28bb2fd34fe8d607
|
4
|
+
data.tar.gz: 2213d1e4f21082535d2af4ee6423037da2002fca60c65bbaa5dd2be46dd05042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb78c49ef8da922d5d03c5cd2da6888bcdd2d15a60ce10ffa843c0b6e3512a29eee4ef83aee33db2b426798524740c77e2f9d771baa0c7c1e3c51a6619fa7a6
|
7
|
+
data.tar.gz: '009c44e61c6176a57b05be827659bcb1164677924d4095a0222a54de6d2c0272b462f9931cc95eb5cc86ddaf9d27e9784fca750951ac2d67f1cc1be633fa2566'
|
data/lib/king_konf/variable.rb
CHANGED
@@ -5,16 +5,18 @@ module KingKonf
|
|
5
5
|
attr_reader :name, :type, :default, :description, :allowed_values, :options
|
6
6
|
|
7
7
|
def initialize(name:, type:, default: nil, description: "", required: false, allowed_values: nil, options: {})
|
8
|
-
@name, @type
|
8
|
+
@name, @type = name, type
|
9
9
|
@description = description
|
10
10
|
@required = required
|
11
11
|
@allowed_values = allowed_values
|
12
12
|
@options = options
|
13
|
+
@default = cast(default)
|
13
14
|
end
|
14
15
|
|
15
16
|
def cast(value)
|
16
17
|
case @type
|
17
18
|
when :float then value.to_f
|
19
|
+
when :duration then value.is_a?(String) ? Decoder.duration(value) : value
|
18
20
|
else value
|
19
21
|
end
|
20
22
|
end
|
@@ -29,6 +31,7 @@ module KingKonf
|
|
29
31
|
when :list then value.is_a?(Array)
|
30
32
|
when :integer then value.is_a?(Integer) || value.nil?
|
31
33
|
when :float then value.is_a?(Float) || value.is_a?(Integer) || value.nil?
|
34
|
+
when :duration then value.is_a?(Float) || value.is_a?(Integer) || value.is_a?(String) || value.nil?
|
32
35
|
when :boolean then value == true || value == false
|
33
36
|
when :symbol then value.is_a?(Symbol)
|
34
37
|
else raise "invalid type #{@type}"
|
data/lib/king_konf/version.rb
CHANGED