Sha256: c21ccc022a56ee34747e6d3a743f446ee894c12652bc8944aa530b43f13e6358

Contents?: true

Size: 1.38 KB

Versions: 13

Compression:

Stored size: 1.38 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 json? path
      begin
        return config(path)[:json?]
      rescue
        return false
      end
    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

13 entries across 13 versions & 1 rubygems

Version Path
franz-1.6.4 lib/franz/input_config.rb
franz-1.6.3 lib/franz/input_config.rb
franz-1.6.2 lib/franz/input_config.rb
franz-1.6.1 lib/franz/input_config.rb
franz-1.6.0 lib/franz/input_config.rb
franz-1.5.9 lib/franz/input_config.rb
franz-1.5.8 lib/franz/input_config.rb
franz-1.5.7 lib/franz/input_config.rb
franz-1.5.14 lib/franz/input_config.rb
franz-1.5.13 lib/franz/input_config.rb
franz-1.5.12 lib/franz/input_config.rb
franz-1.5.11 lib/franz/input_config.rb
franz-1.5.10 lib/franz/input_config.rb