Class: Retrospec::Puppet::Generators::Facter

Inherits:
Object
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb

Defined Under Namespace

Classes: Core

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, &block) ⇒ Facter

Returns a new instance of Facter.



24
25
26
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 24

def initialize(name, options, &block)
  @fact_name = name
end

Class Method Details

.add(name, options = {}, &block) ⇒ Object

every fact will have a Facter.add functionality this is the startign point to collect all data



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 86

def self.add(name, options={}, &block)
  # calls the facter.add block
  # this may call separate confine statements
  # for each Facter.add block that gets called we need to reset a few things
  @confines = {}
  @used_facts = {}
  @exec_calls = {}
  begin
    block.call
  rescue Exception => e
  rescue NameError => e
  end

  @model.facts[name] = OpenStruct.new(:fact_name => name)
  @model.facts[name].used_facts = used_facts
  @model.facts[name].confines = @confines
  @model.defined_methods = methods_defined
  @model.facts[name].exec_calls = exec_calls
  @model
end

.confine(fact, *values) ⇒ Object



65
66
67
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 65

def self.confine(fact, *values)
  @confines << fact
end

.exec_callsObject



28
29
30
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 28

def self.exec_calls
  @exec_calls ||= {}
end

.fact(name) ⇒ Object



44
45
46
47
48
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 44

def self.fact(name)
  fake_fact = OpenStruct.new(:value => '')
  used_facts[name] = {:name => name}
  fake_fact
end

.load_fact(file) ⇒ Object

loads the fact into the loader for evaluation and data collection



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 71

def self.load_fact(file)
  @model = OpenStruct.new(:facts => {}, :defined_methods => [], :global_used_facts => {}, :global_used_execs => {})
  begin
    proc = Proc.new {}
    eval(File.read(file), proc.binding, file)
  rescue LoadError => e
    puts "Error loading dependency for file: #{file}, skipping".fatal
  rescue Exception => e
    puts "Error evaluating file: #{file}, skipping".fatal
  end
  @model
end

.method_missing(method_sym, *arguments, &block) ⇒ Object



50
51
52
53
54
55
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 50

def self.method_missing(method_sym, *arguments, &block)
  unless methods_defined.include?(method_sym)
    methods_defined << method_sym
  end
  method_sym
end

.methods_definedObject



36
37
38
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 36

def self.methods_defined
  @methods_defined ||= []
end

.setcode(&block) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 57

def self.setcode(&block)
  begin
    block.call
  rescue Exception => e
  rescue NameError => e
  end
end

.used_factsObject



32
33
34
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 32

def self.used_facts
  @used_facts ||= {}
end

.value(name) ⇒ Object



40
41
42
# File 'lib/retrospec/plugins/v1/plugin/generators/parsers/facter.rb', line 40

def self.value(name)
  used_facts[name] = {:name => name}
end