Class: Unifig::Var
- Inherits:
-
Object
- Object
- Unifig::Var
- Defined in:
- lib/unifig/var.rb
Overview
A variable created after loading a configuration.
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The variable name.
-
#provider ⇒ Symbol
The provider that supplied the value.
-
#value ⇒ Object
The value of the variable.
Instance Method Summary collapse
-
#initialize(name, config, env) ⇒ Var
constructor
A new instance of Var.
- #local_value ⇒ Object
-
#method ⇒ Symbol
The name of the method this variable can be found using.
-
#required? ⇒ Boolean
Returns whether or not this is a required variable.
Constructor Details
#initialize(name, config, env) ⇒ Var
Returns a new instance of Var.
7 8 9 10 11 12 13 |
# File 'lib/unifig/var.rb', line 7 def initialize(name, config, env) @name = name @config = config @env = env @value = nil @provider = nil end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
The variable name.
18 19 20 |
# File 'lib/unifig/var.rb', line 18 def name @name end |
#provider ⇒ Symbol
The provider that supplied the value.
23 24 25 |
# File 'lib/unifig/var.rb', line 23 def provider @provider end |
#value ⇒ Object
The value of the variable.
31 32 33 |
# File 'lib/unifig/var.rb', line 31 def value @value end |
Instance Method Details
#local_value ⇒ Object
48 49 50 |
# File 'lib/unifig/var.rb', line 48 def local_value @local_value ||= env_config(:value) || @config[:value] end |
#method ⇒ Symbol
The name of the method this variable can be found using.
43 44 45 |
# File 'lib/unifig/var.rb', line 43 def method @method ||= name.to_s.downcase.tr('-', '_').to_sym end |
#required? ⇒ Boolean
Returns whether or not this is a required variable.
55 56 57 58 59 60 61 62 |
# File 'lib/unifig/var.rb', line 55 def required? return @required if defined?(@required) optional = env_config(:optional) optional = @config[:optional] if optional.nil? optional = false if optional.nil? @required = !optional end |