Class: Franz::InputConfig
- Inherits:
-
Object
- Object
- Franz::InputConfig
- Defined in:
- lib/franz/input_config.rb
Instance Attribute Summary collapse
-
#configs ⇒ Object
readonly
Returns the value of attribute configs.
Instance Method Summary collapse
- #config(path) ⇒ Object
- #drop?(path, message) ⇒ Boolean
-
#initialize(configs) ⇒ InputConfig
constructor
A new instance of InputConfig.
- #json?(path) ⇒ Boolean
- #keep?(path, message) ⇒ Boolean
- #type(path) ⇒ Object
Constructor Details
#initialize(configs) ⇒ InputConfig
Returns a new instance of InputConfig.
5 6 7 8 9 10 11 12 13 |
# File 'lib/franz/input_config.rb', line 5 def initialize configs @configs = configs @configs.map! do |c| normalized_config c end @types = Hash.new @drop = Hash.new @keep = Hash.new end |
Instance Attribute Details
#configs ⇒ Object (readonly)
Returns the value of attribute configs.
3 4 5 |
# File 'lib/franz/input_config.rb', line 3 def configs @configs end |
Instance Method Details
#config(path) ⇒ Object
15 16 17 18 |
# File 'lib/franz/input_config.rb', line 15 def config path t = type(path) configs.select { |c| c[:type] == t }.shift end |
#drop?(path, message) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/franz/input_config.rb', line 33 def drop? path, patterns = drops_for(path) return true if patterns.nil? return false if patterns.empty? apply_patterns patterns, end |
#json?(path) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/franz/input_config.rb', line 20 def json? path config(path)[:json?] rescue false end |
#keep?(path, message) ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/franz/input_config.rb', line 26 def keep? path, patterns = keeps_for(path) return true if patterns.nil? return true if patterns.empty? apply_patterns patterns, end |
#type(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/franz/input_config.rb', line 40 def type path @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', file: path @types[path] = nil end |