Class: Facter::FactManager
- Inherits:
-
Object
- Object
- Facter::FactManager
- Includes:
- Singleton
- Defined in:
- lib/facter/framework/core/fact_manager.rb
Overview
Instance Method Summary collapse
-
#initialize ⇒ FactManager
constructor
A new instance of FactManager.
- #resolve_core(user_query = [], options = {}) ⇒ Object
-
#resolve_fact(user_query) ⇒ Object
resolve a fact by name, in a similar way that facter 3 does.
- #resolve_facts(user_query = []) ⇒ Object
Constructor Details
#initialize ⇒ FactManager
Returns a new instance of FactManager.
7 8 9 10 11 12 13 |
# File 'lib/facter/framework/core/fact_manager.rb', line 7 def initialize @internal_fact_mgr = InternalFactManager.new @external_fact_mgr = ExternalFactManager.new @fact_loader = FactLoader.instance @options = Options.get @log = Log.new(self) end |
Instance Method Details
#resolve_core(user_query = [], options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/facter/framework/core/fact_manager.rb', line 64 def resolve_core(user_query = [], = {}) log_resolving_method @cache_manager = CacheManager.new core_fact(user_query, ) end |
#resolve_fact(user_query) ⇒ Object
resolve a fact by name, in a similar way that facter 3 does. search is done in multiple steps, and the next step is executed only if the previous one was not able to resolve the fact
-
load the ‘fact_name.rb` from the configured custom directories
-
load all the core facts, external facts and env facts
-
load all custom facts
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/facter/framework/core/fact_manager.rb', line 43 def resolve_fact(user_query) log_resolving_method @options[:user_query] = user_query @log.debug("resolving fact with user_query: #{user_query}") @cache_manager = Facter::CacheManager.new custom_facts = custom_fact_by_filename(user_query) || [] core_and_external_facts = core_or_external_fact(user_query) || [] resolved_facts = core_and_external_facts + custom_facts if resolved_facts.empty? || resolved_facts.none? { |rf| rf.resolves?(user_query) } resolved_facts.concat(all_custom_facts(user_query)) end @cache_manager.cache_facts(resolved_facts) log_resolved_facts(resolved_facts) resolved_facts end |
#resolve_facts(user_query = []) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/facter/framework/core/fact_manager.rb', line 15 def resolve_facts(user_query = []) log_resolving_method @options[:user_query] = user_query cache_manager = Facter::CacheManager.new searched_facts = QueryParser.parse(user_query, @fact_loader.load(user_query, @options)) searched_facts, cached_facts = cache_manager.resolve_facts(searched_facts) internal_facts = @internal_fact_mgr.resolve_facts(searched_facts) external_facts = @external_fact_mgr.resolve_facts(searched_facts) resolved_facts = override_core_facts(internal_facts, external_facts) resolved_facts.concat(cached_facts) cache_manager.cache_facts(resolved_facts) FactFilter.new.filter_facts!(resolved_facts, user_query) log_resolved_facts(resolved_facts) resolved_facts end |