Module: Savvy::Utility

Defined in:
lib/savvy/utility.rb

Class Method Summary collapse

Class Method Details

.valid_env_var?(var) ⇒ Boolean

Validate that the provided var is a string that can be used as a name for environment variables.

Parameters:

  • var (String)

Returns:

  • (Boolean)


22
23
24
# File 'lib/savvy/utility.rb', line 22

def valid_env_var?(var)
  var.kind_of?(String) && Dux.presentish?(var)
end

.valid_env_vars?(vars) ⇒ Boolean

Validate that the provided value is a one-dimensional array of strings that may or may not exist in ‘ENV`.

Parameters:

  • vars (<String>)

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/savvy/utility.rb', line 9

def valid_env_vars?(vars)
  return false unless vars.kind_of?(Array)

  vars.all? do |var|
    valid_env_var? var
  end
end

.valid_url?(url, scheme: nil) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
# File 'lib/savvy/utility.rb', line 26

def valid_url?(url, scheme: nil)
  return false unless url.kind_of?(String) && Dux.presentish?(url)

  if scheme
    return false unless url.start_with?("#{scheme}://")
  end

  return true
end