Class: Snmp2mkr::ConfigTypes::TemplateString
- Defined in:
- lib/snmp2mkr/config_types/template_string.rb
Defined Under Namespace
Classes: MissingContextVariable
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#bind_context, #children, #collect_children, #initialize, #inspect
Constructor Details
This class inherits a constructor from Snmp2mkr::ConfigTypes::Base
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
13 14 15 |
# File 'lib/snmp2mkr/config_types/template_string.rb', line 13 def value @value end |
Instance Method Details
#evaluate(context: binded_context, previous: nil) ⇒ Object
15 16 17 18 19 |
# File 'lib/snmp2mkr/config_types/template_string.rb', line 15 def evaluate(context: binded_context, previous: nil) @value.gsub(/\#{(.+?)}/) do |_| context[$1 || $1.to_sym] or raise MissingContextVariable.new("variable #{$1.inspect} is missing from context") end end |
#setup(str) ⇒ Object
8 9 10 11 |
# File 'lib/snmp2mkr/config_types/template_string.rb', line 8 def setup(str) raise TypeError, 'TemplateString must be given a String' unless str.kind_of?(String) @value = str end |