class Junos::Ez::Facts::Keeper

Attributes

known[RW]

Public Class Methods

define( fact, &block ) click to toggle source
# File lib/junos-ez/facts.rb, line 49
def self.define( fact, &block )
  define_method( "fact_read_#{fact}".to_sym, block )
end
new( ndev ) click to toggle source
# File lib/junos-ez/facts.rb, line 28
def initialize( ndev )
  @ndev = ndev
  @known = Hash.new
end

Public Instance Methods

[](key) click to toggle source
# File lib/junos-ez/facts.rb, line 57
def [](key)
  @known[key]
end
[]=(key,value) click to toggle source
# File lib/junos-ez/facts.rb, line 53
def []=(key,value)
  @known[key] = value
end
catalog() click to toggle source
# File lib/junos-ez/facts.rb, line 38
def catalog; @known end
catalog!() click to toggle source
# File lib/junos-ez/facts.rb, line 39
def catalog!; read!; catalog end
clear() click to toggle source
# File lib/junos-ez/facts.rb, line 33
def clear; @known.clear end
list() click to toggle source
# File lib/junos-ez/facts.rb, line 35
def list; @known.keys end
list!() click to toggle source
# File lib/junos-ez/facts.rb, line 36
def list!; read!; list; end
read!() click to toggle source
# File lib/junos-ez/facts.rb, line 61
def read!
  @known.clear
  fact_readers = self.methods.grep /^fact_read_/
  fact_readers.each do |getter| 
    getter =~ /^fact_read_(\w+)/
    fact = $1.to_sym
    self.send( getter, @ndev, @known ) unless @known[fact]
  end
end
uses( *facts ) click to toggle source
# File lib/junos-ez/facts.rb, line 41
def uses( *facts )
  values = facts.collect do |f|
    self.send( "fact_read_#{f}", @ndev, @known ) unless @known[f]
    self[f]
  end      
  (values.count == 1) ? values[0] : values      
end