Sha256: 76e71e30f69fae14a672b4ee20c6e5ce1bdae19da7fbf3251262e268a4c8ba1b

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

class Object
  # rubocop:disable Metrics/MethodLength
  def reveal(method_name = nil, **opts, &block)
    if method_name
      @__cache_rshade_reveal ||= {}
      config = opts.fetch(:config, ::RShade::Config::Registry.instance.default_trace_config)
      @__cache_rshade_reveal[method_name] = config
      instance_eval do
        def method_added(name)
          super
          return unless @__cache_rshade_reveal[name]

          if @__reveal_rewrite
            @__reveal_rewrite = false
            return
          end
          @__reveal_rewrite = true
          config = @__cache_rshade_reveal[name]
          origin_method = instance_method(name)
          define_method(name) do |*args, &fn|
            val = nil
            trace = ::RShade::Trace.reveal(config: config) do
              val = origin_method.bind(self).call(*args, &fn)
            end
            trace.show
            val
          end
        end
      end
    else
      trace = ::RShade::Trace.reveal do
        block.call if block_given?
      end
      trace.show
    end
  end
  # rubocop:enable Metrics/MethodLength
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rshade-0.2.2 lib/rshade/core_extensions/object/reveal.rb