Class: Serf::Util::RegexpMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/serf/util/regexp_matcher.rb

Overview

A matcher that does a regexp match on a specific field in the given Env. By default, we use this to do regexp matching on message kinds for routing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp, options = {}) ⇒ RegexpMatcher

Returns a new instance of RegexpMatcher.



13
14
15
16
# File 'lib/serf/util/regexp_matcher.rb', line 13

def initialize(regexp, options={})
  @regexp = regexp
  @field = options.fetch(:field) { :kind }
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



11
12
13
# File 'lib/serf/util/regexp_matcher.rb', line 11

def field
  @field
end

#regexpObject (readonly)

Returns the value of attribute regexp.



10
11
12
# File 'lib/serf/util/regexp_matcher.rb', line 10

def regexp
  @regexp
end

Class Method Details

.build(regexp) ⇒ Object



22
23
24
# File 'lib/serf/util/regexp_matcher.rb', line 22

def self.build(regexp)
  return self.new regexp
end

Instance Method Details

#===(env) ⇒ Object



18
19
20
# File 'lib/serf/util/regexp_matcher.rb', line 18

def ===(env)
  return @regexp === env[@field]
end