lib/peekaboo.rb in peekaboo-0.3.0 vs lib/peekaboo.rb in peekaboo-0.4.0
- old
+ new
@@ -36,33 +36,15 @@
# @private
def included klass
klass.const_set :PEEKABOO_METHOD_MAP, { :singleton_methods => Set.new, :instance_methods => Set.new }.freeze
klass.instance_variable_set :@_hooked_by_peekaboo, true
klass.extend SingletonMethods
-
- def klass.method_added name
- Peekaboo.wrap self, name, :instance if traced_instance_methods.include? name
- end
-
- def klass.singleton_method_added name
- Peekaboo.wrap self, name, :singleton if traced_singleton_methods.include? name
- end
end
# @private
def setup_autoinclusion klass
- # @note changes made to this methods to support backwards
- # compatibility with {#enable_tracing_on}. This will become
- # much simpler when that method is removed.
- def klass.method_missing(method_name, *args, &block)
- if method_name.to_s =~ /^enable_tracing_(on|for)$/
- instance_eval { include Peekaboo }
- __send__ method_name, *args
- else
- super
- end
- end
+ klass.extend SingletonMethods::AutoInclusion
end
# @private
def wrap klass, method_name, target
return if @_adding_a_method
@@ -76,9 +58,19 @@
end
rescue => exe
raise exe
ensure
@_adding_a_method = false
+ end
+ end
+
+ # @private
+ def unwrap klass, method_name, target
+ removal_snippet = "alias_method :#{method_name}, :original_#{method_name}"
+ case target
+ when :singleton then klass.instance_eval "class << self ; #{removal_snippet} ; end"
+ when :instance then klass.class_eval removal_snippet
+ else raise 'Only :class and :instance are valid targets'
end
end
private