Class: Plugin::FilterManager

Inherits:
Object
  • Object
show all
Defined in:
lib/plugin/filter_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeFilterManager

Returns a new instance of FilterManager.



5
6
7
# File 'lib/plugin/filter_manager.rb', line 5

def initialize
  @map = {}
end

Instance Method Details

#apply(name, context, result) ⇒ Object



15
16
17
18
19
20
# File 'lib/plugin/filter_manager.rb', line 15

def apply(name, context, result)
  if filters = @map[name]
    filters.each { |blk| result = blk.call(context, result) }
  end
  result
end

#register(name, &blk) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/plugin/filter_manager.rb', line 9

def register(name, &blk)
  raise ArgumentError unless blk && blk.arity == 2
  filters = @map[name] ||= []
  filters << blk
end