dorian-arguments 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/dorian/arguments.rb +6 -10
- 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: 31d8f3ef5198b3dc9ce418928e840ed5c82f7f3691964e4c1d34d96be9846951
|
4
|
+
data.tar.gz: 7494ebf6c746f4207e21cf79846d24e59c19d3824382e70215c64aeeac8a60b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d32f303df1fa9814866beb211aa8ee6bd90c37d34524d9820a716d768c2230b21799fc90bb472db9c2bf810a45363891475a72d58ce2855e21eeb2d07962b727
|
7
|
+
data.tar.gz: 0e12a036b21735bf712a35a9f96b328d65679f1d69185dac528de4a5eded68e1f7a3b4cbed1062c57ffd4ccf623b563a6b41a4f0bb06e7bf96798d2c78ad3112
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/dorian/arguments.rb
CHANGED
@@ -22,13 +22,7 @@ class Dorian
|
|
22
22
|
|
23
23
|
TYPES = [BOOLEAN, STRING, NUMBER, INTEGER, DECIMAL]
|
24
24
|
|
25
|
-
|
26
|
-
BOOLEAN => "false",
|
27
|
-
STRING => "",
|
28
|
-
NUMBER => "0",
|
29
|
-
INTEGER => "0",
|
30
|
-
DECIMAL => "0"
|
31
|
-
}
|
25
|
+
DEFAULT = nil
|
32
26
|
|
33
27
|
MATCHES = {
|
34
28
|
BOOLEAN => /^(true|false)$/i,
|
@@ -99,7 +93,9 @@ class Dorian
|
|
99
93
|
end
|
100
94
|
|
101
95
|
def cast(type, value)
|
102
|
-
if
|
96
|
+
if value.nil?
|
97
|
+
nil
|
98
|
+
elsif type == BOOLEAN
|
103
99
|
BOOLEANS.fetch(value.downcase)
|
104
100
|
elsif type == INTEGER
|
105
101
|
value.to_i
|
@@ -135,7 +131,7 @@ class Dorian
|
|
135
131
|
def normalize(value)
|
136
132
|
if value.is_a?(Hash)
|
137
133
|
type = value[:type]&.to_s || DEFAULT_TYPE
|
138
|
-
default = value[:default]&.to_s ||
|
134
|
+
default = value[:default]&.to_s || DEFAULT
|
139
135
|
aliases =
|
140
136
|
Array.wrap(
|
141
137
|
value[:alias]&.to_s || value[:aliases]&.map(&:to_s) ||
|
@@ -143,7 +139,7 @@ class Dorian
|
|
143
139
|
)
|
144
140
|
else
|
145
141
|
type = value.to_s
|
146
|
-
default =
|
142
|
+
default = DEFAULT
|
147
143
|
aliases = DEFAULT_ALIASES
|
148
144
|
end
|
149
145
|
|