Sha256: f957de170dbf6f43764d1ebb735dcd5bb14296835a13b83425ab4fcf2ccf1414

Contents?: true

Size: 1.23 KB

Versions: 12

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

# This file is used by projects cloned with clone mode. As such, special care must be taken to
# be compatible with any projects.
# THERE MUST NOT BE ANY USE/REQUIRE OF DEPENDENCIES OF DeepCover HERE
# See deep-cover/core_gem/lib/deep_cover/setup/clone_mode_entry_template.rb for explanation of
# clone mode and of this top_level_module stuff.
top_level_module = Thread.current['_deep_cover_top_level_module'] || Object

# Adds a functionality to add callbacks before an `exec`

module top_level_module::DeepCover # rubocop:disable Naming/ClassAndModuleCamelCase
  module ExecCallbacks
    class << self
      attr_reader :callbacks

      def before_exec(&block)
        (@callbacks ||= []) << block
      end
    end
  end

  # We use #object_id of DeepCover to avoid possible overwrite between clone-mode and non-clone-mode
  original_exec_name = :"exec_without_deep_cover_#{self.object_id}"
  [::Kernel, ::Kernel.singleton_class].each do |mod|
    mod.send(:alias_method, original_exec_name, :exec)
    mod.send(:define_method, :exec) do |*args|
      ExecCallbacks.callbacks.each(&:call)
      send(original_exec_name, *args)
    end
  end
  ::Kernel.send :private, original_exec_name
  ::Kernel.send :private, :exec
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
deep-cover-core-1.1.0 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-1.0.0 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.8.1 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.8.0 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.10 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.9 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.8 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.7 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.6 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.5 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.4 lib/deep_cover/core_ext/exec_callbacks.rb
deep-cover-core-0.7.3 lib/deep_cover/core_ext/exec_callbacks.rb