dotenv_validator 1.1.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ee3d73f77ffe3a5d1a050afcd957d1cda68522963de3c4196f0e8fb22f0b9f3
4
- data.tar.gz: b957b41bde61f0dd24e3ab4a896ea4bdd063804ede8417271ca40d3e0fa101b7
3
+ metadata.gz: 5ddad97517028e5f710b5973f270558feff5c9b0d642c71a3f0efc9a1a291363
4
+ data.tar.gz: d8ab3fa5933aa9b94f443e5a9c297386b6724168eff1420dc3852db6614250c8
5
5
  SHA512:
6
- metadata.gz: 9893692a6ecd009c7bc728cec6c0cd0f66f4d07dde10c32b5dffcb817675af3f5cba3cee750bf3b331f88e05d97db2ed4b417b6755d49e3e6ff50e36aa7e241f
7
- data.tar.gz: 48821a901dd6ffc6d86081d0a72cc652a1d83659eb663ac71165c307eeff88b0af4bfcb76a1699dd9f8ddb2859843d15b26595f3ae8f6d94398df50657c595cd
6
+ metadata.gz: 20c7b2ae0b8970a7256374b27ea9138f5e9ca5d866656ec59ec439472451d3063f828dc45f5fb19893df0f259670ae0558563a9f22bc1f75e8d9d7ea711a3da0
7
+ data.tar.gz: 8c83b8eb210691309d09bf83370e657ccd8ad3ad5e361035d3a580770752d07d9993115be9803ae425a04842384c763e740942aff46765e33d1dbb122baa248f
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DotenvValidator # :nodoc: all
4
+ class SampleFileNotFoundError < StandardError
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DotenvValidator
4
- VERSION = '1.1.0'
4
+ VERSION = "1.2.0"
5
5
  end
@@ -1,5 +1,8 @@
1
- require 'fast_blank'
2
- require 'pathname'
1
+ # frozen_string_literal: true
2
+
3
+ require "fast_blank"
4
+ require "pathname"
5
+ require "dotenv_validator/errors"
3
6
 
4
7
  # Knows how to check the environment variables and compares it to .env.sample
5
8
  # and the comments in every line of your .env.sample file.
@@ -15,8 +18,8 @@ module DotenvValidator
15
18
  invalid_format = []
16
19
 
17
20
  open_sample_file.each do |line|
18
- variable, config = line.split(' #')
19
- variable_name, _sample = variable.split('=')
21
+ variable, config = line.split(" #")
22
+ variable_name, _sample = variable.split("=")
20
23
  value = ENV[variable_name]
21
24
 
22
25
  if value.nil? || value.blank?
@@ -28,11 +31,13 @@ module DotenvValidator
28
31
 
29
32
  valid =
30
33
  case Regexp.last_match(1)
31
- when 'int', 'integer' then integer?(value)
32
- when 'float' then float?(value)
33
- when 'str', 'string' then true
34
- when 'email' then email?(value)
35
- when 'url' then url?(value)
34
+ when "int", "integer" then integer?(value)
35
+ when "float" then float?(value)
36
+ when "str", "string" then true
37
+ when "email" then email?(value)
38
+ when "url" then url?(value)
39
+ when "bool", "boolean" then boolean?(value)
40
+ when "uuid" then uuid?(value)
36
41
  else
37
42
  value.match?(Regexp.new(Regexp.last_match(1)))
38
43
  end
@@ -51,12 +56,12 @@ module DotenvValidator
51
56
 
52
57
  missing_variables, invalid_format = analyze_variables
53
58
  if missing_variables.any?
54
- puts("WARNING - Missing environment variables: #{missing_variables.join(', ')}")
59
+ puts("WARNING - Missing environment variables: #{missing_variables.join(", ")}")
55
60
  result = false
56
61
  end
57
62
 
58
63
  if invalid_format.any?
59
- puts("WARNING - Environment variables with invalid format: #{invalid_format.join(', ')}")
64
+ puts("WARNING - Environment variables with invalid format: #{invalid_format.join(", ")}")
60
65
  result = false
