File: marshal.rb

package info (click to toggle)
ruby-spy 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 360 kB
  • sloc: ruby: 3,101; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 640 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Marshal
  class << self
    # @private
    def dump_with_mocks(*args)
      object = args.shift
      spies = Spy::Subroutine.get_spies(object)
      if spies.empty?
        return dump_without_mocks(*args.unshift(object))
      end

      spy_hook_options = spies.map do |spy|
        [spy.hook_opts, spy.unhook]
      end

      begin
        dump_without_mocks(*args.unshift(object.dup))
      ensure
        spy_hook_options.each do |hook_opts, spy|
          spy.hook(hook_opts)
        end
      end
    end

    alias_method :dump_without_mocks, :dump
    undef_method :dump
    alias_method :dump, :dump_with_mocks
  end
end