Class: ConsulWatcher::Filters
- Inherits:
-
Object
- Object
- ConsulWatcher::Filters
- Includes:
- FlazmRubyHelpers::Class
- Defined in:
- lib/consul_watcher/filters.rb
Instance Method Summary collapse
- #add_filters(filters_to_add) ⇒ Object
- #filter?(change) ⇒ Boolean
-
#initialize(filter_config) ⇒ Filters
constructor
A new instance of Filters.
- #match?(value, regexs) ⇒ Boolean
- #print_filters ⇒ Object
Constructor Details
#initialize(filter_config) ⇒ Filters
Returns a new instance of Filters.
10 11 12 |
# File 'lib/consul_watcher/filters.rb', line 10 def initialize(filter_config) initialize_variables(filter_config) end |
Instance Method Details
#add_filters(filters_to_add) ⇒ Object
14 15 16 |
# File 'lib/consul_watcher/filters.rb', line 14 def add_filters(filters_to_add) @filters = @filters.deep_merge(filters_to_add) unless filters_to_add.nil? end |
#filter?(change) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/consul_watcher/filters.rb', line 18 def filter?(change) @filters.each do |attribute, regexs| next unless change.key?(attribute) && !change[attribute].nil? match = match?(change[attribute], regexs) if match @logger.debug("filtered #{attribute} '#{change[attribute]}' against regular expressions #{regexs}") return true end end false end |
#match?(value, regexs) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/consul_watcher/filters.rb', line 31 def match?(value, regexs) results = regexs.each.collect do |regex| value.match?(/#{regex}/) end results.any? end |
#print_filters ⇒ Object
38 39 40 41 42 |
# File 'lib/consul_watcher/filters.rb', line 38 def print_filters @filters.each do |filter| @logger.debug("filter: #{filter}") end end |