dotenv_validator 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 426cf730fa10449f239c5ae8c01fc268fbc2be4ba8db0a855d5dea84e8dee909
4
- data.tar.gz: 1dd12b8dbae9d5712e94a33f5de97718f242b18fb5790afae1f75d1752c1455b
3
+ metadata.gz: 6ee3d73f77ffe3a5d1a050afcd957d1cda68522963de3c4196f0e8fb22f0b9f3
4
+ data.tar.gz: b957b41bde61f0dd24e3ab4a896ea4bdd063804ede8417271ca40d3e0fa101b7
5
5
  SHA512:
6
- metadata.gz: 5d3bbbc1a4e3515ebff3248fb36e904247e6fc415a010877e65264bba84b658ab284f922643fe5b5c63c41500f6f8fbc32f460d6964603ff9c8ddc6f4d59ab16
7
- data.tar.gz: 574809319fb840c2b2f275662ebc3c12502773a6cfc32cd9492fa726852a26afee6adc07b194b75c482093c14c11ccb4864656552f1cb3936a3105b53419c1c4
6
+ metadata.gz: 9893692a6ecd009c7bc728cec6c0cd0f66f4d07dde10c32b5dffcb817675af3f5cba3cee750bf3b331f88e05d97db2ed4b417b6755d49e3e6ff50e36aa7e241f
7
+ data.tar.gz: 48821a901dd6ffc6d86081d0a72cc652a1d83659eb663ac71165c307eeff88b0af4bfcb76a1699dd9f8ddb2859843d15b26595f3ae8f6d94398df50657c595cd
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DotenvValidator
4
- VERSION = "1.0.0"
5
- end
4
+ VERSION = '1.1.0'
5
+ end
@@ -1,9 +1,9 @@
1
- require "fast_blank"
1
+ require 'fast_blank'
2
+ require 'pathname'
2
3
 
3
4
  # Knows how to check the environment variables and compares it to .env.sample
4
5
  # and the comments in every line of your .env.sample file.
5
6
  module DotenvValidator
6
-
7
7
  # It analyzes the current environment and it compares it to the documentation
8
8
  # present in .env.sample.
9
9
  #
@@ -15,8 +15,8 @@ module DotenvValidator
15
15
  invalid_format = []
16
16
 
17
17
  open_sample_file.each do |line|
18
- variable, config = line.split(" #")
19
- variable_name, _sample = variable.split("=")
18
+ variable, config = line.split(' #')
19
+ variable_name, _sample = variable.split('=')
20
20
  value = ENV[variable_name]
21
21
 
22
22
  if value.nil? || value.blank?
@@ -24,20 +24,20 @@ module DotenvValidator
24
24
  next
25
25
  end
26
26
 
27
- if config =~ /format=(.*)/
28
- valid =
29
- case $1
30
- when "int", "integer" then integer?(value)
31
- when "float" then float?(value)
32
- when "str", "string" then false
33
- when "email" then email?(value)
34
- when "url" then url?(value)
35
- else
36
- value.match?(Regexp.new($1))
37
- end
38
-
39
- invalid_format << variable_name unless valid
40
- end
27
+ next unless config =~ /format=(.*)/
28
+
29
+ valid =
30
+ 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)
36
+ else
37
+ value.match?(Regexp.new(Regexp.last_match(1)))
38
+ end
39
+
40
+ invalid_format << variable_name unless valid
41
41
  end
42
42
 
43
43
  [missing_variables, invalid_format]
@@ -51,12 +51,12 @@ module DotenvValidator
51
51
 
52
52
  missing_variables, invalid_format = analyze_variables
53
53
  if missing_variables.any?
54
- puts("WARNING - Missing environment variables: #{missing_variables.join(", ")}")
54
+ puts("WARNING - Missing environment variables: #{missing_variables.join(', ')}")
55
55
  result = false
56
56
  end
57
57
 
58
58
  if invalid_format.any?
59
- puts("WARNING - Environment variables with invalid format: #{invalid_format.join(", ")}")
59
+ puts("WARNING - Environment variables with invalid format: #{invalid_format.join(', ')}")
60
60
  result = false
61
61
  end
62
62
 
@@ -69,13 +69,9 @@ module DotenvValidator
69
69
  def self.check!
70
70
  missing_variables, invalid_format = analyze_variables
71
71
 
72
- if missing_variables.any?
73
- raise("Missing environment variables: #{missing_variables.join(", ")}")
74
- end
72
+ raise("Missing environment variables: #{missing_variables.join(', ')}") if missing_variables.any?
75
73
 
76
- if invalid_format.any?
77
- raise("Environment variables with invalid format: #{invalid_format.join(", ")}")
78
- end
74
+ raise("Environment variables with invalid format: #{invalid_format.join(', ')}") if invalid_format.any?
79
75
  end
80
76
 
81
77
  # It checks the value to check if it is a float or not.
@@ -84,7 +80,7 @@ module DotenvValidator
84
80
  # @return [Boolean] True if it is a float value. False otherwise.
