Class: Unifig::Var

Inherits:
Object
  • Object
show all
Defined in:
lib/unifig/var.rb

Overview

A variable created after loading a configuration.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameSymbol (readonly)

The variable name.

Returns:

  • (Symbol)


25
26
27
# File 'lib/unifig/var.rb', line 25

def name
  @name
end

#providerSymbol

The provider that supplied the value.

Returns:

  • (Symbol)


30
31
32
# File 'lib/unifig/var.rb', line 30

def provider
  @provider
end

#valueObject

The value of the variable.

Returns:

  • (Object)


38
39
40
# File 'lib/unifig/var.rb', line 38

def value
  @value
end

Instance Method Details

#local_valueObject



56
57
58
# File 'lib/unifig/var.rb', line 56

def local_value
  @local_value ||= config(:value)
end

#methodSymbol

The name of the method this variable can be found using.

Returns:

  • (Symbol)


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.

Returns:

  • (Boolean)


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