dotenv_validator 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dotenv_validator/version.rb +1 -1
- data/lib/dotenv_validator.rb +24 -15
- 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: '03040841959fe965027d57672d55726640199bb217b52a169c40b3bf465c7d69'
|
4
|
+
data.tar.gz: 80f1543f7719e2f3758bcf69b6294469c22033a56e96f03358d1627350e266b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aee0d70d03f541d3d30171f1eafc5481df165a702b60bb0426b21db52af3c561100213765b0df20f80aeaa8b866b1fb47019b0bf5600aa8d181c825a64df63cf
|
7
|
+
data.tar.gz: a0e9a2bedb35d6cd82b5ebb3872544b009d849fa6de34044e060aeadbea12f77cf53a98b6a8ee7e95ef865bf7ecd40ab9e6583e7db99e6065434278090b67f59
|
data/lib/dotenv_validator.rb
CHANGED
@@ -29,20 +29,22 @@ module DotenvValidator
|
|
29
29
|
|
30
30
|
next unless config =~ /format=(.*)/
|
31
31
|
|
32
|
+
format = Regexp.last_match(1)
|
33
|
+
|
32
34
|
valid =
|
33
|
-
case
|
34
|
-
when "int", "integer" then integer?(value)
|
35
|
-
when "float" then float?(value)
|
36
|
-
when "str", "string" then true
|
35
|
+
case format
|
36
|
+
when "int", "integer", "Integer" then integer?(value)
|
37
|
+
when "float", "Float" then float?(value)
|
38
|
+
when "str", "string", "String" then true
|
37
39
|
when "email" then email?(value)
|
38
40
|
when "url" then url?(value)
|
39
|
-
when "bool", "boolean" then boolean?(value)
|
40
|
-
when "uuid" then uuid?(value)
|
41
|
+
when "bool", "boolean", "Boolean" then boolean?(value)
|
42
|
+
when "uuid", "UUID" then uuid?(value)
|
41
43
|
else
|
42
44
|
value.match?(Regexp.new(Regexp.last_match(1)))
|
43
45
|
end
|
44
46
|
|
45
|
-
invalid_format << variable_name unless valid
|
47
|
+
invalid_format << {name: variable_name, value: value, format: format} unless valid
|
46
48
|
end
|
47
49
|
|
48
50
|
[missing_variables, invalid_format]
|
@@ -61,7 +63,8 @@ module DotenvValidator
|
|
61
63
|
end
|
62
64
|
|
63
65
|
if invalid_format.any?
|
64
|
-
puts
|
66
|
+
puts "WARNING - Environment variables with invalid format:"
|
67
|
+
puts invalid_format_list(invalid_format)
|
65
68
|
result = false
|
66
69
|
end
|
67
70
|
|
@@ -76,10 +79,10 @@ module DotenvValidator
|
|
76
79
|
|
77
80
|
raise("Missing environment variables: #{missing_variables.join(", ")}") if missing_variables.any?
|
78
81
|
|
79
|
-
raise("Environment variables with invalid format
|
82
|
+
raise("Environment variables with invalid format:\n#{invalid_format_list(invalid_format)}") if invalid_format.any?
|
80
83
|
end
|
81
84
|
|
82
|
-
# It checks the value
|
85
|
+
# It checks if the value is float or not.
|
83
86
|
#
|
84
87
|
# @param [String] A string
|
85
88
|
# @return [Boolean] True if it is a float value. False otherwise.
|
@@ -89,7 +92,7 @@ module DotenvValidator
|
|
89
92
|
false
|
90
93
|
end
|
91
94
|
|
92
|
-
# It checks the value
|
95
|
+
# It checks if the value is an integer or not.
|
93
96
|
#
|
94
97
|
# @param [String] A string
|
95
98
|
# @return [Boolean] True if it is an integer value. False otherwise.
|
@@ -99,7 +102,7 @@ module DotenvValidator
|
|
99
102
|
false
|
100
103
|
end
|
101
104
|
|
102
|
-
# It checks the value
|
105
|
+
# It checks if the value is an email or not.
|
103
106
|
#
|
104
107
|
# @param [String] A string
|
105
108
|
# @return [Boolean] True if it is an email value. False otherwise.
|
@@ -107,7 +110,7 @@ module DotenvValidator
|
|
107
110
|
string.match?(URI::MailTo::EMAIL_REGEXP)
|
108
111
|
end
|
109
112
|
|
110
|
-
# It checks the value
|
113
|
+
# It checks if the value is a URL or not.
|
111
114
|
#
|
112
115
|
# @param [String] A string
|
113
116
|
# @return [Boolean] True if it is an URL value. False otherwise.
|
@@ -115,7 +118,7 @@ module DotenvValidator
|
|
115
118
|
string.match?(/\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/)
|
116
119
|
end
|
117
120
|
|
118
|
-
# It checks the value
|
121
|
+
# It checks if the value is a boolean or not.
|
119
122
|
#
|
120
123
|
# @param [String] A string
|
121
124
|
# @return [Boolean] True if it is a boolean value. False otherwise.
|
@@ -123,7 +126,7 @@ module DotenvValidator
|
|
123
126
|
string.match?(/(true|false)/)
|
124
127
|
end
|
125
128
|
|
126
|
-
# It checks the value
|
129
|
+
# It checks if the value is a uuid or not.
|
127
130
|
#
|
128
131
|
# @param [String] A string
|
129
132
|
# @return [Boolean] True if it is a UUID value. False otherwise.
|
@@ -156,4 +159,10 @@ module DotenvValidator
|
|
156
159
|
root_or_pwd
|
157
160
|
end
|
158
161
|
end
|
162
|
+
|
163
|
+
def self.invalid_format_list(invalid_format)
|
164
|
+
invalid_format.map do |var|
|
165
|
+
%(- #{var[:name]}: expected "#{var[:value]}" to match "#{var[:format]}" format)
|
166
|
+
end.join("\n")
|
167
|
+
end
|
159
168
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Juodziukynas
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: fast_blank
|