Class: MoreViewHooks::HookCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/more_view_hooks/hook_collection.rb

Overview

Manages hooks to be applied into Redmine's templates

Instance Method Summary collapse

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

Parameters:

  • name (String)
  • options (Hash) —

    for Defaced



18
19
20
21
22
23
# File 'lib/more_view_hooks/hook_collection.rb', line 18

def add(name, options)
  fail ArgumentError, "A view hook '#{name}' already exists" if @hooks[name]
  context = options.delete(:context)
  hook = @hooks[name] = Hook.new(name, context, options)
  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