Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Some fix on document.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaoru Kobo committed Nov 24, 2010
1 parent c6c4f18 commit 243625b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/rhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def bind(name, opt = {}, &block)
# If the hook-point is already injected, this just does {#bind}.
#
# @param [Symbol] name The name of method to hack.
# @yield [inv]
# @return [Hook]
# @see #bind See #bind for other param/return.
def hack(name, opt = {}, &block)
success = false
Expand All @@ -82,9 +84,11 @@ def hack(name, opt = {}, &block)
# @group Methods for hook-side(outside)
#
# Unbind all hooks bound to {#bound_object}.
# @return [self]
def unbind_all
@hooks_map.clear
@class_cached_hooks_map.clear
self
end

# @private
Expand Down Expand Up @@ -249,7 +253,7 @@ def concat_hooks_internal(dest, name)
# @attr [Object] target The target object that the hook is applied. (Usually same to {#receiver})
# @attr [Object] receiver The receiver object of this method invocation.
# @attr [Array<Object>] args The arguments given to the method invocation.
# @attr [Object] block The block given to the method invocation
# @attr [Proc] block The block given to the method invocation
# @attr [Object] returned The returned value by the method invocation. (Don't set this. To change it, just return by the alternative value from the hook procedure.)
# @attr [Array<Hook>] hooks (Internally used) The applied hooks on this invocation.
# @attr [Proc] target_proc (Internally used) The procedure to execute the target method/procedure.
Expand Down Expand Up @@ -281,8 +285,10 @@ def proceed
# The registered hook instance returned by #{RHookService#bind}.
class Hook
# Whether this hook is enabled.
# @return [Boolean]
attr_accessor :enabled
# The hook procedure.
# The hook procedure registered by {RHookService#bind}.
# @return [Proc]
attr_accessor :hook_proc

# @private
Expand All @@ -295,6 +301,7 @@ def call(inv)
# @overload enable()
# @overload enable(&block)
# @yield If block was given, the hook is enabled only within the given code block. (Note: This is not thread-safe.)
# @return [self]
def enable(&block)
@enabled = true
if block_given?
Expand All @@ -308,6 +315,7 @@ def enable(&block)
end

# Disable this hook.
# @return [self]
def disable
@enabled = false
self
Expand All @@ -317,6 +325,7 @@ def disable
#
class ::Object
# Get {RHookService} object bound to this object.
# @return [RHookService]
def _rhook
@_rhook ||= RHook::RHookService.new(self)
end
Expand All @@ -338,12 +347,14 @@ def initialize
end

# Add a new hook to this group.
# @return [self]
def add(hook)
@hooks << hook
self
end

# Add any hooks to this group that was registered by #{RHookService#bind} in the given block code.
# @return [HookGroup] itself
# @return [self]
def wrap(&block)
group_stack = (Thread.current["rhook_group"] ||= [])
group_stack << self
Expand All @@ -356,6 +367,7 @@ def wrap(&block)
end

# Enable the hooks.
# @return [self]
# @see Hook#enable
def enable(&block)
@hooks.each do |h|
Expand All @@ -372,6 +384,7 @@ def enable(&block)
end

# Disable the hooks.
# @return [self]
# @see Hook#disable
def disable
@hooks.each do |h|
Expand Down

0 comments on commit 243625b

Please sign in to comment.