lib/covered/eval.rb in covered-0.1.0 vs lib/covered/eval.rb in covered-0.3.0
- old
+ new
@@ -16,63 +16,63 @@
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
+require 'thread'
+
+module Covered
+ module Eval
+ @mutex = Mutex.new
+ @handler = nil
+
+ def self.enable(handler)
+ @mutex.synchronize do
+ @handler = handler
+ end
+ end
+
+ def self.disable(handler)
+ @mutex.synchronize do
+ @handler = nil
+ end
+ end
+
+ def self.intercept_eval(*args)
+ @mutex.synchronize do
+ @handler.intercept_eval(*args) if @handler
+ end
+ end
+ end
+end
+
module Kernel
class << self
- alias_method :original_eval, :eval
+ alias_method :__eval__, :eval
def eval(*args)
- if source = $source
- source.map(*args)
- end
+ Covered::Eval.intercept_eval(*args)
- original_eval(*args)
+ __eval__(*args)
end
end
private
- alias_method :original_eval, :eval
+ alias_method :__eval__, :eval
def eval(*args)
- if source = $source
- source.map(*args)
- end
+ Covered::Eval.intercept_eval(*args)
- original_eval(*args)
+ __eval__(*args)
end
end
class Binding
- alias_method :original_eval, :eval
+ alias_method :__eval__, :eval
def eval(*args)
- if source = $source
- source.map(*args)
- end
+ Covered::Eval.intercept_eval(*args)
- original_eval(*args)
+ __eval__(*args)
end
end
-
-# class BasicObject
-# alias_method :original_instance_eval, :instance_eval
-#
-# def instance_eval(*args, &block)
-# puts args.inspect
-# original_instance_eval(*args, &block)
-# end
-# end
-#
-# class Module
-# alias_method :original_module_eval, :module_eval
-#
-# def module_eval(*args, &block)
-# puts args.inspect
-# original_module_eval(*args, &block)
-# end
-#
-# remove_method :class_eval
-# alias_method :class_eval, :module_eval
-# end