Class: Facter::FactLoader

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/facter/framework/core/fact_loaders/fact_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFactLoader

Returns a new instance of FactLoader.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 9

def initialize
  @log = Log.new(self)

  @internal_facts = []
  @external_facts = []
  @custom_facts = []
  @facts = []

  @internal_loader ||= InternalFactLoader.new
  @external_fact_loader ||= ExternalFactLoader.new
end

Instance Attribute Details

#external_factsObject (readonly)

Returns the value of attribute external_facts.



7
8
9
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 7

def external_facts
  @external_facts
end

#factsObject (readonly)

Returns the value of attribute facts.



7
8
9
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 7

def facts
  @facts
end

#internal_factsObject (readonly)

Returns the value of attribute internal_facts.



7
8
9
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 7

def internal_facts
  @internal_facts
end

Instance Method Details

#load(user_query, options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 21

def load(user_query, options)
  @internal_facts = load_internal_facts(user_query, options)
  @custom_facts = load_custom_facts(options)
  if ENV['INSIDE_FACTER']
    @log.debug('INSIDE_FACTER env var detected, not loading external facts to prevent recursion')
    if options[:external_facts]
      @log.warn('Recursion detected, skipping external facts. Silence this warning by adding --no-external-facts')
    end
  else
    begin
      ENV['INSIDE_FACTER'] = 'true'
      @external_facts = load_external_facts(options)
    ensure
      ENV.delete('INSIDE_FACTER')
    end
  end

  filter_env_facts

  @facts = @internal_facts + @external_facts + @custom_facts
end

#load_custom_fact(options, fact_name) ⇒ Object



57
58
59
60
61
62
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 57

def load_custom_fact(options, fact_name)
  return [] unless options[:custom_facts]

  custom_facts = @external_fact_loader.load_fact(fact_name)
  block_facts(custom_facts, options)
end

#load_custom_facts(options) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 64

def load_custom_facts(options)
  return [] unless options[:custom_facts]

  @log.debug('Loading custom facts')
  custom_facts = @external_fact_loader.custom_facts
  block_facts(custom_facts, options)
end

#load_external_facts(options) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 72

def load_external_facts(options)
  return [] unless options[:external_facts]

  @log.debug('Loading external facts')
  external_facts = @external_fact_loader.external_facts
  block_facts(external_facts, options)
end

#load_internal_facts(user_query, options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 43

def load_internal_facts(user_query, options)
  internal_facts = []
  if user_query || options[:show_legacy]
    # if we have a user query, then we must search in core facts and legacy facts
    @log.debug('Loading all internal facts')
    internal_facts = @internal_loader.facts
  else
    @log.debug('Load only core facts')
    internal_facts = @internal_loader.core_facts
  end

  block_facts(internal_facts, options)
end