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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Filter.



9
10
11
12
13
14
# File 'lib/rsmp/collect/filter.rb', line 9

def initialize ingoing:true, outgoing:true, type:nil, component:nil
  @ingoing = ingoing
  @outgoing = outgoing
  @type = type ? [type].flatten : nil
  @component = component
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



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

def component
  @component
end

#ingoingObject (readonly)

Returns the value of attribute ingoing.



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

def ingoing
  @ingoing
end

#outgoingObject (readonly)

Returns the value of attribute outgoing.



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

def outgoing
  @outgoing
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
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)


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

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

#reject?(message) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rsmp/collect/filter.rb', line 32

def reject? message
  !accept?(message)
end