Class: ENV

Inherits:
Object
  • Object
show all
Defined in:
lib/env_helpers/ext/env.rb

Class Method Summary collapse

Class Method Details

.array(var_name, sep = ',') ⇒ Array

Get an array value from an ENV variable

Defaults to [] if value is blank.

Parameters:

  • var_name (String)

    ENV variable name

  • sep (String) (defaults to: ',')

    string to split ENV value on

Returns:

  • (Array)

    array of strings representing the ENV value.


39
40
41
# File 'lib/env_helpers/ext/env.rb', line 39

def array(var_name, sep = ',')
  EnvHelpers.array(var_name, sep)
end

.bool(var_name, default = nil) ⇒ Boolean

Get an boolean value from an ENV variable or return a default. Will return the default if there is a non-boolean like value for the ENV variable.

or doesn't represent a numeric value

Parameters:

  • var_name (String)

    ENV variable name

  • default (Object) (defaults to: nil)

    retured when ENV is blank

Returns:

  • (Boolean)

    boolean representing the ENV value


59
60
61
# File 'lib/env_helpers/ext/env.rb', line 59

def bool(var_name, default = nil)
  EnvHelpers.bool(var_name, default)
end

.equal?(var_name, value) ⇒ Boolean

Compare the value of an ENV variable to a given string.

Parameters:

  • var_name (String)

    ENV variable name

  • value (String)

    comparison string

Returns:

  • (Boolean)

    `true` if the value of the ENV variable is the same as value


11
12
13
# File 'lib/env_helpers/ext/env.rb', line 11

def equal?(var_name, value)
  EnvHelpers.equal?(var_name, value)
end

.false?(var_name) ⇒ Boolean

Check if an ENV variable represents `false`. ('false', 'f', or '0'). Returns false if environment variable isn't defined.

Parameters:

  • var_name (String)

    ENV variable name

Returns:

  • (Boolean)

77
78
79
# File 'lib/env_helpers/ext/env.rb', line 77

def false?(var_name)
  EnvHelpers.false?(var_name)
end

.int(var_name, default = nil) ⇒ Integer

Get an integer value from an ENV variable or return a default.

Parameters:

  • var_name (String)

    ENV variable name

  • default (Object) (defaults to: nil)

    retured when ENV is blank or doesn't exist

Returns:

  • (Integer)

    integer representing the ENV value


29
30
31
# File 'lib/env_helpers/ext/env.rb', line 29

def int(var_name, default = nil)
  EnvHelpers.int(var_name, default)
end

.json(var_name, default = nil) ⇒ Object

Get a JSON value from an ENV variable

Parameters:

  • var_name (String)

    ENV variable name

Returns:

  • (Object)

    array of strings representing the ENV value.

Raises:

  • (JSON::ParserError)

    if value is invalid JSON


48
49
50
# File 'lib/env_helpers/ext/env.rb', line 48

def json(var_name, default = nil)
  EnvHelpers.json(var_name, default)
end

.num(var_name, default = nil) ⇒ Float

Get a number value from an ENV variable or return a default.

Parameters:

  • var_name (String)

    ENV variable name

  • default (Object) (defaults to: nil)

    retured when ENV is blank or doesn't exist

Returns:

  • (Float)

    float representing the ENV value


20
21
22
# File 'lib/env_helpers/ext/env.rb', line 20

def num(var_name, default = nil)
  EnvHelpers.num(var_name, default)
end

.true?(var_name) ⇒ Boolean

Check if an ENV variable represents `true`. ('true', 't', or '1'). Returns false if environment variable isn't defined.

Parameters:

  • var_name (String)

    ENV variable name

Returns:

  • (Boolean)

68
69
70
# File 'lib/env_helpers/ext/env.rb', line 68

def true?(var_name)
  EnvHelpers.true?(var_name)
end