Module: Gaskit::Hookable
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #apply_after_hooks(result) ⇒ Object
- #apply_around_hooks(&block) ⇒ Object
- #apply_before_hooks ⇒ Object
- #apply_hooks(*types, &block) ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 |
# File 'lib/gaskit/hookable.rb', line 7 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#apply_after_hooks(result) ⇒ Object
93 94 95 |
# File 'lib/gaskit/hookable.rb', line 93 def apply_after_hooks(result) apply_type_hooks(:after, result: result) end |
#apply_around_hooks(&block) ⇒ Object
89 90 91 |
# File 'lib/gaskit/hookable.rb', line 89 def apply_around_hooks(&block) apply_type_hooks(:around, &block) end |
#apply_before_hooks ⇒ Object
85 86 87 |
# File 'lib/gaskit/hookable.rb', line 85 def apply_before_hooks apply_type_hooks(:before) end |
#apply_hooks(*types, &block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gaskit/hookable.rb', line 72 def apply_hooks(*types, &block) return block.call unless self.class.hooks_enabled? types = types.map(&:to_sym) result = nil apply_type_hooks(:before) if types.include?(:before) result = apply_type_hooks(:around, &block) if types.include?(:around) apply_type_hooks(:after, result: result) if types.include?(:after) result end |