Class: Track::FilterMap

Inherits:
Object
  • Object
show all
Defined in:
lib/track/filter_map.rb

Instance Method Summary collapse

Constructor Details

#initializeFilterMap

Returns a new instance of FilterMap.



6
7
8
# File 'lib/track/filter_map.rb', line 6

def initialize
  @filters = {}
end

Instance Method Details

#add(klass, kind, method, options = {}) ⇒ Object



10
11
12
13
# File 'lib/track/filter_map.rb', line 10

def add(klass, kind, method, options = {})
  @filters[kind] ||= []
  @filters[kind] << [method, options, klass]
end

#scan(klass, kind, action) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/track/filter_map.rb', line 15

def scan(klass, kind, action)
  filters = []
  if @filters[kind]
    @filters[kind].each do |method, options, k|
      next if contains?(options[:except], action) || !(klass <= k)
      filters << method if contains?(options[:only], action) || blank?(options[:only])
    end
  end
  filters
end