Sha256: fefa11ef77e2ffd6bd04a72296a4da9c130b7d911a5e5de22d6585c3f823c048

Contents?: true

Size: 1.26 KB

Versions: 21

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    class BaseResolver
      def self.log
        @log ||= Log.new(self)
      end

      def self.invalidate_cache
        @fact_list = {}
      end

      def self.init_resolver
        @fact_list = {}
        @semaphore = Mutex.new
      end

      def self.subscribe_to_manager
        Facter::SessionCache.subscribe(self)
      end

      def self.resolve(fact_name, options = {})
        @semaphore.synchronize do
          subscribe_to_manager
          post_resolve(fact_name, options)

          cache_nil_for_unresolved_facts(fact_name)
        end
      rescue NoMethodError => e
        log.debug("Could not resolve #{fact_name}, got #{e} at #{e.backtrace[0]}")
        @fact_list[fact_name] = nil
      rescue LoadError, NameError => e
        log.debug("Resolving fact #{fact_name}, but got #{e} at #{e.backtrace[0]}")
        @fact_list[fact_name] = nil
      end

      def self.cache_nil_for_unresolved_facts(fact_name)
        @fact_list.fetch(fact_name) { @fact_list[fact_name] = nil }
        @fact_list[fact_name]
      end

      def self.post_resolve(_fact_name, _options)
        raise NotImplementedError, "You must implement post_resolve(fact_name, options) method in #{name}"
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
facter-4.4.1 lib/facter/resolvers/base_resolver.rb
facter-4.4.0 lib/facter/resolvers/base_resolver.rb
facter-4.3.1 lib/facter/resolvers/base_resolver.rb
facter-4.3.0 lib/facter/resolvers/base_resolver.rb
facter-4.2.14 lib/facter/resolvers/base_resolver.rb
facter-4.2.13 lib/facter/resolvers/base_resolver.rb
facter-4.2.12 lib/facter/resolvers/base_resolver.rb
facter-4.2.11 lib/facter/resolvers/base_resolver.rb
facter-4.2.10 lib/facter/resolvers/base_resolver.rb
facter-4.2.9 lib/facter/resolvers/base_resolver.rb
facter-4.2.8 lib/facter/resolvers/base_resolver.rb
facter-4.2.7 lib/facter/resolvers/base_resolver.rb
facter-4.2.6 lib/facter/resolvers/base_resolver.rb
facter-4.2.5 lib/facter/resolvers/base_resolver.rb
facter-4.2.4 lib/facter/resolvers/base_resolver.rb
facter-4.2.3 lib/facter/resolvers/base_resolver.rb
facter-4.2.2 lib/facter/resolvers/base_resolver.rb
facter-4.2.1 lib/facter/resolvers/base_resolver.rb
facter-4.2.0 lib/facter/resolvers/base_resolver.rb
facter-4.1.1 lib/facter/resolvers/base_resolver.rb