Class: Mutant::RequireHighjack
- Inherits:
-
Object
- Object
- Mutant::RequireHighjack
- Defined in:
- lib/mutant/require_highjack.rb
Overview
Require highjack
Instance Attribute Summary collapse
-
#original ⇒ #call
readonly
private
Return original method.
Instance Method Summary collapse
-
#disinfect ⇒ self
private
Imperfectly disinfect kernel from highjack.
-
#infect ⇒ self
private
Infect kernel with highjack.
-
#run ⇒ self
private
Run block with highjacked require.
Instance Attribute Details
#original ⇒ #call (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return original method
12 13 14 |
# File 'lib/mutant/require_highjack.rb', line 12 def original @original end |
Instance Method Details
#disinfect ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Imperfectly disinfect kernel from highjack
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mutant/require_highjack.rb', line 52 def disinfect original = @original target.module_eval do undef :require define_method(:require) do |logical_name| original.call(logical_name) end module_function :require end end |
#infect ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Infect kernel with highjack
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mutant/require_highjack.rb', line 34 def infect callback = @callback @original = target.method(:require) target.module_eval do undef :require define_method(:require) do |logical_name| callback.call(logical_name) end module_function :require end end |
#run ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Run block with highjacked require
20 21 22 23 24 25 26 |
# File 'lib/mutant/require_highjack.rb', line 20 def run infect yield self ensure disinfect end |