85
81
  def self.float?(string)
86
82
  true if Float(string)
87
- rescue
83
+ rescue StandardError
88
84
  false
89
85
  end
90
86
 
@@ -94,7 +90,7 @@ module DotenvValidator
94
90
  # @return [Boolean] True if it is an integer value. False otherwise.
95
91
  def self.integer?(string)
96
92
  true if Integer(string)
97
- rescue
93
+ rescue StandardError
98
94
  false
99
95
  end
100
96
 
@@ -111,7 +107,7 @@ module DotenvValidator
111
107
  # @param [String] A string
112
108
  # @return [Boolean] True if it is an URL value. False otherwise.
113
109
  def self.url?(string)
114
- string.match?(/https?:\/\/.+/)
110
+ string.match?(%r{https?://.+})
115
111
  end
116
112
 
117
113
  def self.open_sample_file
@@ -119,6 +115,21 @@ module DotenvValidator
119
115
  end
120
116
 
121
117
  def self.sample_file
122
- File.join(File.expand_path(File.dirname(__FILE__)), ".env.sample")
118
+ File.join(root, '.env.sample')
119
+ end
120
+
121
+ # Internal: `Rails.root` is nil in Rails 4.1 before the application is
122
+ # initialized, so this falls back to the `RAILS_ROOT` environment variable,
123
+ # or the current working directory.
124
+ #
125
+ # Taken from Dotenv source code.
126
+ def self.root
127
+ root_or_pwd = Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd)
128
+
129
+ if defined?(Rails)
130
+ Rails.root || root_or_pwd
131
+ else
132
+ root_or_pwd
133
+ end
123
134
  end
124
135
  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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Juodziukynas
@@ -12,28 +12,8 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-07-29 00:00:00.000000000 Z
15
+ date: 2021-09-14 00:00:00.000000000 Z
16
16
  dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: dotenv
19
- requirement: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: '2.7'
24
- - - "<"
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
- type: :runtime
28
- prerelease: false
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '2.7'
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '3.0'
37
17
  - !ruby/object:Gem::Dependency
38
18
  name: fast_blank
39
19
  requirement: !ruby/object:Gem::Requirement
@@ -69,45 +49,45 @@ dependencies:
69
49
  - !ruby/object:Gem::Version
70
50
  version: '12.0'
71
51
  - !ruby/object:Gem::Dependency
72
- name: codecov
52
+ name: climate_control
73
53
  requirement: !ruby/object:Gem::Requirement
74
54
  requirements:
75
55
  - - ">="
76
56
  - !ruby/object:Gem::Version
77
- version: 0.5.0
57
+ version: '1.0'
78
58
  - - "<"
79
59
  - !ruby/object:Gem::Version
80
- version: '1.0'
60
+ version: '2.0'
81
61
  type: :development
82
62
  prerelease: false
83
63
  version_requirements: !ruby/object:Gem::Requirement
84
64
  requirements:
85
65
  - - ">="
86
66
  - !ruby/object:Gem::Version
87
- version: 0.5.0
67
+ version: '1.0'
88
68
  - - "<"
89
69
  - !ruby/object:Gem::Version
90
- version: '1.0'
70
+ version: '2.0'
91
71
  - !ruby/object:Gem::Dependency
92
- name: climate_control
72
+ name: codecov
93
73
  requirement: !ruby/object:Gem::Requirement
94
74
  requirements:
95
75
  - - ">="
96
76
  - !ruby/object:Gem::Version
97
- version: '1.0'
77
+ version: 0.5.0
98
78
  - - "<"
99
79
  - !ruby/object:Gem::Version
100
- version: '2.0'
80
+ version: '1.0'
101
81
  type: :development
102
82
  prerelease: false
103
83
  version_requirements: !ruby/object:Gem::Requirement
104
84
  requirements:
105
85
  - - ">="
106
86
  - !ruby/object:Gem::Version
107
- version: '1.0'
87
+ version: 0.5.0
108
88
  - - "<"
109
89
  - !ruby/object:Gem::Version
110
- version: '2.0'
90
+ version: '1.0'
111
91
  - !ruby/object:Gem::Dependency
112
92
  name: rake
113
93
  requirement: !ruby/object:Gem::Requirement
@@ -196,7 +176,7 @@ extensions: []
196
176
  extra_rdoc_files: []
197
177
  files:
198
178
  - lib/dotenv_validator.rb
199
- - lib/version.rb
179
+ - lib/dotenv_validator/version.rb
200
180
  homepage: https://github.com/fastruby/dotenv_validator
201
181
  licenses:
202
182
  - MIT
@@ -216,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
196
  - !ruby/object:Gem::Version
217
197
  version: '0'
218
198
  requirements: []
219
- rubygems_version: 3.1.4
199
+ rubygems_version: 3.1.2
220
200
  signing_key:
221
201
  specification_version: 4
222
202
  summary: Checks required env variables and its format using .env.sample