Sha256: 113264417d57574b846086c2e3739bb64dfb389432a68204544d32509c1dfa99

Contents?: true

Size: 888 Bytes

Versions: 2

Compression:

Stored size: 888 Bytes

Contents

$__filters__ = {}
def before_filter( action, opts = {} )
  $__filters__[action] = opts
end

module Bivouac::Filters
  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  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bivouac-0.3.0 lib/bivouac/filter.rb
bivouac-0.4.0 lib/bivouac/filter.rb