Sha256: cc5873d9afdb3cc8cb68025a4d94453d257fd389800f0b3f18ae777311ec299f

Contents?: true

Size: 800 Bytes

Versions: 7

Compression:

Stored size: 800 Bytes

Contents

module GitCompound
  module Logger
    # Debugger mixin
    #
    module Debugger
      def debug_before(method, &block)
        debug(method, :before, &block)
      end

      def debug_after(method, &block)
        debug(method, :after, &block)
      end

      private

      def debug(method, moment, &block)
        raise GitCompoundError, 'No block given !' unless block

        method_old = "#{method}_old_debugged".to_sym
        alias_method(method_old, method)
        private method_old

        define_method(method) do |*args|
          Logger.debug(instance_exec(*args, &block)) if moment == :before
          args.insert(0, send(method_old, *args))
          Logger.debug(instance_exec(*args, &block)) if moment == :after

          args.first
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
git_compound-0.2.2 lib/git_compound/logger/debugger.rb
git_compound-0.2.1 lib/git_compound/logger/debugger.rb
git_compound-0.2.0 lib/git_compound/logger/debugger.rb
git_compound-0.1.2 lib/git_compound/logger/debugger.rb
git_compound-0.1.1 lib/git_compound/logger/debugger.rb
git_compound-0.1.0 lib/git_compound/logger/debugger.rb
git_compound-0.0.10 lib/git_compound/logger/debugger.rb