Class: ValidEnv::EnvVar
- Inherits:
-
Object
show all
- Defined in:
- lib/valid-env/env_var.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(key, type = nil, default: nil, additional_details: nil) ⇒ EnvVar
Returns a new instance of EnvVar.
5
6
7
8
9
10
|
# File 'lib/valid-env/env_var.rb', line 5
def initialize(key, type = nil, default: nil, additional_details: nil)
@key = key.to_s
@type = type
@default_value = default
@additional_details = additional_details
end
|
Instance Attribute Details
#additional_details ⇒ Object
Returns the value of attribute additional_details.
3
4
5
|
# File 'lib/valid-env/env_var.rb', line 3
def additional_details
@additional_details
end
|
#default_value ⇒ Object
Returns the value of attribute default_value.
3
4
5
|
# File 'lib/valid-env/env_var.rb', line 3
def default_value
@default_value
end
|
#key ⇒ Object
Returns the value of attribute key.
3
4
5
|
# File 'lib/valid-env/env_var.rb', line 3
def key
@key
end
|
Instance Method Details
#==(other) ⇒ Object
12
13
14
15
|
# File 'lib/valid-env/env_var.rb', line 12
def ==(other)
other.is_a?(self.class) &&
other.key == key
end
|
#boolean? ⇒ Boolean
31
32
33
|
# File 'lib/valid-env/env_var.rb', line 31
def boolean?
@type == :boolean
end
|
#raw_value_from_env ⇒ Object
27
28
29
|
# File 'lib/valid-env/env_var.rb', line 27
def raw_value_from_env
ENV[@key]
end
|
#to_s ⇒ Object
35
36
37
38
39
|
# File 'lib/valid-env/env_var.rb', line 35
def to_s
msg = "Environment Variable: #{key}"
msg << " (#{additional_details})" if additional_details
msg
end
|
#value ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/valid-env/env_var.rb', line 17
def value
if raw_value_from_env.nil?
default_value
elsif boolean?
converted_boolean_value
else
raw_value_from_env
end
end
|