Class: Gamefic::Rulebook::Hooks
- Inherits:
-
Object
- Object
- Gamefic::Rulebook::Hooks
- Defined in:
- lib/gamefic/rulebook/hooks.rb
Overview
A collection of hooks that can be executed before and after an action.
Instance Attribute Summary collapse
-
#after_actions ⇒ Object
readonly
Returns the value of attribute after_actions.
-
#before_actions ⇒ Object
readonly
Returns the value of attribute before_actions.
Instance Method Summary collapse
- #after_action(narrative, *verbs, &block) ⇒ Object
- #before_action(narrative, *verbs, &block) ⇒ Object
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Hooks
constructor
A new instance of Hooks.
- #run_after(action) ⇒ Object
- #run_before(action) ⇒ Object
Constructor Details
#initialize ⇒ Hooks
Returns a new instance of Hooks.
12 13 14 15 |
# File 'lib/gamefic/rulebook/hooks.rb', line 12 def initialize @before_actions = [] @after_actions = [] end |
Instance Attribute Details
#after_actions ⇒ Object (readonly)
Returns the value of attribute after_actions.
10 11 12 |
# File 'lib/gamefic/rulebook/hooks.rb', line 10 def after_actions @after_actions end |
#before_actions ⇒ Object (readonly)
Returns the value of attribute before_actions.
8 9 10 |
# File 'lib/gamefic/rulebook/hooks.rb', line 8 def before_actions @before_actions end |
Instance Method Details
#after_action(narrative, *verbs, &block) ⇒ Object
28 29 30 |
# File 'lib/gamefic/rulebook/hooks.rb', line 28 def after_action narrative, *verbs, &block after_actions.push Action::Hook.new(verbs, Callback.new(narrative, block)) end |
#before_action(narrative, *verbs, &block) ⇒ Object
24 25 26 |
# File 'lib/gamefic/rulebook/hooks.rb', line 24 def before_action narrative, *verbs, &block before_actions.push Action::Hook.new(verbs, Callback.new(narrative, block)) end |
#empty? ⇒ Boolean
32 33 34 |
# File 'lib/gamefic/rulebook/hooks.rb', line 32 def empty? before_actions.empty? && after_actions.empty? end |
#freeze ⇒ Object
17 18 19 20 21 22 |
# File 'lib/gamefic/rulebook/hooks.rb', line 17 def freeze super @before_actions.freeze @after_actions.freeze self end |
#run_after(action) ⇒ Object
40 41 42 |
# File 'lib/gamefic/rulebook/hooks.rb', line 40 def run_after action run_action_hooks action, after_actions end |
#run_before(action) ⇒ Object
36 37 38 |
# File 'lib/gamefic/rulebook/hooks.rb', line 36 def run_before action run_action_hooks action, before_actions end |