Class: Puppet::Util::NetworkDevice::Cisco_ios::Model::ScopedValue
- Inherits:
-
GenericValue
- Object
- GenericValue
- Puppet::Util::NetworkDevice::Cisco_ios::Model::ScopedValue
- Defined in:
- lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#scope(*args, &block) ⇒ Object
Returns the value of attribute scope.
-
#scope_name(*args, &block) ⇒ Object
Returns the value of attribute scope_name.
Instance Method Summary collapse
- #extract_scope(txt) ⇒ Object
- #munge_scope(content, name) ⇒ Object
- #parse(txt) ⇒ Object
-
#scope_match(&block) ⇒ Object
pass a block if a single scope can match multiple names the block must split up the given content and matched name and return a list of new content and name pairs.
Instance Attribute Details
#scope(*args, &block) ⇒ Object
Returns the value of attribute scope.
6 7 8 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 6 def scope @scope end |
#scope_name(*args, &block) ⇒ Object
Returns the value of attribute scope_name.
6 7 8 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 6 def scope_name @scope_name end |
Instance Method Details
#extract_scope(txt) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 34 def extract_scope(txt) raise "No scope_name configured" if @scope_name.nil? return if txt.nil? || txt.empty? munged = txt.scan(scope).collect do |content,name| munge_scope(content,name) end.reduce(:+) || [] munged.collect do |pair| (content,name) = pair content if name == @scope_name end.reject { |v| v.nil? }.first end |
#munge_scope(content, name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 26 def munge_scope(content, name) if self.scope_match.is_a? Proc self.scope_match.call(content, name) else [[content, name]] end end |
#parse(txt) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 48 def parse(txt) result = extract_scope(txt) if result.nil? || result.empty? Puppet.debug("Scope #{scope} not found for Param #{name}") return end if self.match.is_a?(Proc) self.value = self.match.call(result) else self.value = result.scan(self.match).flatten[self.idx] end self.evaluated = true end |
#scope_match(&block) ⇒ Object
pass a block if a single scope can match multiple names the block must split up the given content and matched name and return a list of new content and name pairs
21 22 23 24 |
# File 'lib/puppet/util/network_device/cisco_ios/model/scoped_value.rb', line 21 def scope_match(&block) return @scope_match if block.nil? @scope_match = block end |