Module: Bivouac::Filters

Defined in:
lib/bivouac/filter.rb

Instance Method Summary collapse

Instance Method Details

#service(*a) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bivouac/filter.rb', line 7

def service(*a)
  current_class_name = self.class.name #.to_s.gsub( /.*::/, '' )
  apply_filter = nil
  
  $__filters__.each do |k, v|
    if v.size > 0
      
      v.each do |only_or_except, klasses|
        kklasses = klasses.map{|_| _.name}
        if only_or_except == :only and kklasses.include?( current_class_name ) 
          apply_filter = k
        end
        
        if only_or_except == :except and not kklasses.include?( current_class_name ) 
          apply_filter = k
        end
      end
      
    else
      apply_filter = k
    end
  end
  
  s = super(*a)
  unless apply_filter.nil?
    r = apply_filter.filter( @state )
    unless r.nil?
      redirect r
    end
  end
  s
end