Sha256: f8fab8211a97171d5463505c76b8d3389cc18a2b435e64b6e8fc1a4ad198558b

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

module Franz
  class InputConfig
    attr_reader :configs

    def initialize configs
      @configs = configs
      @types = Hash.new
    end

    def config path
      t = type(path)
      configs.select { |c| c[:type] == t }.shift
    end

    def drop? path, message
      begin
        drop = config(path)[:drop]
      rescue
        return true # No config found, drop it!
      end
      if drop
        drop = drop.is_a?(Array) ? drop : [ drop ]
        drop.each do |pattern|
          return true if message =~ pattern
        end
      end
      return false
    end

    def type path
      begin
        @types.fetch path
      rescue KeyError
        configs.each do |config|
          type = config[:type] if config[:includes].any? { |glob|
            included = File.fnmatch? glob, path
            excludes = !config[:excludes].nil?
            excluded = excludes && config[:excludes].any? { |exlude|
              File.fnmatch? exlude, File::basename(path)
            }
            included && !excluded
          }
          unless type.nil?
            @types[path] = type
            return type
          end
        end
        log.warn \
          event: 'type unknown',
          path: path
        @types[path] = nil
        return nil
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
franz-1.5.6 lib/franz/input_config.rb
franz-1.4.31 lib/franz/input_config.rb
franz-1.5.5 lib/franz/input_config.rb
franz-1.5.4 lib/franz/input_config.rb
franz-1.5.3 lib/franz/input_config.rb
franz-1.5.2 lib/franz/input_config.rb
franz-1.5.1 lib/franz/input_config.rb
franz-1.5.0 lib/franz/input_config.rb