lib/spy/subroutine.rb in spy-0.2.5 vs lib/spy/subroutine.rb in spy-0.3.0
- old
+ new
@@ -1,7 +1,8 @@
module Spy
class Subroutine
+ include Base
# @!attribute [r] base_object
# @return [Object] the object that is being watched
#
# @!attribute [r] method_name
# @return [Symbol] the name of the method that is being watched
@@ -43,11 +44,10 @@
raise AlreadyHookedError, "#{base_object} method '#{method_name}' has already been hooked" if self.class.get(base_object, method_name, singleton_method)
@hook_opts = opts
@original_method_visibility = method_visibility_of(method_name)
hook_opts[:visibility] ||= original_method_visibility
- hook_opts[:force] ||= base_object.is_a?(Double)
if original_method_visibility || !hook_opts[:force]
@original_method = current_method
end
@@ -359,17 +359,14 @@
all_methods.map do |method_name|
Agency.instance.find(get_spy_id(base_object.method(method_name)))
end.compact
end
- private
-
+ # @private
def get_spy_id(method)
return nil unless method.parameters[0].is_a?(Array)
- first_param_name = method.parameters[0][1].to_s
- if first_param_name.include?("__spy_args")
- first_param_name.split("_").last.to_i
- end
+ id = method.parameters[0][1].to_s.sub!("__spy_args_", "")
+ id.to_i if id
end
end
end
end