Sha256: 220955fd90e55e1a11a899e5b1827dd2cb07dd120d1fbe256cb4b0fe937c41a9

Contents?: true

Size: 1.23 KB

Versions: 26

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Facter
  module Util
    module ApiDebugger
      def self.prepended(receiver) # rubocop:disable Metrics/AbcSize
        exclude, print_caller = parse_options(ENV['API_DEBUG'])

        receiver_methods = receiver.instance_methods - Object.methods
        receiver_methods.each do |meth|
          ApiDebugger.class_eval do
            define_method(meth) do |*args|
              method_call = super(*args)

              unless exclude.include?(meth)
                puts '#' * 80
                puts "Method call: #{meth}"
                puts "Called with: #{args.inspect}"
                if print_caller.include?(meth)
                  puts '-' * 80
                  puts caller
                end
                puts '#' * 80
              end
              method_call
            end
          end
        end
      end

      def self.parse_options(options)
        exclude = []
        print_caller = []

        options.split(',').each do |option|
          if option.start_with?('-')
            exclude << option[1..-1].to_sym
          elsif option.start_with?('+')
            print_caller << option[1..-1].to_sym
          end
        end

        [exclude, print_caller]
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

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