61
66
  end
62
67
 
@@ -69,9 +74,9 @@ module DotenvValidator
69
74
  def self.check!
70
75
  missing_variables, invalid_format = analyze_variables
71
76
 
72
- raise("Missing environment variables: #{missing_variables.join(', ')}") if missing_variables.any?
77
+ raise("Missing environment variables: #{missing_variables.join(", ")}") if missing_variables.any?
73
78
 
74
- raise("Environment variables with invalid format: #{invalid_format.join(', ')}") if invalid_format.any?
79
+ raise("Environment variables with invalid format: #{invalid_format.join(", ")}") if invalid_format.any?
75
80
  end
76
81
 
77
82
  # It checks the value to check if it is a float or not.
@@ -80,7 +85,7 @@ module DotenvValidator
80
85
  # @return [Boolean] True if it is a float value. False otherwise.
81
86
  def self.float?(string)
82
87
  true if Float(string)
83
- rescue StandardError
88
+ rescue
84
89
  false
85
90
  end
86
91
 
@@ -90,7 +95,7 @@ module DotenvValidator
90
95
  # @return [Boolean] True if it is an integer value. False otherwise.
91
96
  def self.integer?(string)
92
97
  true if Integer(string)
93
- rescue StandardError
98
+ rescue
94
99
  false
95
100
  end
96
101
 
@@ -99,7 +104,7 @@ module DotenvValidator
99
104
  # @param [String] A string
100
105
  # @return [Boolean] True if it is an email value. False otherwise.
101
106
  def self.email?(string)
102
- string.match?(/[\w@]+@[\w@]+\.[\w@]+/)
107
+ string.match?(URI::MailTo::EMAIL_REGEXP)
103
108
  end
104
109
 
105
110
  # It checks the value to check if it is a URL or not.
@@ -107,15 +112,34 @@ module DotenvValidator
107
112
  # @param [String] A string
108
113
  # @return [Boolean] True if it is an URL value. False otherwise.
109
114
  def self.url?(string)
110
- string.match?(%r{https?://.+})
115
+ string.match?(/\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/)
116
+ end
117
+
118
+ # It checks the value to check if it is a boolean or not.
119
+ #
120
+ # @param [String] A string
121
+ # @return [Boolean] True if it is a boolean value. False otherwise.
122
+ def self.boolean?(string)
123
+ string.match?(/(true|false)/)
124
+ end
125
+
126
+ # It checks the value to check if it is a uuid or not.
127
+ #
128
+ # @param [String] A string
129
+ # @return [Boolean] True if it is a UUID value. False otherwise.
130
+ def self.uuid?(string)
131
+ string.match?(/\A[\da-f]{32}\z/i) ||
132
+ string.match?(/\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\z/i)
111
133
  end
112
134
 
113
135
  def self.open_sample_file
114
136
  File.open(sample_file)
137
+ rescue Errno::ENOENT
138
+ raise DotenvValidator::SampleFileNotFoundError, "#{sample_file} was not found!"
115
139
  end
116
140
 
117
141
  def self.sample_file
118
- File.join(root, '.env.sample')
142
+ File.join(root, ".env.sample")
119
143
  end
120
144
 
121
145
  # Internal: `Rails.root` is nil in Rails 4.1 before the application is
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.1.0
4
+ version: 1.2.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: 2021-09-14 00:00:00.000000000 Z
15
+ date: 2022-04-05 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: fast_blank
@@ -176,6 +176,7 @@ extensions: []
176
176
  extra_rdoc_files: []
177
177
  files:
178
178
  - lib/dotenv_validator.rb
179
+ - lib/dotenv_validator/errors.rb
179
180
  - lib/dotenv_validator/version.rb
180
181
  homepage: https://github.com/fastruby/dotenv_validator
181
182
  licenses:
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  - !ruby/object:Gem::Version
197
198
  version: '0'
198
199
  requirements: []
199
- rubygems_version: 3.1.2
200
+ rubygems_version: 3.3.7
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: Checks required env variables and its format using .env.sample