Module: Hooked
- Defined in:
- lib/hooked.rb,
lib/hooked/hook.rb,
lib/hooked/graph.rb,
lib/hooked/aspect.rb,
lib/hooked/version.rb
Defined Under Namespace
Modules: ClassMethods
Classes: Aspect, Graph, Hook
Constant Summary
collapse
- VERSION =
"0.3.3"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#hooked ⇒ Object
Returns the value of attribute hooked.
7
8
9
|
# File 'lib/hooked.rb', line 7
def hooked
@hooked
end
|
Class Method Details
.included(klass) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/hooked.rb', line 40
def self.included(klass)
klass.instance_variable_set :@instance_hooked, {}
klass.extend ClassMethods
class << klass
alias_method :new_without_hooked, :new
alias_method :new, :new_with_hooked
end
end
|
Instance Method Details
#hook!(pointcut) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/hooked.rb', line 16
def hook!(pointcut)
@hooked ||= {}
return if hooked[pointcut]
hooked[pointcut] = Hooked::Hook.new method(pointcut)
(class << self; self; end).class_eval do
undef_method pointcut
define_method pointcut do |*args, &block|
hooked[pointcut].call *args, &block
end
end
end
|
#unhook!(pointcut) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/hooked.rb', line 29
def unhook!(pointcut)
return unless hooked && hooked[pointcut]
p = hooked[pointcut].pointcut
(class << self; self; end).class_eval do
remove_method pointcut
define_method pointcut, &p
end
hooked.delete pointcut
end
|