Module: EnvControl::Validators

Defined in:
lib/env_control/validators.rb

Class Method Summary collapse

Class Method Details

.bool(val) ⇒ Object



9
10
11
# File 'lib/env_control/validators.rb', line 9

def bool(val)
  ["true", "false"].include?(val)
end

.email(string) ⇒ Object



13
14
15
# File 'lib/env_control/validators.rb', line 13

def email(string)
  string.match?(URI::MailTo::EMAIL_REGEXP)
end

.empty(string) ⇒ Object



17
18
19
# File 'lib/env_control/validators.rb', line 17

def empty(string)
  string == ""
end

.existing_file_path(path) ⇒ Object



21
22
23
# File 'lib/env_control/validators.rb', line 21

def existing_file_path(path)
  File.file?(path)
end

.existing_folder_path(path) ⇒ Object



25
26
27
# File 'lib/env_control/validators.rb', line 25

def existing_folder_path(path)
  Dir.exists?(path)
end

.existing_path(path) ⇒ Object



29
30
31
# File 'lib/env_control/validators.rb', line 29

def existing_path(path)
  File.exists?(path)
end

.hex(string) ⇒ Object



71
72
73
# File 'lib/env_control/validators.rb', line 71

def hex(string)
  string.match?(/\A[a-f0-9]+\z/i)
end

.https_uri(string) ⇒ Object



33
34
35
# File 'lib/env_control/validators.rb', line 33

def https_uri(string)
  uri(string) && URI(string).scheme.eql?("https")
end

.ignore(string) ⇒ Object



37
38
39
# File 'lib/env_control/validators.rb', line 37

def ignore(string)
  true
end

.integer(string) ⇒ Object



41
42
43
# File 'lib/env_control/validators.rb', line 41

def integer(string)
  string.match?(/\A[-]{,1}\d+\z/)
end

.irrelevant(string) ⇒ Object



45
46
47
# File 'lib/env_control/validators.rb', line 45

def irrelevant(string)
  true
end

.not_set(value) ⇒ Object Also known as: deprecated



49
50
51
# File 'lib/env_control/validators.rb', line 49

def not_set(value)
  false
end

.postgres_uri(string) ⇒ Object



55
56
57
# File 'lib/env_control/validators.rb', line 55

def postgres_uri(string)
  uri(string) && URI(string).scheme.eql?("postgres")
end

.string(val) ⇒ Object



59
60
61
# File 'lib/env_control/validators.rb', line 59

def string(val)
  val.strip.size > 0
end

.uri(string) ⇒ Object



63
64
65
# File 'lib/env_control/validators.rb', line 63

def uri(string)
  string.match?(/\A#{URI::regexp}\z/)
end

.uuid(string) ⇒ Object



67
68
69
# File 'lib/env_control/validators.rb', line 67

def uuid(string)
  string.match?(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}\z/i)
end