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.
14 15 16 17 18 19 20 |
# File 'lib/unifig/var.rb', line 14 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.
25 26 27 |
# File 'lib/unifig/var.rb', line 25 def name @name end |
#provider ⇒ Symbol
The provider that supplied the value.
30 31 32 |
# File 'lib/unifig/var.rb', line 30 def provider @provider end |
#value ⇒ Object
The value of the variable.
38 39 40 |
# File 'lib/unifig/var.rb', line 38 def value @value end |
Instance Method Details
#local_value ⇒ Object
56 57 58 |
# File 'lib/unifig/var.rb', line 56 def local_value @local_value ||= config(:value) end |
#method ⇒ Symbol
The name of the method this variable can be found using.
51 52 53 |
# File 'lib/unifig/var.rb', line 51 def method @method ||= name.to_s.downcase.tr('-', '_').to_sym end |
#required? ⇒ Boolean
Returns whether or not this is a required variable.
63 64 65 66 67 68 69 70 |
# File 'lib/unifig/var.rb', line 63 def required? return @required if defined?(@required) optional = config(:optional) optional = @config[:optional] if optional.nil? optional = false if optional.nil? @required = !optional end |