Sha256: cd07f45e25b6c41c6133fbad9e7d843444df1757e01d968c094a8fcb2e6aadb0

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 KB

Contents

# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# 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 :__eval__, :eval
		
		def eval(*args)
			Covered::Eval.intercept_eval(*args)
			
			__eval__(*args)
		end
	end
	
	private
	
	alias_method :__eval__, :eval
	
	def eval(*args)
		Covered::Eval.intercept_eval(*args)
		
		__eval__(*args)
	end
end

class Binding
	alias_method :__eval__, :eval
	
	def eval(*args)
		Covered::Eval.intercept_eval(*args)
		
		__eval__(*args)
	end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
covered-0.10.5 lib/covered/eval.rb
covered-0.10.4 lib/covered/eval.rb
covered-0.10.3 lib/covered/eval.rb
covered-0.10.2 lib/covered/eval.rb
covered-0.10.1 lib/covered/eval.rb
covered-0.10.0 lib/covered/eval.rb
covered-0.9.0 lib/covered/eval.rb
covered-0.8.0 lib/covered/eval.rb
covered-0.7.0 lib/covered/eval.rb
covered-0.6.2 lib/covered/eval.rb
covered-0.5.2 lib/covered/eval.rb
covered-0.5.1 lib/covered/eval.rb
covered-0.4.1 lib/covered/eval.rb
covered-0.4.0 lib/covered/eval.rb
covered-0.3.0 lib/covered/eval.rb