Class: Pechkin::MessageMatcher
- Inherits:
-
Object
- Object
- Pechkin::MessageMatcher
- Defined in:
- lib/pechkin/message_matcher.rb
Overview
Allows to match message configuration against received data.
Data is checked againts either allow or forbid rules. But not both at the same time. Each field can contain list of rules to check. ‘allow’ list means we need at least one matching rule to allow data processing. And ‘forbid’ list respectievly means we need at least one matching rule to decline data processing.
Constant Summary collapse
- KEY_ALLOW =
'allow'.freeze
- KEY_FORBID =
'forbid'.freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(logger) ⇒ MessageMatcher
constructor
A new instance of MessageMatcher.
-
#matches?(message_config, data) ⇒ Boolean
Checks data object against allow / forbid rule sets in message configuration.
Constructor Details
#initialize(logger) ⇒ MessageMatcher
Returns a new instance of MessageMatcher.
17 18 19 |
# File 'lib/pechkin/message_matcher.rb', line 17 def initialize(logger) @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
15 16 17 |
# File 'lib/pechkin/message_matcher.rb', line 15 def logger @logger end |
Instance Method Details
#matches?(message_config, data) ⇒ Boolean
Checks data object against allow / forbid rule sets in message configuration. If data object matches rules it means we can process this data and send message.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pechkin/message_matcher.rb', line 29 def matches?(, data) check() if .key?(KEY_ALLOW) rules = [KEY_ALLOW] rules.any? { |r| check_rule(r, r, data) } elsif .key?(KEY_FORBID) rules = [KEY_FORBID] rules.all? { |r| !check_rule(r, r, data) } else true end end |