class Facter::JsonFactFormatter

Public Class Methods

new() click to toggle source
# File lib/facter/framework/formatters/json_fact_formatter.rb, line 5
def initialize
  @log = Facter::Log.new(self)
end

Public Instance Methods

format(resolved_facts) click to toggle source
# File lib/facter/framework/formatters/json_fact_formatter.rb, line 9
def format(resolved_facts)
  user_queries = resolved_facts.uniq(&:user_query).map(&:user_query)

  if user_queries.count == 1 && user_queries.first.empty?
    format_for_no_query(resolved_facts)
  else
    format_for_user_queries(user_queries, resolved_facts)
  end
end

Private Instance Methods

format_for_no_query(resolved_facts) click to toggle source
# File lib/facter/framework/formatters/json_fact_formatter.rb, line 21
def format_for_no_query(resolved_facts)
  @log.debug('No user query provided')

  fact_collection = FormatterHelper.retrieve_fact_collection(resolved_facts)
  JSON.pretty_generate(fact_collection)
end
format_for_user_queries(user_queries, resolved_facts) click to toggle source
# File lib/facter/framework/formatters/json_fact_formatter.rb, line 28
def format_for_user_queries(user_queries, resolved_facts)
  @log.debug('User provided a query')

  facts_to_display = FormatterHelper.retrieve_facts_to_display_for_user_query(user_queries, resolved_facts)
  JSON.pretty_generate(facts_to_display)
end