Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "dotenv_validator"

require "irb"
IRB.start(__FILE__)
22 changes: 17 additions & 5 deletions dotenv_validator.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
require_relative "lib/version"

Gem::Specification.new do |s|
s.name = "dotenv_validator"
s.version = "1.0.0"
s.authors = ["Ariel Juodziukynas <arieljuod@gmail.com>"]
s.email = "arieljuod@gmail.com"
s.version = DotenvValidator::VERSION
s.authors = ["Ariel Juodziukynas",
"Ernesto Tagwerker",
"Francois Buys",
"Luis Sagastume",
"Robert Dormer"]
s.email = ["arieljuod@gmail.com",
"ernesto+github@ombulabs.com",
"francois@ombulabs.com",
"luis@ombulabs.com",
"robert@ombulabs.com"
]
s.licenses = ["MIT"]
s.summary = "Checks required env variables and its format using .env and .env.sample files from Dotenv"
s.description = "Checks required env variables and its format using .env and .env.sample files from Dotenv"
s.summary = "Checks required env variables and its format using .env.sample"
s.description = "Checks required env variables and its format using dotenv and .env.sample files. Sample files include validation documentation which is interpreted and used to validate your environment."
s.homepage = "https://github.com/fastruby/dotenv_validator"
s.files = [
"lib/version.rb",
"lib/dotenv_validator.rb"
]
s.require_paths = ["lib"]
Expand Down
29 changes: 29 additions & 0 deletions lib/dotenv_validator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
require "fast_blank"

# Knows how to check the environment variables and compares it to .env.sample
# and the comments in every line of your .env.sample file.
module DotenvValidator

# It analyzes the current environment and it compares it to the documentation
# present in .env.sample.
#
# @return [[String],[String]] An array with two arrays. First array: List of missing variables. Second array: List of variables with invalid format.
def self.analyze_variables
return [], [] unless File.exist?(sample_file)

Expand Down Expand Up @@ -36,6 +43,9 @@ def self.analyze_variables
[missing_variables, invalid_format]
end

# It checks the current environment and it returns a boolean value.
#
# @return [Boolean] True if everything looks good. False otherwise.
def self.check
result = true

Expand All @@ -53,6 +63,9 @@ def self.check
result
end

# It checks the current environment and it raises a runtime exception.
#
# @raise [RuntimeError] Raised if a missing variable is found or an invalid format is encountered.
def self.check!
missing_variables, invalid_format = analyze_variables

Expand All @@ -65,22 +78,38 @@ def self.check!
end
end

# It checks the value to check if it is a float or not.
#
# @param [String] A string
# @return [Boolean] True if it is a float value. False otherwise.
def self.float?(string)
true if Float(string)
rescue
false
end

# It checks the value to check if it is an integer or not.
#
# @param [String] A string
# @return [Boolean] True if it is an integer value. False otherwise.
def self.integer?(string)
true if Integer(string)
rescue
false
end

# It checks the value to check if it is an email or not.
#
# @param [String] A string
# @return [Boolean] True if it is an email value. False otherwise.
def self.email?(string)
string.match?(/[\w@]+@[\w@]+\.[\w@]+/)
end

# It checks the value to check if it is a URL or not.
#
# @param [String] A string
# @return [Boolean] True if it is an URL value. False otherwise.
def self.url?(string)
string.match?(/https?:\/\/.+/)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module DotenvValidator
VERSION = "1.0.0"
end