Class: Droonga::MessageMatcher
- Inherits:
-
Object
- Object
- Droonga::MessageMatcher
- Defined in:
- lib/droonga/message_matcher.rb
Overview
It checks whether the pattern matches against a message.
It provides the small language. Here is the pattern syntax.
- PATTERN = [TARGET_PATH, OPERATOR, ARGUMENT*]
- PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
- TARGET_PATH = "COMPONENT(.COMPONENT)*"
- OPERATOR = :equal, :in, :include, :exist, :start_with (More operators may be added in the future. For example, :end_with and so on.)
- ARGUMENT = OBJECT_DEFINED_IN_JSON
- LOGICAL_OPERATOR = :or (:add will be added.)
For example:
["type", :equal, "search"]
matches to the following message:
{"type" => "search"}
Another example:
["body.output.limit", :equal, 10]
matches to the following message:
{
"body" => {
"output" => {
"limit" => 10,
},
},
}
Instance Method Summary collapse
-
#initialize(pattern) ⇒ MessageMatcher
constructor
A new instance of MessageMatcher.
- #match?(message) ⇒ Boolean
Constructor Details
#initialize(pattern) ⇒ MessageMatcher
Returns a new instance of MessageMatcher.
61 62 63 |
# File 'lib/droonga/message_matcher.rb', line 61 def initialize(pattern) @pattern = pattern end |
Instance Method Details
#match?(message) ⇒ Boolean
65 66 67 68 69 70 |
# File 'lib/droonga/message_matcher.rb', line 65 def match?() return false if @pattern.nil? path, operator, *arguments = @pattern target = resolve_path(path, ) apply_operator(operator, target, arguments) end |