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
# 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)
  @external_facts = load_external_facts(options)

  filter_env_facts

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

#load_custom_fact(options, fact_name) ⇒ Object



45
46
47
48
49
50
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 45

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



52
53
54
55
56
57
58
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 52

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



60
61
62
63
64
65
66
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 60

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



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/facter/framework/core/fact_loaders/fact_loader.rb', line 31

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