Class: RSMP::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/collect/filter.rb

Overview

Filter messages based on type, direction and component id. Used by Collectors.

Instance Method Summary collapse

Constructor Details

#initialize(ingoing: true, outgoing: true, type:, component: nil) ⇒ Filter

Returns a new instance of Filter.



6
7
8
9
10
11
# File 'lib/rsmp/collect/filter.rb', line 6

def initialize ingoing:true, outgoing:true, type:, component:nil
  @ingoing = ingoing
  @outgoing = outgoing
  @type = type
  @component = component
end

Instance Method Details

#accept?(message) ⇒ Boolean

Check a message against our match criteria Return true if there's a match, false if not

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rsmp/collect/filter.rb', line 15

def accept? message
  return false if message.direction == :in && @ingoing == false
  return false if message.direction == :out && @outgoing == false
  if @type
    if @type.is_a? Array
      return false unless @type.include? message.type
    else
      return false unless message.type == @type
    end
  end
  if @component
    return false if message.attributes['cId'] && message.attributes['cId'] != @component
  end
  true
end