Class: MoreViewHooks::HookCollection
- Inherits:
-
Object
- Object
- MoreViewHooks::HookCollection
- Defined in:
- lib/more_view_hooks/hook_collection.rb
Overview
Manages hooks to be applied into Redmine's templates
Instance Method Summary collapse
-
#add(name, options) ⇒ Object
Registers a new view hook.
-
#apply! ⇒ Object
Applies all registered view hooks.
-
#initialize ⇒ HookCollection
constructor
A new instance of HookCollection.
Constructor Details
#initialize ⇒ HookCollection
Returns a new instance of HookCollection.
4 5 6 7 |
# File 'lib/more_view_hooks/hook_collection.rb', line 4 def initialize @hooks = {} @applied = false end |
Instance Method Details
#add(name, options) ⇒ Object
Registers a new view hook
18 19 20 21 22 23 |
# File 'lib/more_view_hooks/hook_collection.rb', line 18 def add(name, ) fail ArgumentError, "A view hook '#{name}' already exists" if @hooks[name] context = .delete(:context) hook = @hooks[name] = Hook.new(name, context, ) hook.apply! if @applied end |
#apply! ⇒ Object
Applies all registered view hooks
10 11 12 13 |
# File 'lib/more_view_hooks/hook_collection.rb', line 10 def apply! @hooks.values.each(&:apply!) @applied = true end |