Class: BindingDumper::CoreExt::LocalBindingPatchBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/binding_dumper/core_ext/local_binding_patch_builder.rb

Overview

Class responsible for building patch for local binding

Examples:

data = {
  file: '/path/to/file.rb',
  line: 17,
  method: 'do_something'
}
patch = BindingDumper::CoreExt::LocalBindingPatchBuilder.new(data).patch
patched_binding = binding.extend(patch)

patched_binding.eval('__FILE__')
# => '/path/to/file.rb'
patched_binding.eval('__LINE__')
# => 17
patched_binding.eval('__method__')
# => 'do_something'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(undumped) ⇒ LocalBindingPatchBuilder



24
25
26
# File 'lib/binding_dumper/core_ext/local_binding_patch_builder.rb', line 24

def initialize(undumped)
  @undumped = undumped
end

Instance Attribute Details

#undumpedObject (readonly)

Returns the value of attribute undumped.



20
21
22
# File 'lib/binding_dumper/core_ext/local_binding_patch_builder.rb', line 20

def undumped
  @undumped
end

Instance Method Details

#patchModule

Returns module that is ready for patching existing binding



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/binding_dumper/core_ext/local_binding_patch_builder.rb', line 32

def patch
  deps = [
    file_method_patch,
    line_method_patch,
    method_method_patch,
    eval_method_patch
  ]
  Module.new do
    include *deps
  end
end