Class: QED::Advice::Events
- Inherits:
-
Object
- Object
- QED::Advice::Events
- Defined in:
- lib/qed/advice/events.rb
Overview
This class encapsulates advice on symbolic targets, such as Before, After and Upon.
Instance Attribute Summary collapse
-
#signals ⇒ Object
readonly
Returns the value of attribute signals.
Instance Method Summary collapse
- #add(type, &procedure) ⇒ Object
- #call(scope, type, *args) ⇒ Object
-
#clear(type = nil) ⇒ Object
Clear advice.
-
#initialize ⇒ Events
constructor
A new instance of Events.
-
#reset ⇒ Object
Clear last set of advice.
- #setup ⇒ Object
Constructor Details
#initialize ⇒ Events
Returns a new instance of Events.
14 15 16 |
# File 'lib/qed/advice/events.rb', line 14 def initialize @signals = [{}] end |
Instance Attribute Details
#signals ⇒ Object (readonly)
Returns the value of attribute signals.
11 12 13 |
# File 'lib/qed/advice/events.rb', line 11 def signals @signals end |
Instance Method Details
#add(type, &procedure) ⇒ Object
19 20 21 |
# File 'lib/qed/advice/events.rb', line 19 def add(type, &procedure) @signals.last[type.to_sym] = procedure end |
#call(scope, type, *args) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/qed/advice/events.rb', line 24 def call(scope, type, *args) @signals.each do |set| proc = set[type.to_sym] #proc.call(*args) if proc scope.instance_exec(*args, &proc) if proc end end |
#clear(type = nil) ⇒ Object
Clear advice.
44 45 46 47 48 49 50 |
# File 'lib/qed/advice/events.rb', line 44 def clear(type=nil) if type @signals.each{ |set| set.delete(type.to_sym) } else @signals = [{}] end end |
#reset ⇒ Object
Clear last set of advice.
34 35 36 |
# File 'lib/qed/advice/events.rb', line 34 def reset @signals.pop end |
#setup ⇒ Object
39 40 41 |
# File 'lib/qed/advice/events.rb', line 39 def setup @signals.push {} end |